-
Notifications
You must be signed in to change notification settings - Fork 0
/
coinbase.go
47 lines (36 loc) · 1.15 KB
/
coinbase.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package types
import (
"io"
"github.com/bytom/bystack/encoding/blockchain"
"github.com/bytom/bystack/protocol/bc"
)
// CoinbaseInput records the coinbase message
type CoinbaseInput struct {
Arbitrary []byte
}
// NewCoinbaseInput creates a new coinbase input struct
func NewCoinbaseInput(arbitrary []byte) *TxInput {
return &TxInput{
AssetVersion: 1,
TypedInput: &CoinbaseInput{Arbitrary: arbitrary},
}
}
// AssetID implement the TypedInput.
func (cb *CoinbaseInput) AssetID() bc.AssetID {
return bc.AssetID{}
}
// InputType is the interface function for return the input type
func (cb *CoinbaseInput) InputType() uint8 { return CoinbaseInputType }
func (cb *CoinbaseInput) readCommitment(r *blockchain.Reader) (err error) {
cb.Arbitrary, err = blockchain.ReadVarstr31(r)
return err
}
func (cb *CoinbaseInput) readWitness(_ *blockchain.Reader) error { return nil }
func (cb *CoinbaseInput) writeCommitment(w io.Writer, _ uint64) error {
if _, err := w.Write([]byte{CoinbaseInputType}); err != nil {
return err
}
_, err := blockchain.WriteVarstr31(w, cb.Arbitrary)
return err
}
func (cb *CoinbaseInput) writeWitness(_ io.Writer) error { return nil }