github.com/bytom/bytom@v1.1.2-0.20221014091027-bbcba3df6075/protocol/bc/types/coinbase.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 // CoinbaseInput records the coinbase message 11 type CoinbaseInput struct { 12 Arbitrary []byte 13 } 14 15 // NewCoinbaseInput creates a new coinbase input struct 16 func NewCoinbaseInput(arbitrary []byte) *TxInput { 17 return &TxInput{ 18 AssetVersion: 1, 19 TypedInput: &CoinbaseInput{Arbitrary: arbitrary}, 20 } 21 } 22 23 // AssetID implement the TypedInput. 24 func (cb *CoinbaseInput) AssetID() bc.AssetID { 25 return bc.AssetID{} 26 } 27 28 // InputType is the interface function for return the input type 29 func (cb *CoinbaseInput) InputType() uint8 { return CoinbaseInputType } 30 31 func (cb *CoinbaseInput) readCommitment(r *blockchain.Reader) (err error) { 32 cb.Arbitrary, err = blockchain.ReadVarstr31(r) 33 return err 34 } 35 36 func (cb *CoinbaseInput) readWitness(_ *blockchain.Reader) error { return nil } 37 38 func (cb *CoinbaseInput) writeCommitment(w io.Writer, _ uint64) error { 39 if _, err := w.Write([]byte{CoinbaseInputType}); err != nil { 40 return err 41 } 42 43 _, err := blockchain.WriteVarstr31(w, cb.Arbitrary) 44 return err 45 } 46 47 func (cb *CoinbaseInput) writeWitness(_ io.Writer) error { return nil }