transaction

package
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 21, 2020 License: MIT Imports: 8 Imported by: 21

Documentation

Index

Constants

View Source
const (
	WitnessScaleFactor   = 4
	DefaultSequence      = 0xffffffff
	MinusOne             = 4294967295
	OutpointIndexMask    = 0x3fffffff
	OutpointIssuanceFlag = (1 << 31) >> 0
	OutpointPeginFlag    = (1 << 30) >> 0
)

Variables

View Source
var (
	One = [32]byte{
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
	}
	Zero = [32]byte{
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
	}
	MaxConfidentialValue = []byte{
		0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
	}
)
View Source
var BinarySerializer binaryFreeList = make(chan []byte, binaryFreeListMaxItems)

binarySerializer provides a free list of buffers to use for serializing and deserializing primitive integer values to and from io.Readers and io.Writers.

Functions

This section is empty.

Types

type Deserializer

type Deserializer struct {
	// contains filtered or unexported fields
}

Deserializer implements methods that help to deserialize an Elements transaction.

func NewDeserializer

func NewDeserializer(buffer *bytes.Buffer) *Deserializer

NewDeserializer returns an instance of Deserializer.

func (*Deserializer) ReadElementsAsset

func (d *Deserializer) ReadElementsAsset() ([]byte, error)

ReadElementsAsset reads an Elements output asset form the reader's buffer

func (*Deserializer) ReadElementsNonce

func (d *Deserializer) ReadElementsNonce() ([]byte, error)

ReadElementsNonce reads a maybe non-zero Elements output nonce form the reader's buffer

func (*Deserializer) ReadElementsValue

func (d *Deserializer) ReadElementsValue() ([]byte, error)

ReadElementsValue reads the first byte to determine if the value is confidential or unconfidential, then reads the right number of bytes accordingly.

func (*Deserializer) ReadSlice

func (d *Deserializer) ReadSlice(n uint) ([]byte, error)

ReadSlice reads the next n bytes from the reader's buffer

func (*Deserializer) ReadUint16

func (d *Deserializer) ReadUint16() (uint16, error)

ReadUint16 reads a uint16 value from reader's buffer.

func (*Deserializer) ReadUint32

func (d *Deserializer) ReadUint32() (uint32, error)

ReadUint32 reads a uint32 value from reader's buffer.

func (*Deserializer) ReadUint64

func (d *Deserializer) ReadUint64() (uint64, error)

ReadUint64 reads a uint64 value from reader's buffer.

func (*Deserializer) ReadUint8

func (d *Deserializer) ReadUint8() (uint8, error)

ReadUint8 reads a uint8 value from reader's buffer.

func (*Deserializer) ReadVarInt

func (d *Deserializer) ReadVarInt() (uint64, error)

ReadVarInt reads a variable length integer from reader's buffer and returns it as a uint64.

func (*Deserializer) ReadVarSlice

func (d *Deserializer) ReadVarSlice() ([]byte, error)

ReadVarSlice first reads the length n of the bytes, then reads the next n bytes

func (*Deserializer) ReadVector

func (d *Deserializer) ReadVector() ([][]byte, error)

ReadVector reads the length n of the array of bytes, then reads the next n array bytes

type Serializer

type Serializer struct {
	// contains filtered or unexported fields
}

Serializer implements methods that help to serialize an Elements transaction.

func NewSerializer

func NewSerializer(buf *bytes.Buffer) (*Serializer, error)

NewSerializer returns an instance of Serializer.

func (*Serializer) Bytes

func (s *Serializer) Bytes() []byte

Bytes returns writer's buffer

func (*Serializer) WriteSlice

func (s *Serializer) WriteSlice(val []byte) error

WriteSlice appends the given byte array to the writer's buffer

func (*Serializer) WriteUint16

func (s *Serializer) WriteUint16(val uint16) error

WriteUint16 writes the given uint8 value to writer's buffer.

func (*Serializer) WriteUint32

func (s *Serializer) WriteUint32(val uint32) error

WriteUint32 writes the given uint32 value to writer's buffer.

func (*Serializer) WriteUint64

func (s *Serializer) WriteUint64(val uint64) error

WriteUint64 writes the given uint64 value to writer's buffer.

func (*Serializer) WriteUint8

func (s *Serializer) WriteUint8(val uint8) error

WriteUint8 writes the given uint8 value to writer's buffer.

func (*Serializer) WriteVarInt

func (s *Serializer) WriteVarInt(val uint64) error

WriteVarInt serializes the given value to writer's buffer using a variable number of bytes depending on its value.

func (*Serializer) WriteVarSlice

func (s *Serializer) WriteVarSlice(val []byte) error

WriteVarSlice appends the length of the given byte array as var int and the byte array itself to the writer's buffer

func (*Serializer) WriteVector

func (s *Serializer) WriteVector(v [][]byte) error

WriteVector appends an array of array bytes to the writer's buffer

type Transaction

type Transaction struct {
	Version  int32
	Flag     int32
	Locktime uint32
	Inputs   []*TxInput
	Outputs  []*TxOutput
}

Transaction defines an elements transaction message.

func NewTx

func NewTx(version int32) *Transaction

NewTx returns a new elements tx message. The return instance has no transaction inputs or outputs. Also, the lock time is set to zero to indicate the transaction is valid immediately as opposed to some time in future.

func NewTxFromBuffer

func NewTxFromBuffer(buf *bytes.Buffer) (*Transaction, error)

NewTxFromBuffer deserializes the given raw transaction in bytes and returns an instance of *Transaction.

func NewTxFromHex

func NewTxFromHex(str string) (*Transaction, error)

NewTxFromHex deserializes the given transaction in hex format and returns an instance of *Transaction.

func (*Transaction) AddInput

func (tx *Transaction) AddInput(ti *TxInput)

AddInput creates an input with the given hash and index and adds it to the transaction.

func (*Transaction) AddOutput

func (tx *Transaction) AddOutput(to *TxOutput)

AddOutput adds an output to the transaction.

func (*Transaction) Copy

func (tx *Transaction) Copy() *Transaction

Copy creates a deep copy of a transaction so that the original does not get modified when the copy is manipulated.

func (*Transaction) HasWitness

func (tx *Transaction) HasWitness() bool

HasWitness returns wether the transaction contains witness data

func (*Transaction) HashForSignature

func (tx *Transaction) HashForSignature(
	inIndex int,
	prevoutScript []byte,
	hashType txscript.SigHashType) ([32]byte, error)

HashForSignature returns the double sha256 hash of the serialization of the transaction in order to then produce a signature from it. The transaction is serialized in a different way depending on the hashType provided.

func (*Transaction) HashForWitnessV0

func (tx *Transaction) HashForWitnessV0(inIndex int, prevoutScript []byte, value []byte, hashType txscript.SigHashType) [32]byte

HashForWitnessV0 returns the double sha256 hash of the serialization of the transaction following the BIP-0143 specification. This hash should then be used to produce a witness signatures for the given inIndex input.

func (*Transaction) Serialize

func (tx *Transaction) Serialize() ([]byte, error)

Serialize returns the serialization of the transaction.

func (*Transaction) SerializeSize

func (tx *Transaction) SerializeSize(allowWitness, forSignature bool) int

SerializeSize returns the number of bytes it would take to serialize the the transaction.

func (*Transaction) ToHex

func (tx *Transaction) ToHex() (string, error)

ToHex returns the serializarion of the transaction in hex enncoding format.

func (*Transaction) TxHash

func (tx *Transaction) TxHash() chainhash.Hash

TxHash generates the Hash for the transaction.

func (*Transaction) VirtualSize

func (tx *Transaction) VirtualSize() int

VirtualSize returns the total weight of a transaction excluding witnesses

func (*Transaction) Weight

func (tx *Transaction) Weight() int

Weight returns the total weight in bytes of the transaction

func (*Transaction) WitnessHash

func (tx *Transaction) WitnessHash() chainhash.Hash

WitnessHash generates the hash of the transaction serialized according to the new witness serialization defined in BIP0141 and BIP0144. The final output is used within the Segregated Witness commitment of all the witnesses within a block. If a transaction has no witness data, then the witness hash, is the same as its txid.

type TxInput

type TxInput struct {
	Hash                []byte
	Index               uint32
	Sequence            uint32
	Script              []byte
	Witness             TxWitness
	IsPegin             bool
	PeginWitness        TxWitness
	Issuance            *TxIssuance
	IssuanceRangeProof  []byte
	InflationRangeProof []byte
}

TxInput defines an elements transaction input.

func NewTxInput

func NewTxInput(hash []byte, index uint32) *TxInput

NewTxInput returns a new input with given hash and index and a default max sequence number.

func (*TxInput) SerializeSize

func (in *TxInput) SerializeSize() int

SerializeSize returns the number of bytes it would take to serialize the the transaction input.

type TxIssuance

type TxIssuance struct {
	AssetBlindingNonce []byte
	AssetEntropy       []byte
	AssetAmount        []byte
	TokenAmount        []byte
}

TxIssuance defines the type for Issuance field in TxInput

type TxOutput

type TxOutput struct {
	Asset           []byte
	Value           []byte
	Script          []byte
	Nonce           []byte
	RangeProof      []byte
	SurjectionProof []byte
}

TxOutput defines an elements transaction output.

func NewTxOutput

func NewTxOutput(asset, value, script []byte) *TxOutput

NewTxOutput returns a new output with given asset, value and script and a default 0 nonce.

func (*TxOutput) SerializeSize

func (out *TxOutput) SerializeSize() int

SerializeSize returns the number of bytes it would take to serialize the the transaction output.

type TxWitness

type TxWitness [][]byte

TxWitness defines the witness for a TxIn. A witness is to be interpreted as a slice of byte slices, or a stack with one or many elements.

func (TxWitness) SerializeSize

func (tw TxWitness) SerializeSize() int

SerializeSize returns the number of bytes it would take to serialize the the transaction input's witness.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL