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 // IntraChainOutput try to get the intra-chain output entry by given hash
37 func (tx *Tx) IntraChainOutput(id Hash) (*IntraChainOutput, error) {
38 e, ok := tx.Entries[id]
40 return nil, errors.Wrapf(ErrMissingEntry, "id %x", id.Bytes())
42 o, ok := e.(*IntraChainOutput)
44 return nil, errors.Wrapf(ErrEntryType, "entry %x has unexpected type %T", id.Bytes(), e)
49 // CrossChainOutput try to get the cross-chain output entry by given hash
50 func (tx *Tx) CrossChainOutput(id Hash) (*CrossChainOutput, error) {
51 e, ok := tx.Entries[id]
53 return nil, errors.Wrapf(ErrMissingEntry, "id %x", id.Bytes())
55 o, ok := e.(*CrossChainOutput)
57 return nil, errors.Wrapf(ErrEntryType, "entry %x has unexpected type %T", id.Bytes(), e)
62 // Entry try to get the entry by given hash
63 func (tx *Tx) Entry(id Hash) (Entry, error) {
64 e, ok := tx.Entries[id]
66 return nil, errors.Wrapf(ErrMissingEntry, "id %x", id.Bytes())
71 // Spend try to get the spend entry by given hash
72 func (tx *Tx) Spend(id Hash) (*Spend, error) {
73 e, ok := tx.Entries[id]
75 return nil, errors.Wrapf(ErrMissingEntry, "id %x", id.Bytes())
79 return nil, errors.Wrapf(ErrEntryType, "entry %x has unexpected type %T", id.Bytes(), e)
84 // VoteOutput try to get the vote output entry by given hash
85 func (tx *Tx) VoteOutput(id Hash) (*VoteOutput, error) {
86 e, ok := tx.Entries[id]
88 return nil, errors.Wrapf(ErrMissingEntry, "id %x", id.Bytes())
90 o, ok := e.(*VoteOutput)
92 return nil, errors.Wrapf(ErrEntryType, "entry %x has unexpected type %T", id.Bytes(), e)