4 "github.com/vapor/crypto/sha3pool"
5 "github.com/vapor/errors"
8 // Tx is a wrapper for the entries-based representation of a transaction.
12 Entries map[Hash]Entry
13 InputIDs []Hash // 1:1 correspondence with TxData.Inputs
20 func (tx *Tx) SigHash(n uint32) (hash Hash) {
21 hasher := sha3pool.Get256()
22 defer sha3pool.Put256(hasher)
24 tx.InputIDs[n].WriteTo(hasher)
30 // Convenience routines for accessing entries of specific types by ID.
32 ErrEntryType = errors.New("invalid entry type")
33 ErrMissingEntry = errors.New("missing entry")
36 // Output try to get the output entry by given hash
37 func (tx *Tx) Output(id Hash) (*Output, error) {
38 e, ok := tx.Entries[id]
40 return nil, errors.Wrapf(ErrMissingEntry, "id %x", id.Bytes())
44 return nil, errors.Wrapf(ErrEntryType, "entry %x has unexpected type %T", id.Bytes(), e)
49 // Spend try to get the spend entry by given hash
50 func (tx *Tx) Spend(id Hash) (*Spend, error) {
51 e, ok := tx.Entries[id]
53 return nil, errors.Wrapf(ErrMissingEntry, "id %x", id.Bytes())
57 return nil, errors.Wrapf(ErrEntryType, "entry %x has unexpected type %T", id.Bytes(), e)
62 // Issuance try to get the issuance entry by given hash
63 func (tx *Tx) Issuance(id Hash) (*Issuance, error) {
64 e, ok := tx.Entries[id]
66 return nil, errors.Wrapf(ErrMissingEntry, "id %x", id.Bytes())
68 iss, ok := e.(*Issuance)
70 return nil, errors.Wrapf(ErrEntryType, "entry %x has unexpected type %T", id.Bytes(), e)