OSDN Git Service

fix commands
[bytom/shuttle.git] / vendor / github.com / bytom / protocol / bc / types / spend.go
diff --git a/vendor/github.com/bytom/protocol/bc/types/spend.go b/vendor/github.com/bytom/protocol/bc/types/spend.go
new file mode 100644 (file)
index 0000000..2fb26cd
--- /dev/null
@@ -0,0 +1,36 @@
+package types
+
+import (
+       "github.com/bytom/protocol/bc"
+)
+
+// SpendInput satisfies the TypedInput interface and represents a spend transaction.
+type SpendInput struct {
+       SpendCommitmentSuffix []byte   // The unconsumed suffix of the output commitment
+       Arguments             [][]byte // Witness
+       SpendCommitment
+}
+
+// NewSpendInput create a new SpendInput struct.
+func NewSpendInput(arguments [][]byte, sourceID bc.Hash, assetID bc.AssetID, amount, sourcePos uint64, controlProgram []byte) *TxInput {
+       sc := SpendCommitment{
+               AssetAmount: bc.AssetAmount{
+                       AssetId: &assetID,
+                       Amount:  amount,
+               },
+               SourceID:       sourceID,
+               SourcePosition: sourcePos,
+               VMVersion:      1,
+               ControlProgram: controlProgram,
+       }
+       return &TxInput{
+               AssetVersion: 1,
+               TypedInput: &SpendInput{
+                       SpendCommitment: sc,
+                       Arguments:       arguments,
+               },
+       }
+}
+
+// InputType is the interface function for return the input type.
+func (si *SpendInput) InputType() uint8 { return SpendInputType }