github.com/bytom/bytom@v1.1.2-0.20221014091027-bbcba3df6075/protocol/bc/types/veto_input.go (about) 1 package types 2 3 import ( 4 "io" 5 6 "github.com/bytom/bytom/encoding/blockchain" 7 "github.com/bytom/bytom/protocol/bc" 8 ) 9 10 // VetoInput satisfies the TypedInput interface and represents a veto transaction. 11 type VetoInput struct { 12 VetoCommitmentSuffix []byte // The unconsumed suffix of the output commitment 13 Arguments [][]byte // Witness 14 Vote []byte // voter xpub 15 SpendCommitment 16 } 17 18 // NewVetoInput create a new VetoInput struct. 19 func NewVetoInput(arguments [][]byte, sourceID bc.Hash, assetID bc.AssetID, amount, sourcePos uint64, controlProgram []byte, vote []byte, stateData [][]byte) *TxInput { 20 sc := SpendCommitment{ 21 AssetAmount: bc.AssetAmount{ 22 AssetId: &assetID, 23 Amount: amount, 24 }, 25 SourceID: sourceID, 26 SourcePosition: sourcePos, 27 VMVersion: 1, 28 ControlProgram: controlProgram, 29 StateData: stateData, 30 } 31 return &TxInput{ 32 AssetVersion: 1, 33 TypedInput: &VetoInput{ 34 SpendCommitment: sc, 35 Arguments: arguments, 36 Vote: vote, 37 }, 38 } 39 } 40 41 // AssetID implement the TypedInput. 42 func (vi *VetoInput) AssetID() bc.AssetID { 43 return *vi.AssetId 44 } 45 46 // InputType is the interface function for return the input type. 47 func (vi *VetoInput) InputType() uint8 { return VetoInputType } 48 49 func (vi *VetoInput) readCommitment(r *blockchain.Reader) (err error) { 50 if vi.VetoCommitmentSuffix, err = vi.SpendCommitment.readFrom(r, 1); err != nil { 51 return 52 } 53 54 vi.Vote, err = blockchain.ReadVarstr31(r) 55 return 56 } 57 58 func (vi *VetoInput) readWitness(r *blockchain.Reader) (err error) { 59 vi.Arguments, err = blockchain.ReadVarstrList(r) 60 return err 61 } 62 63 func (vi *VetoInput) writeCommitment(w io.Writer, assetVersion uint64) error { 64 if _, err := w.Write([]byte{VetoInputType}); err != nil { 65 return err 66 } 67 68 if err := vi.SpendCommitment.writeExtensibleString(w, vi.VetoCommitmentSuffix, assetVersion); err != nil { 69 return err 70 } 71 72 _, err := blockchain.WriteVarstr31(w, vi.Vote) 73 return err 74 } 75 76 func (vi *VetoInput) writeWitness(w io.Writer) error { 77 _, err := blockchain.WriteVarstrList(w, vi.Arguments) 78 return err 79 }