OSDN Git Service

Add validate votetx (#64)
[bytom/vapor.git] / protocol / bc / tx.go
index 98ac6a8..9b00d39 100644 (file)
@@ -33,19 +33,41 @@ var (
        ErrMissingEntry = errors.New("missing entry")
 )
 
-// Output try to get the output entry by given hash
-func (tx *Tx) Output(id Hash) (*Output, error) {
+// IntraChainOutput try to get the intra-chain output entry by given hash
+func (tx *Tx) IntraChainOutput(id Hash) (*IntraChainOutput, error) {
        e, ok := tx.Entries[id]
        if !ok || e == nil {
                return nil, errors.Wrapf(ErrMissingEntry, "id %x", id.Bytes())
        }
-       o, ok := e.(*Output)
+       o, ok := e.(*IntraChainOutput)
        if !ok {
                return nil, errors.Wrapf(ErrEntryType, "entry %x has unexpected type %T", id.Bytes(), e)
        }
        return o, nil
 }
 
+// CrossChainOutput try to get the cross-chain output entry by given hash
+func (tx *Tx) CrossChainOutput(id Hash) (*CrossChainOutput, error) {
+       e, ok := tx.Entries[id]
+       if !ok || e == nil {
+               return nil, errors.Wrapf(ErrMissingEntry, "id %x", id.Bytes())
+       }
+       o, ok := e.(*CrossChainOutput)
+       if !ok {
+               return nil, errors.Wrapf(ErrEntryType, "entry %x has unexpected type %T", id.Bytes(), e)
+       }
+       return o, nil
+}
+
+// Entry try to get the  entry by given hash
+func (tx *Tx) Entry(id Hash) (Entry, error) {
+       e, ok := tx.Entries[id]
+       if !ok || e == nil {
+               return nil, errors.Wrapf(ErrMissingEntry, "id %x", id.Bytes())
+       }
+       return e, nil
+}
+
 // Spend try to get the spend entry by given hash
 func (tx *Tx) Spend(id Hash) (*Spend, error) {
        e, ok := tx.Entries[id]
@@ -71,3 +93,16 @@ func (tx *Tx) Issuance(id Hash) (*Issuance, error) {
        }
        return iss, nil
 }
+
+// VoteOutput try to get the vote output entry by given hash
+func (tx *Tx) VoteOutput(id Hash) (*VoteOutput, error) {
+       e, ok := tx.Entries[id]
+       if !ok || e == nil {
+               return nil, errors.Wrapf(ErrMissingEntry, "id %x", id.Bytes())
+       }
+       o, ok := e.(*VoteOutput)
+       if !ok {
+               return nil, errors.Wrapf(ErrEntryType, "entry %x has unexpected type %T", id.Bytes(), e)
+       }
+       return o, nil
+}