transaction

package
v0.2.4-0...-2c2ceb1 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2020 License: Apache-2.0, BSD-2-Clause Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const IDLength = 32

IDLength contains the amount of bytes that a marshaled version of the ID contains.

View Source
const (
	// MaxTransactionInputCount is the maximum number of inputs a transaction can have
	MaxTransactionInputCount = 100
)
View Source
const OutputIDLength = address.Length + IDLength

OutputIDLength contains the amount of bytes that a marshaled version of the OutputID contains.

Variables

View Source
var (
	// ErrMaxDataPayloadSizeExceeded is returned if the data payload size is exceeded.
	ErrMaxDataPayloadSizeExceeded = errors.New("maximum data payload size exceeded")
)

Functions

func FromObjectStorage

func FromObjectStorage(key []byte, data []byte) (result objectstorage.StorableObject, err error)

FromObjectStorage is a factory method that creates a new Transaction instance from a storage key of the objectstorage. It is used by the objectstorage, to create new instances of this entity.

Types

type CachedTransaction

type CachedTransaction struct {
	objectstorage.CachedObject
}

CachedTransaction is a wrapper for the object storage, that takes care of type casting the Transaction objects. Since go does not have generics (yet), the object storage works based on the generic "interface{}" type, which means that we have to regularly type cast the returned objects, to match the expected type. To reduce the burden of manually managing these type, we create a wrapper that does this for us. This way, we can consistently handle the specialized types of Transaction, without having to manually type cast over and over again.

func (*CachedTransaction) Consume

func (cachedTransaction *CachedTransaction) Consume(consumer func(tx *Transaction)) bool

Consume overrides the underlying method to use a CachedTransaction object instead of a generic CachedObject in the consumer).

func (*CachedTransaction) Retain

func (cachedTransaction *CachedTransaction) Retain() *CachedTransaction

Retain overrides the underlying method to return a new CachedTransaction instead of a generic CachedObject.

func (*CachedTransaction) Unwrap

func (cachedTransaction *CachedTransaction) Unwrap() *Transaction

Unwrap provides a way to retrieve a type casted version of the underlying object.

type ID

type ID [IDLength]byte

ID is the data type that represents the identifier for a Transaction.

var GenesisID ID

GenesisID represents the genesis ID.

func IDFromBase58

func IDFromBase58(base58String string) (id ID, err error)

IDFromBase58 creates an id from a base58 encoded string.

func IDFromBytes

func IDFromBytes(bytes []byte) (result ID, consumedBytes int, err error)

IDFromBytes unmarshals an ID from a sequence of bytes.

func ParseID

func ParseID(marshalUtil *marshalutil.MarshalUtil) (ID, error)

ParseID is a wrapper for simplified unmarshaling of Ids from a byte stream using the marshalUtil package.

func RandomID

func RandomID() (id ID)

RandomID creates a random id which can for example be used in unit tests.

func (ID) Bytes

func (id ID) Bytes() []byte

Bytes marshals the ID into a sequence of bytes.

func (ID) String

func (id ID) String() string

String creates a human readable version of the ID (for debug purposes).

type Inputs

type Inputs struct {
	*orderedmap.OrderedMap
}

Inputs represents a list of referenced Outputs that are used as Inputs in a transaction.

func InputsFromBytes

func InputsFromBytes(bytes []byte) (inputs *Inputs, consumedBytes int, err error)

InputsFromBytes unmarshals the Inputs from a sequence of bytes.

func NewInputs

func NewInputs(outputIds ...OutputID) (inputs *Inputs)

NewInputs is the constructor of the Inputs object and creates a new list with the given OutputIds.

func (*Inputs) Add

func (inputs *Inputs) Add(input OutputID) *Inputs

Add allows us to add a new Output to the list of Inputs.

func (*Inputs) Bytes

func (inputs *Inputs) Bytes() (bytes []byte)

Bytes returns a marshaled version of this list of Inputs.

func (*Inputs) ForEach

func (inputs *Inputs) ForEach(consumer func(outputID OutputID) bool) bool

ForEach iterates through the referenced Outputs and calls the consumer function for every Output. The iteration can be aborted by returning false in the consumer.

func (*Inputs) ForEachAddress

func (inputs *Inputs) ForEachAddress(consumer func(currentAddress address.Address) bool) bool

ForEachAddress iterates through the input addresses and calls the consumer function for every Address. The iteration can be aborted by returning false in the consumer.

func (*Inputs) ForEachTransaction

func (inputs *Inputs) ForEachTransaction(consumer func(transactionId ID) bool) bool

ForEachTransaction iterates through the transactions that had their Outputs consumed and calls the consumer function for every founds transaction. The iteration can be aborted by returning false in the consumer.

func (*Inputs) String

func (inputs *Inputs) String() string

String returns a human readable version of the list of Inputs (for debug purposes).

type OutputID

type OutputID [OutputIDLength]byte

OutputID is the data type that represents the identifier for a Output.

func NewOutputID

func NewOutputID(outputAddress address.Address, transactionID ID) (outputID OutputID)

NewOutputID is the constructor for the OutputID type.

func OutputIDFromBase58

func OutputIDFromBase58(base58String string) (outputid OutputID, err error)

OutputIDFromBase58 creates an output id from a base58 encoded string.

func OutputIDFromBytes

func OutputIDFromBytes(bytes []byte) (result OutputID, consumedBytes int, err error)

OutputIDFromBytes unmarshals an OutputID from a sequence of bytes.

func ParseOutputID

func ParseOutputID(marshalUtil *marshalutil.MarshalUtil) (OutputID, error)

ParseOutputID is a wrapper for simplified unmarshaling of Ids from a byte stream using the marshalUtil package.

func (OutputID) Address

func (outputID OutputID) Address() (address address.Address)

Address returns the address part of an OutputID.

func (OutputID) Bytes

func (outputID OutputID) Bytes() []byte

Bytes marshals the OutputID into a sequence of bytes.

func (OutputID) String

func (outputID OutputID) String() string

String creates a human readable version of the OutputID (for debug purposes).

func (OutputID) TransactionID

func (outputID OutputID) TransactionID() (transactionID ID)

TransactionID returns the transaction id part of an OutputID.

type Outputs

type Outputs struct {
	*orderedmap.OrderedMap
}

Outputs represents a list of Outputs that are part of a transaction.

func NewOutputs

func NewOutputs(outputs map[address.Address][]*balance.Balance) (result *Outputs)

NewOutputs is the constructor of the Outputs struct and creates the list of Outputs from the given details.

func OutputsFromBytes

func OutputsFromBytes(bytes []byte, optionalTargetObject ...*Outputs) (result *Outputs, consumedBytes int, err error)

OutputsFromBytes reads the bytes and unmarshals the given information into an *Outputs object. It either creates a new object, or uses the optional object provided in the arguments.

func (*Outputs) Add

func (outputs *Outputs) Add(address address.Address, balances []*balance.Balance) *Outputs

Add adds a new Output to the list of Outputs.

func (*Outputs) Bytes

func (outputs *Outputs) Bytes() []byte

Bytes returns a marshaled version of this list of Outputs.

func (*Outputs) ForEach

func (outputs *Outputs) ForEach(consumer func(address address.Address, balances []*balance.Balance) bool) bool

ForEach iterates through the Outputs and calls them consumer for every found one. The iteration can be aborted by returning false in the consumer.

func (*Outputs) String

func (outputs *Outputs) String() string

String returns a human readable version of this list of Outputs (for debug purposes).

type Signatures

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

Signatures represents a container for the address signatures of a value transfer. It internally manages the list of signatures as an ordered map, so that the serialization order is deterministic and produces the same sequence of bytes during marshaling and unmarshaling.

func NewSignatures

func NewSignatures() *Signatures

NewSignatures creates an empty container for the address signatures of a value transfer.

func SignaturesFromBytes

func SignaturesFromBytes(bytes []byte, optionalTargetObject ...*Signatures) (result *Signatures, consumedBytes int, err error)

SignaturesFromBytes unmarshals a container with signatures from a sequence of bytes. It either creates a new container or fills the optionally provided container with the parsed information.

func (*Signatures) Add

func (signatures *Signatures) Add(address address.Address, signature signaturescheme.Signature)

Add adds a new Signature to this container.

func (*Signatures) Bytes

func (signatures *Signatures) Bytes() []byte

Bytes marshals the signatures into a sequence of bytes.

func (*Signatures) ForEach

func (signatures *Signatures) ForEach(consumer func(address address.Address, signature signaturescheme.Signature) bool)

ForEach iterates through all signatures, calling the consumer for every found entry. The iteration can be aborted by the consumer returning false

func (*Signatures) Get

func (signatures *Signatures) Get(address address.Address) (signaturescheme.Signature, bool)

Get returns the Signature, that belongs to an Address.

func (*Signatures) Size

func (signatures *Signatures) Size() int

Size returns the amount of signatures in this container.

func (*Signatures) String

func (signatures *Signatures) String() string

type Transaction

type Transaction struct {
	objectstorage.StorableObjectFlags
	// contains filtered or unexported fields
}

Transaction represents a value transfer for IOTA. It consists out of a number of inputs, a number of outputs and their corresponding signature. Additionally, there is an optional data field, that can be used to include payment details or processing information.

func FromBytes

func FromBytes(bytes []byte) (result *Transaction, consumedBytes int, err error)

FromBytes unmarshals a Transaction from a sequence of bytes.

func New

func New(inputs *Inputs, outputs *Outputs) *Transaction

New creates a new Transaction from the given details. The signatures are omitted as signing requires us to marshal the transaction into a sequence of bytes and these bytes are unknown at the time of the creation of the Transaction.

func Parse

func Parse(marshalUtil *marshalutil.MarshalUtil) (result *Transaction, err error)

Parse unmarshals a Transaction using the given marshalUtil (for easier marshaling/unmarshaling).

func (*Transaction) Bytes

func (transaction *Transaction) Bytes() []byte

Bytes returns a marshaled version of this Transaction (essence + signatures).

func (*Transaction) DataPayloadSize

func (transaction *Transaction) DataPayloadSize() uint32

DataPayloadSize returns the size of the dataPayload as uint32. nil payload as size 0

func (*Transaction) EssenceBytes

func (transaction *Transaction) EssenceBytes() []byte

EssenceBytes return the bytes of the transaction excluding the Signatures. These bytes are later signed and used to generate the Signatures.

func (*Transaction) GetDataPayload

func (transaction *Transaction) GetDataPayload() []byte

GetDataPayload gets the dataPayload and its type

func (*Transaction) ID

func (transaction *Transaction) ID() ID

ID returns the identifier of this Transaction.

func (*Transaction) Inputs

func (transaction *Transaction) Inputs() *Inputs

Inputs returns the list of Inputs that were consumed by this Transaction.

func (*Transaction) InputsCountValid

func (transaction *Transaction) InputsCountValid() bool

InputsCountValid returns true if the number of inputs in this transaction is not greater than MaxTransactionInputCount.

func (*Transaction) ObjectStorageKey

func (transaction *Transaction) ObjectStorageKey() []byte

ObjectStorageKey returns the bytes that are used as a key when storing the Transaction in an objectstorage.

func (*Transaction) ObjectStorageValue

func (transaction *Transaction) ObjectStorageValue() []byte

ObjectStorageValue returns a bytes representation of the Transaction by implementing the encoding.BinaryMarshaler interface.

func (*Transaction) Outputs

func (transaction *Transaction) Outputs() *Outputs

Outputs returns the list of Outputs where this Transaction moves its consumed funds.

func (*Transaction) PutSignature

func (transaction *Transaction) PutSignature(signature signaturescheme.Signature) error

PutSignature validates and adds signature to the transaction

func (*Transaction) SetDataPayload

func (transaction *Transaction) SetDataPayload(data []byte) error

SetDataPayload sets yhe dataPayload and its type

func (*Transaction) Sign

func (transaction *Transaction) Sign(signature signaturescheme.SignatureScheme) *Transaction

Sign adds a new signature to the Transaction.

func (*Transaction) SignatureBytes

func (transaction *Transaction) SignatureBytes() []byte

SignatureBytes returns the bytes of all of the signatures in the Transaction.

func (*Transaction) Signatures

func (transaction *Transaction) Signatures() (signatures []signaturescheme.Signature)

Signatures returns all the signatures in this transaction.

func (*Transaction) SignaturesValid

func (transaction *Transaction) SignaturesValid() bool

SignaturesValid returns true if the Signatures in this transaction

func (*Transaction) String

func (transaction *Transaction) String() string

String returns a human readable version of this Transaction (for debug purposes).

func (*Transaction) Update

func (transaction *Transaction) Update(other objectstorage.StorableObject)

Update is disabled but needs to be implemented to be compatible with the objectstorage.

Jump to

Keyboard shortcuts

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