OSDN Git Service

feat: add cross-chain output (#56)
[bytom/vapor.git] / protocol / bc / tx.go
index 98ac6a8..c07ed0f 100644 (file)
@@ -33,13 +33,26 @@ 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)
        }