tx

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2023 License: Apache-2.0 Imports: 8 Imported by: 0

README

Transactions

GoDoc

Package tx implements structs for serialization and deserialization of cardano transaction. It also provides a convenience txBuilder to ease creating transactions, adding inputs/outputs, calculating minimum fee and signing the transaction using a your private key.

Installation

go get github.com/jsambuo/go-cardano-serialization/tx

License

Package tx is licensed under Apache License.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BootstrapWitness

type BootstrapWitness struct {
	VKey       []byte
	Signature  []byte
	ChainCode  []byte
	Attributes []byte
	// contains filtered or unexported fields
}

BootstrapWitness for use with Byron/Legacy based transactions

type Tx

type Tx struct {
	Body     *TxBody
	Witness  *Witness
	Valid    bool
	Metadata interface{}
	// contains filtered or unexported fields
}

func NewTx

func NewTx() *Tx

NewTx returns a pointer to a new Transaction

func (*Tx) AddInputs

func (t *Tx) AddInputs(inputs ...*TxInput) error

AddInputs adds the inputs to the transaction body

func (*Tx) AddOutputs

func (t *Tx) AddOutputs(outputs ...*TxOutput) error

AddOutputs adds the outputs to the transaction body

func (*Tx) Bytes

func (t *Tx) Bytes() ([]byte, error)

Bytes returns a slice of cbor marshalled bytes

func (*Tx) CalculateAuxiliaryDataHash

func (t *Tx) CalculateAuxiliaryDataHash() error

func (*Tx) Fee

func (t *Tx) Fee(lfee *fees.LinearFee) (uint, error)

Fee returns the fee(in lovelaces) required by the transaction from the linear formula fee = txFeeFixed + txFeePerByte*tx_len_in_bytes

func (*Tx) Hash

func (t *Tx) Hash() ([32]byte, error)

Hash performs a blake2b hash of the transaction body and returns a slice of [32]byte

func (*Tx) Hex

func (t *Tx) Hex() (string, error)

Hex returns hex encoding of the transacion bytes

func (*Tx) SetFee

func (t *Tx) SetFee(fee uint)

SetFee sets the fee

type TxBody

type TxBody struct {
	Inputs            []*TxInput  `cbor:"0,keyasint"`
	Outputs           []*TxOutput `cbor:"1,keyasint"`
	Fee               uint64      `cbor:"2,keyasint"`
	TTL               uint32      `cbor:"3,keyasint,omitempty"`
	AuxiliaryDataHash []byte      `cbor:"7,keyasint,omitempty"`
}

TxBody contains the inputs, outputs, fee and titme to live for the transaction.

func NewTxBody

func NewTxBody() *TxBody

NewTxBody returns a pointer to a new transaction body.

func (*TxBody) Bytes

func (b *TxBody) Bytes() ([]byte, error)

Bytes returns a slice of cbor Marshalled bytes.

func (*TxBody) Hex

func (b *TxBody) Hex() (string, error)

Hex returns hex encoded string of the transaction bytes.

type TxBuilder

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

TxBuilder - used to create, validate and sign transactions.

func NewTxBuilder

func NewTxBuilder(pr protocol.Protocol, xprvs []bip32.XPrv) *TxBuilder

NewTxBuilder returns pointer to a new TxBuilder.

func (*TxBuilder) AddChangeIfNeeded

func (tb *TxBuilder) AddChangeIfNeeded(addr address.Address)

AddChangeIfNeeded calculates the excess change from UTXO inputs - outputs and adds it to the transaction body.

func (*TxBuilder) AddInputs

func (tb *TxBuilder) AddInputs(inputs ...*TxInput)

AddInputs adds inputs to the transaction body

func (*TxBuilder) AddOutputs

func (tb *TxBuilder) AddOutputs(outputs ...*TxOutput)

AddOutputs add outputs to the transaction body

func (*TxBuilder) Build

func (tb *TxBuilder) Build() (tx Tx, err error)

Build creates hash of transaction, signs the hash using supplied witnesses and adds them to the transaction.

func (TxBuilder) MinFee

func (tb TxBuilder) MinFee() (fee uint)

MinFee calculates the minimum fee for the provided transaction.

func (*TxBuilder) SetTTL

func (tb *TxBuilder) SetTTL(ttl uint32)

SetTTL sets the time to live for the transaction.

func (*TxBuilder) Sign

func (tb *TxBuilder) Sign(xprv bip32.XPrv)

Sign adds a private key to create signature for witness

func (*TxBuilder) Tx

func (tb *TxBuilder) Tx() (tx *Tx)

Tx returns a pointer to the transaction

type TxInput

type TxInput struct {
	cbor.Marshaler

	TxHash []byte
	Index  uint16
	Amount uint
}

func NewTxInput

func NewTxInput(txHash string, txIx uint16, amount uint) *TxInput

NewTxInput creates and returns a *TxInput from Transaction Hash(Hex Encoded), Transaction Index and Amount.

func (*TxInput) MarshalCBOR

func (txI *TxInput) MarshalCBOR() ([]byte, error)

type TxOutput

type TxOutput struct {
	Address address.Address
	Amount  uint
	// contains filtered or unexported fields
}

func NewTxOutput

func NewTxOutput(addr address.Address, amount uint) *TxOutput

type VKeyWitness

type VKeyWitness struct {
	VKey      []byte
	Signature []byte
	// contains filtered or unexported fields
}

VKeyWitness - Witness for use with Shelley based transactions

func NewVKeyWitness

func NewVKeyWitness(vkey, signature []byte) *VKeyWitness

NewVKeyWitness creates a Witness for Shelley Based transactions from a verification key and transaction signature.

type Witness

type Witness struct {
	Keys []*VKeyWitness `cbor:"0,keyasint,omitempty"`
}

func NewTXWitness

func NewTXWitness(keys ...*VKeyWitness) *Witness

NewTXWitness returns a pointer to a Witness created from VKeyWitnesses.

Jump to

Keyboard shortcuts

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