• R/O
  • HTTP
  • SSH
  • HTTPS

bytom: Commit

Official Go implementation of the Bytom protocol


Commit MetaInfo

Revisionec3f0494a6d3ff946f48722bf38ec05685e6cda8 (tree)
Time2021-06-11 11:15:24
AuthorPaladz <yzhu101@uott...>
CommiterGitHub

Log Message

edit types (#1961)

Co-authored-by: paladz <colt@ColtdeMacBook-Pro.local>

Change Summary

Incremental Difference

--- a/protocol/bc/types/coinbase.go
+++ b/protocol/bc/types/coinbase.go
@@ -30,7 +30,7 @@ func (cb *CoinbaseInput) InputType() uint8 { return CoinbaseInputType }
3030
3131 func (cb *CoinbaseInput) readCommitment(r *blockchain.Reader) (err error) {
3232 cb.Arbitrary, err = blockchain.ReadVarstr31(r)
33- return
33+ return err
3434 }
3535
3636 func (cb *CoinbaseInput) readWitness(_ *blockchain.Reader) error { return nil }
--- a/protocol/bc/types/issuance.go
+++ b/protocol/bc/types/issuance.go
@@ -5,9 +5,12 @@ import (
55
66 "github.com/bytom/bytom/crypto/sha3pool"
77 "github.com/bytom/bytom/encoding/blockchain"
8+ "github.com/bytom/bytom/errors"
89 "github.com/bytom/bytom/protocol/bc"
910 )
1011
12+var errBadAssetID = errors.New("asset ID does not match other issuance parameters")
13+
1114 // IssuanceInput satisfies the TypedInput interface and represents a issuance.
1215 type IssuanceInput struct {
1316 Nonce []byte
--- a/protocol/bc/types/spend.go
+++ b/protocol/bc/types/spend.go
@@ -46,7 +46,7 @@ func (si *SpendInput) InputType() uint8 { return SpendInputType }
4646
4747 func (si *SpendInput) readCommitment(r *blockchain.Reader) (err error) {
4848 si.SpendCommitmentSuffix, err = si.SpendCommitment.readFrom(r, 1)
49- return
49+ return err
5050 }
5151
5252 func (si *SpendInput) readWitness(r *blockchain.Reader) (err error) {
--- a/protocol/bc/types/transaction.go
+++ b/protocol/bc/types/transaction.go
@@ -53,6 +53,8 @@ func (tx *Tx) SetInputArguments(n uint32, args [][]byte) {
5353 e.WitnessArguments = args
5454 case *bc.Spend:
5555 e.WitnessArguments = args
56+ case *bc.VetoInput:
57+ e.WitnessArguments = args
5658 }
5759 }
5860
@@ -101,6 +103,7 @@ func (tx *TxData) readFrom(r *blockchain.Reader) (err error) {
101103 if _, err = io.ReadFull(r, serflags[:]); err != nil {
102104 return errors.Wrap(err, "reading serialization flags")
103105 }
106+
104107 if serflags[0] != serRequired {
105108 return fmt.Errorf("unsupported serflags %#x", serflags[0])
106109 }
@@ -108,6 +111,7 @@ func (tx *TxData) readFrom(r *blockchain.Reader) (err error) {
108111 if tx.Version, err = blockchain.ReadVarint63(r); err != nil {
109112 return errors.Wrap(err, "reading transaction version")
110113 }
114+
111115 if tx.TimeRange, err = blockchain.ReadVarint63(r); err != nil {
112116 return err
113117 }
@@ -122,6 +126,7 @@ func (tx *TxData) readFrom(r *blockchain.Reader) (err error) {
122126 if err = ti.readFrom(r); err != nil {
123127 return errors.Wrapf(err, "reading input %d", len(tx.Inputs))
124128 }
129+
125130 tx.Inputs = append(tx.Inputs, ti)
126131 }
127132
@@ -135,8 +140,10 @@ func (tx *TxData) readFrom(r *blockchain.Reader) (err error) {
135140 if err = to.readFrom(r); err != nil {
136141 return errors.Wrapf(err, "reading output %d", len(tx.Outputs))
137142 }
143+
138144 tx.Outputs = append(tx.Outputs, to)
139145 }
146+
140147 tx.SerializedSize = uint64(startSerializedSize - r.Len())
141148 return nil
142149 }
@@ -147,6 +154,7 @@ func (tx *TxData) WriteTo(w io.Writer) (int64, error) {
147154 if err := tx.writeTo(ew, serRequired); err != nil {
148155 return 0, err
149156 }
157+
150158 return ew.Written(), ew.Err()
151159 }
152160
@@ -154,9 +162,11 @@ func (tx *TxData) writeTo(w io.Writer, serflags byte) error {
154162 if _, err := w.Write([]byte{serflags}); err != nil {
155163 return errors.Wrap(err, "writing serialization flags")
156164 }
165+
157166 if _, err := blockchain.WriteVarint63(w, tx.Version); err != nil {
158167 return errors.Wrap(err, "writing transaction version")
159168 }
169+
160170 if _, err := blockchain.WriteVarint63(w, tx.TimeRange); err != nil {
161171 return errors.Wrap(err, "writing transaction maxtime")
162172 }
@@ -182,4 +192,3 @@ func (tx *TxData) writeTo(w io.Writer, serflags byte) error {
182192 }
183193 return nil
184194 }
185-
--- a/protocol/bc/types/txinput.go
+++ b/protocol/bc/types/txinput.go
@@ -58,8 +58,6 @@ type (
5858 }
5959 )
6060
61-var errBadAssetID = errors.New("asset ID does not match other issuance parameters")
62-
6361 // Amount return the asset amount of the txinput
6462 func (t *TxInput) Amount() uint64 {
6563 switch inp := t.TypedInput.(type) {
--- a/protocol/bc/types/txoutput.go
+++ b/protocol/bc/types/txoutput.go
@@ -33,6 +33,25 @@ type TypedOutput interface {
3333 writeTo(io.Writer) error
3434 }
3535
36+var outputTypeMap = map[uint8]func() TypedOutput{
37+ OriginalOutputType: func() TypedOutput { return &originalTxOutput{} },
38+ VoteOutputType: func() TypedOutput { return &VoteOutput{} },
39+}
40+
41+func parseTypedOutput(r *blockchain.Reader) (TypedOutput, error) {
42+ var outType [1]byte
43+ if _, err := io.ReadFull(r, outType[:]); err != nil {
44+ return nil, errors.Wrap(err, "reading output type")
45+ }
46+
47+ newOutFun, ok := outputTypeMap[outType[0]]
48+ if !ok {
49+ return nil, fmt.Errorf("unsupported output type %d", outType[0])
50+ }
51+
52+ return newOutFun(), nil
53+}
54+
3655 func (to *TxOutput) readFrom(r *blockchain.Reader) (err error) {
3756 if to.AssetVersion, err = blockchain.ReadVarint63(r); err != nil {
3857 return errors.Wrap(err, "reading asset version")
@@ -58,25 +77,6 @@ func (to *TxOutput) readFrom(r *blockchain.Reader) (err error) {
5877 return errors.Wrap(err, "reading output witness")
5978 }
6079
61-var outputTypeMap = map[uint8]func() TypedOutput{
62- OriginalOutputType: func() TypedOutput { return &originalTxOutput{} },
63- VoteOutputType: func() TypedOutput { return &VoteOutput{} },
64-}
65-
66-func parseTypedOutput(r *blockchain.Reader) (TypedOutput, error) {
67- var outType [1]byte
68- if _, err := io.ReadFull(r, outType[:]); err != nil {
69- return nil, errors.Wrap(err, "reading output type")
70- }
71-
72- newOutFun, ok := outputTypeMap[outType[0]]
73- if !ok {
74- return nil, fmt.Errorf("unsupported output type %d", outType[0])
75- }
76-
77- return newOutFun(), nil
78-}
79-
8080 func (to *TxOutput) writeTo(w io.Writer) error {
8181 if _, err := blockchain.WriteVarint63(w, to.AssetVersion); err != nil {
8282 return errors.Wrap(err, "writing asset version")
@@ -115,8 +115,7 @@ func ComputeOutputID(sc *SpendCommitment) (h bc.Hash, err error) {
115115 Value: &sc.AssetAmount,
116116 Position: sc.SourcePosition,
117117 }
118- o := bc.NewOutput(src, &bc.Program{VmVersion: sc.VMVersion, Code: sc.ControlProgram}, &bc.StateData{StateData: sc.StateData}, 0)
119118
120- h = bc.EntryID(o)
121- return h, nil
119+ o := bc.NewOutput(src, &bc.Program{VmVersion: sc.VMVersion, Code: sc.ControlProgram}, &bc.StateData{StateData: sc.StateData}, 0)
120+ return bc.EntryID(o), nil
122121 }
Show on old repository browser