transaction

package
v0.5.3 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2024 License: MIT Imports: 10 Imported by: 15

Documentation

Index

Constants

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

	//SighashRangeproof is a flag that means the rangeproofs should be included in the sighash.
	SighashRangeproof = 0x40
)

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,
	}
)

Functions

func ComputeAsset added in v0.4.3

func ComputeAsset(entropy []byte) ([]byte, error)

ComputeAsset generates the hash of the asset from the issuance entropy

func ComputeEntropy added in v0.4.3

func ComputeEntropy(inTxHash []byte, inTxIndex uint32, contractHash []byte) ([]byte, error)

func ComputeReissuanceToken added in v0.4.3

func ComputeReissuanceToken(entropy []byte, flag uint) ([]byte, error)

ComputeReissuanceToken generates the hash of the reissuance token asset from the entropy and issuance flag

Types

type IssuanceContract added in v0.0.3

type IssuanceContract struct {
	Name      string         `json:"name"`
	Ticker    string         `json:"ticker"`
	Version   uint           `json:"version"`
	Precision uint           `json:"precision"`
	PubKey    string         `json:"issuer_pubkey"`
	Entity    IssuanceEntity `json:"entity"`
}

IssuanceContract defines the structure of the Ricardian contract of the issuance

type IssuanceEntity added in v0.0.3

type IssuanceEntity struct {
	Domain string `json:"domain"`
}

IssuanceEntity defines one of the fields of the issuance contract

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) CountIssuances added in v0.0.3

func (tx *Transaction) CountIssuances() (issuances, reissuances, total int)

CountIssuances returns the number issuances contained in the transaction as the number of issuances, reissuances and the total (their sum).

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) HashForWitnessV1 added in v0.4.0

func (tx *Transaction) HashForWitnessV1(
	inIndex int,
	prevoutsScripts [][]byte,
	prevoutsAssets [][]byte,
	prevoutsValues [][]byte,
	hashType txscript.SigHashType,
	genesisBlockHash *chainhash.Hash,
	leafHash *chainhash.Hash,
	annex []byte,
) [32]byte

HashForWitnessV1 returns the sighash as described in BIP-340

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) HasAnyIssuance added in v0.1.0

func (in *TxInput) HasAnyIssuance() bool

HasAnyIssuance returns whether the input contains an issuance

func (*TxInput) HasConfidentialIssuance added in v0.0.4

func (in *TxInput) HasConfidentialIssuance() bool

HasConfidentialIssuance returns whether the input contains a blinded issuance

func (*TxInput) HasIssuance added in v0.0.3

func (in *TxInput) HasIssuance() bool

HasIssuance returns wheter the input contains a pure asset issuance

func (*TxInput) HasReissuance added in v0.1.0

func (in *TxInput) HasReissuance() bool

HasReissuance returns wheter the input contains a reissuance of an asset

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

func (*TxIssuance) HasTokenAmount added in v0.1.0

func (issuance *TxIssuance) HasTokenAmount() bool

HasTokenAmount returns whether the token amount is defined for the issuance

func (*TxIssuance) IsReissuance added in v0.0.4

func (issuance *TxIssuance) IsReissuance() bool

IsReissuance returns whether the issuance is an asset re-issuance

type TxIssuanceExtended added in v0.0.3

type TxIssuanceExtended struct {
	TxIssuance
	Precision    uint
	ContractHash []byte
}

TxIssuanceExtended adds fields to the issuance type that are not encoded in the transaction

func NewTxIssuance added in v0.0.3

func NewTxIssuance(
	assetAmount uint64,
	tokenAmount uint64,
	precision uint,
	contract *IssuanceContract,
) (*TxIssuanceExtended, error)

NewTxIssuance returns a new issuance instance

func NewTxIssuanceFromContractHash added in v0.0.3

func NewTxIssuanceFromContractHash(contractHash []byte) *TxIssuanceExtended

NewTxIssuanceFromContractHash returns a new issuance instance from contract hash

func NewTxIssuanceFromEntropy added in v0.0.4

func NewTxIssuanceFromEntropy(entropy []byte) *TxIssuanceExtended

NewTxIssuanceFromEntropy returns a new issuance instance from entropy

func NewTxIssuanceFromInput added in v0.0.4

func NewTxIssuanceFromInput(in *TxInput) (*TxIssuanceExtended, error)

NewTxIssuanceFromInput returns the extended issuance for the given input

func (*TxIssuanceExtended) GenerateAsset added in v0.0.3

func (issuance *TxIssuanceExtended) GenerateAsset() ([]byte, error)

GenerateAsset calculates the asset hash for the given issuance

func (*TxIssuanceExtended) GenerateEntropy added in v0.0.3

func (issuance *TxIssuanceExtended) GenerateEntropy(inTxHash []byte, inTxIndex uint32) error

GenerateEntropy generates the entropy from which the hash of the asset and of the reissuance token are calculated

func (*TxIssuanceExtended) GenerateReissuanceToken added in v0.0.3

func (issuance *TxIssuanceExtended) GenerateReissuanceToken(flag uint) ([]byte, error)

GenerateReissuanceToken calculates the asset hash for the given issuance

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) IsConfidential added in v0.0.3

func (out *TxOutput) IsConfidential() bool

IsConfidential returns whether the output is a confidential one

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