tx

package
v0.0.0-...-5d200cf Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2024 License: Apache-2.0 Imports: 11 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/milos-ethernal/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

func Blake224Hash

func Blake224Hash(b []byte) ([]byte, error)

func GetBytesFromCBORHex

func GetBytesFromCBORHex(cborHex string) ([]byte, error)

func GetCBORHexFromBytes

func GetCBORHexFromBytes(data []byte) (string, error)

func GetCBOR_DecMode

func GetCBOR_DecMode() cbor.DecMode

func GetCBOR_EncMode

func GetCBOR_EncMode() cbor.EncMode

func GetVerificationKeyFromSigningKey

func GetVerificationKeyFromSigningKey(signingKey []byte) []byte

GetVerificationKeyFromSigningKey retrieves verification/public key from signing/private key

func SignMessage

func SignMessage(signingKey, verificationKey, message []byte) (result []byte, err error)

Types

type AddrKeyHash

type AddrKeyHash = Hash28

type AuxiliaryData

type AuxiliaryData struct {
	Metadata           Metadata    `cbor:"0,keyasint,omitempty"`
	NativeScripts      interface{} `cbor:"1,keyasint,omitempty"`
	PlutusScripts      interface{} `cbor:"2,keyasint,omitempty"`
	PreferAlonzoFormat bool        `cbor:"2,keyasint,omitempty"`
}

AuxiliaryData is the auxiliary data in the transaction.

func NewAuxiliaryData

func NewAuxiliaryData() *AuxiliaryData

func (*AuxiliaryData) AddMetadataElement

func (d *AuxiliaryData) AddMetadataElement(key string, value MetadataElement)

func (*AuxiliaryData) AddMetadataTransaction

func (d *AuxiliaryData) AddMetadataTransaction(address string, amount uint)

func (*AuxiliaryData) MarshalCBOR

func (d *AuxiliaryData) MarshalCBOR() ([]byte, error)

MarshalCBOR implements cbor.Marshaler

func (*AuxiliaryData) UnmarshalCBOR

func (d *AuxiliaryData) UnmarshalCBOR(data []byte) error

UnmarshalCBOR implements cbor.Unmarshaler

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 Hash28

type Hash28 []byte

type Metadata

type Metadata map[uint]map[string]MetadataElement

Metadata represents the transaction metadata.

type MetadataElement

type MetadataElement interface{}

type NativeScript

type NativeScript struct {
	Type          NativeScriptType
	KeyHash       AddrKeyHash
	N             uint64
	Scripts       []NativeScript
	IntervalValue uint64
}

NativeScript is a Cardano Native Script.

func NewScriptPubKey

func NewScriptPubKey(keyHash []byte) (NativeScript, error)

NewScriptPubKey returns a new Script PubKey. keyHash = PubKey.Hash()

func (*NativeScript) Bytes

func (ns *NativeScript) Bytes() ([]byte, error)

Bytes returns the CBOR encoding of the script as bytes.

func (*NativeScript) Hash

func (ns *NativeScript) Hash() (Hash28, error)

Hash returns the script hash using blake2b224.

func (*NativeScript) MarshalCBOR

func (ns *NativeScript) MarshalCBOR() ([]byte, error)

MarshalCBOR implements cbor.Marshaler.

func (*NativeScript) UnmarshalCBOR

func (ns *NativeScript) UnmarshalCBOR(data []byte) error

UnmarshalCBOR implements cbor.Unmarshaler.

type NativeScriptType

type NativeScriptType uint64
const (
	ScriptPubKey NativeScriptType = iota
	ScriptAll
	ScriptAny
	ScriptNofK
	ScriptInvalidBefore
	ScriptInvalidAfter
)

type ScriptHashNamespace

type ScriptHashNamespace uint8
const (
	NativeScriptNamespace ScriptHashNamespace = iota
	PlutusScriptNamespace
)

type Tx

type Tx struct {
	Body          *TxBody
	WitnessSet    *WitnessSet
	Valid         bool
	AuxiliaryData *AuxiliaryData // or null
	// 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) GetTotalInputOutputs

func (tb TxBuilder) GetTotalInputOutputs() (inputs, outputs uint)

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 WitnessSet

type WitnessSet struct {
	Witnesses []VKeyWitness  `cbor:"0,keyasint,omitempty"`
	Scripts   []NativeScript `cbor:"1,keyasint,omitempty"`
}

func NewTXWitnessSet

func NewTXWitnessSet(scripts []NativeScript, witnesses []VKeyWitness) *WitnessSet

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