Documentation
¶
Overview ¶
Package transaction provides functions for parsing transactions, extracting JSON data from them, conversions and validation.
Index ¶
- func ExtractJSON(txs Transactions) (string, error)
- func FinalTransactionTrytes(txs Transactions) ([]Trytes, error)
- func HasValidNonce(t *Transaction, mwm uint64) bool
- func IsTailTransaction(t *Transaction) bool
- func MustFinalTransactionTrytes(txs Transactions) []Trytes
- func MustTransactionToTrytes(t *Transaction) Trytes
- func MustTransactionsToTrytes(txs Transactions) []Trytes
- func TransactionHash(t *Transaction) Hash
- func TransactionToTrits(t *Transaction) (Trits, error)
- func TransactionToTrytes(t *Transaction) (Trytes, error)
- func TransactionsToTrytes(txs Transactions) ([]Trytes, error)
- func ValidTransactionTrytes(trytes Trytes) error
- type Transaction
- type Transactions
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExtractJSON ¶
func ExtractJSON(txs Transactions) (string, error)
ExtractJSON extracts a JSON string from the given transactions. It supports JSON messages in the following format:
- "{ \"message\": \"hello\" }"
- "[1, 2, 3]"
- "true", "false" and "null"
- "hello"
- 123
func FinalTransactionTrytes ¶
func FinalTransactionTrytes(txs Transactions) ([]Trytes, error)
FinalTransactionTrytes returns a slice of transaction trytes from the given transactions. The order of the transactions is reversed in the output slice.
func HasValidNonce ¶
func HasValidNonce(t *Transaction, mwm uint64) bool
HasValidNonce checks if the transaction has the valid MinWeightMagnitude. MWM corresponds to the amount of zero trits at the end of the transaction hash.
func IsTailTransaction ¶
func IsTailTransaction(t *Transaction) bool
IsTailTransaction checks if given transaction object is tail transaction. A tail transaction is one with currentIndex = 0.
func MustFinalTransactionTrytes ¶
func MustFinalTransactionTrytes(txs Transactions) []Trytes
MustFinalTransactionTrytes returns a slice of transaction trytes from the given transactions. The order of the transactions is reversed in the output slice.
func MustTransactionToTrytes ¶
func MustTransactionToTrytes(t *Transaction) Trytes
MustTransactionToTrytes converts the transaction to trytes.
func MustTransactionsToTrytes ¶
func MustTransactionsToTrytes(txs Transactions) []Trytes
MustTransactionsToTrytes returns a slice of transaction trytes from the given transactions.
func TransactionHash ¶
func TransactionHash(t *Transaction) Hash
TransactionHash makes a transaction hash from the given transaction.
func TransactionToTrits ¶
func TransactionToTrits(t *Transaction) (Trits, error)
TransactionToTrits converts the transaction to trits.
func TransactionToTrytes ¶
func TransactionToTrytes(t *Transaction) (Trytes, error)
TransactionToTrytes converts the transaction to trytes.
func TransactionsToTrytes ¶
func TransactionsToTrytes(txs Transactions) ([]Trytes, error)
TransactionsToTrytes returns a slice of transaction trytes from the given transactions.
func ValidTransactionTrytes ¶
func ValidTransactionTrytes(trytes Trytes) error
ValidTransactionTrytes checks whether the given trytes make up a valid transaction schematically.
Types ¶
type Transaction ¶
type Transaction struct {
Hash Hash `json:"hash"`
SignatureMessageFragment Trytes `json:"signatureMessageFragment"`
Address Hash `json:"address"`
Value int64 `json:"value"`
ObsoleteTag Trytes `json:"obsoleteTag"`
Timestamp uint64 `json:"timestamp"`
CurrentIndex uint64 `json:"currentIndex"`
LastIndex uint64 `json:"lastIndex"`
Bundle Hash `json:"bundle"`
TrunkTransaction Hash `json:"trunkTransaction"`
BranchTransaction Hash `json:"branchTransaction"`
Tag Trytes `json:"tag"`
AttachmentTimestamp int64 `json:"attachmentTimestamp"`
AttachmentTimestampLowerBound int64 `json:"attachmentTimestampLowerBound"`
AttachmentTimestampUpperBound int64 `json:"attachmentTimestampUpperBound"`
Nonce Trytes `json:"nonce"`
Confirmed *bool `json:"confirmed,omitempty"`
Persistence *bool `json:"persistence,omitempty"`
}
Transaction represents a single transaction.
func AsTransactionObject ¶
func AsTransactionObject(trytes Trytes, hash ...Hash) (*Transaction, error)
AsTransactionObject makes a new transaction from the given trytes. Optionally the computed transaction hash can be overwritten by supplying an own hash.
func ParseTransaction ¶
func ParseTransaction(trits Trits, noHash ...bool) (*Transaction, error)
ParseTransaction parses the trits and returns a transaction object. The trits slice must be TransactionTrinarySize in length. If noHash is set to true, no transaction hash is calculated.
type Transactions ¶
type Transactions []Transaction
Transactions is a slice of Transaction.
func AsTransactionObjects ¶
func AsTransactionObjects(rawTrytes []Trytes, hashes Hashes) (Transactions, error)
AsTransactionObjects constructs new transactions from the given raw trytes.