Official Go implementation of the Bytom protocol
Révision | 0252d7f508fc5a71f0f5bf54567f6052fccc7597 (tree) |
---|---|
l'heure | 2021-06-10 12:58:19 |
Auteur | paladz <colt@Colt...> |
Commiter | paladz |
edit issuance
@@ -28,12 +28,12 @@ func (cb *CoinbaseInput) AssetID() bc.AssetID { | ||
28 | 28 | // InputType is the interface function for return the input type |
29 | 29 | func (cb *CoinbaseInput) InputType() uint8 { return CoinbaseInputType } |
30 | 30 | |
31 | -func (cb *CoinbaseInput) readCommitment(r *blockchain.Reader) (_ bc.AssetID, err error) { | |
31 | +func (cb *CoinbaseInput) readCommitment(r *blockchain.Reader) (err error) { | |
32 | 32 | cb.Arbitrary, err = blockchain.ReadVarstr31(r) |
33 | 33 | return |
34 | 34 | } |
35 | 35 | |
36 | -func (cb *CoinbaseInput) readWitness(_ *blockchain.Reader, _ bc.AssetID) error { return nil } | |
36 | +func (cb *CoinbaseInput) readWitness(_ *blockchain.Reader) error { return nil } | |
37 | 37 | |
38 | 38 | func (cb *CoinbaseInput) writeCommitment(w io.Writer, _ uint64) error { |
39 | 39 | if _, err := w.Write([]byte{CoinbaseInputType}); err != nil { |
@@ -17,6 +17,8 @@ type IssuanceInput struct { | ||
17 | 17 | VMVersion uint64 |
18 | 18 | IssuanceProgram []byte |
19 | 19 | Arguments [][]byte |
20 | + | |
21 | + assetId bc.AssetID | |
20 | 22 | } |
21 | 23 | |
22 | 24 | // NewIssuanceInput create a new IssuanceInput struct. |
@@ -45,8 +47,11 @@ func (ii *IssuanceInput) AssetDefinitionHash() (defhash bc.Hash) { | ||
45 | 47 | |
46 | 48 | // AssetID calculate the assetID of the issuance input. |
47 | 49 | func (ii *IssuanceInput) AssetID() bc.AssetID { |
48 | - defhash := ii.AssetDefinitionHash() | |
49 | - return bc.ComputeAssetID(ii.IssuanceProgram, ii.VMVersion, &defhash) | |
50 | + if ii.assetId.IsZero() { | |
51 | + ii.assetId = ii.calcAssetID() | |
52 | + } | |
53 | + | |
54 | + return ii.assetId | |
50 | 55 | } |
51 | 56 | |
52 | 57 | // InputType is the interface function for return the input type. |
@@ -61,12 +66,17 @@ func (ii *IssuanceInput) NonceHash() (hash bc.Hash) { | ||
61 | 66 | return hash |
62 | 67 | } |
63 | 68 | |
64 | -func (ii *IssuanceInput) readCommitment(r *blockchain.Reader) (assetID bc.AssetID, err error) { | |
69 | +func (ii *IssuanceInput) calcAssetID() bc.AssetID { | |
70 | + defhash := ii.AssetDefinitionHash() | |
71 | + return bc.ComputeAssetID(ii.IssuanceProgram, ii.VMVersion, &defhash) | |
72 | +} | |
73 | + | |
74 | +func (ii *IssuanceInput) readCommitment(r *blockchain.Reader) (err error) { | |
65 | 75 | if ii.Nonce, err = blockchain.ReadVarstr31(r); err != nil { |
66 | 76 | return |
67 | 77 | } |
68 | 78 | |
69 | - if _, err = assetID.ReadFrom(r); err != nil { | |
79 | + if _, err = ii.assetId.ReadFrom(r); err != nil { | |
70 | 80 | return |
71 | 81 | } |
72 | 82 |
@@ -74,7 +84,7 @@ func (ii *IssuanceInput) readCommitment(r *blockchain.Reader) (assetID bc.AssetI | ||
74 | 84 | return |
75 | 85 | } |
76 | 86 | |
77 | -func (ii *IssuanceInput) readWitness(r *blockchain.Reader, assetID bc.AssetID) (err error) { | |
87 | +func (ii *IssuanceInput) readWitness(r *blockchain.Reader) (err error) { | |
78 | 88 | if ii.AssetDefinition, err = blockchain.ReadVarstr31(r); err != nil { |
79 | 89 | return err |
80 | 90 | } |
@@ -87,7 +97,7 @@ func (ii *IssuanceInput) readWitness(r *blockchain.Reader, assetID bc.AssetID) ( | ||
87 | 97 | return err |
88 | 98 | } |
89 | 99 | |
90 | - if ii.AssetID() != assetID { | |
100 | + if ii.calcAssetID() != ii.assetId { | |
91 | 101 | return errBadAssetID |
92 | 102 | } |
93 | 103 |
@@ -44,12 +44,12 @@ func (si *SpendInput) AssetID() bc.AssetID { | ||
44 | 44 | // InputType is the interface function for return the input type. |
45 | 45 | func (si *SpendInput) InputType() uint8 { return SpendInputType } |
46 | 46 | |
47 | -func (si *SpendInput) readCommitment(r *blockchain.Reader) (assetID bc.AssetID, err error) { | |
47 | +func (si *SpendInput) readCommitment(r *blockchain.Reader) (err error) { | |
48 | 48 | si.SpendCommitmentSuffix, err = si.SpendCommitment.readFrom(r, 1) |
49 | 49 | return |
50 | 50 | } |
51 | 51 | |
52 | -func (si *SpendInput) readWitness(r *blockchain.Reader, _ bc.AssetID) (err error) { | |
52 | +func (si *SpendInput) readWitness(r *blockchain.Reader) (err error) { | |
53 | 53 | si.Arguments, err = blockchain.ReadVarstrList(r) |
54 | 54 | return err |
55 | 55 | } |
@@ -51,8 +51,8 @@ type ( | ||
51 | 51 | TypedInput interface { |
52 | 52 | InputType() uint8 |
53 | 53 | AssetID() bc.AssetID |
54 | - readCommitment(*blockchain.Reader) (bc.AssetID, error) | |
55 | - readWitness(*blockchain.Reader, bc.AssetID) error | |
54 | + readCommitment(*blockchain.Reader) error | |
55 | + readWitness(*blockchain.Reader) error | |
56 | 56 | writeCommitment(io.Writer, uint64) error |
57 | 57 | writeWitness(w io.Writer) error |
58 | 58 | } |
@@ -127,7 +127,6 @@ func (t *TxInput) readFrom(r *blockchain.Reader) (err error) { | ||
127 | 127 | return err |
128 | 128 | } |
129 | 129 | |
130 | - var assetID bc.AssetID | |
131 | 130 | t.CommitmentSuffix, err = blockchain.ReadExtensibleString(r, func(r *blockchain.Reader) error { |
132 | 131 | if t.AssetVersion != 1 { |
133 | 132 | return nil |
@@ -137,8 +136,7 @@ func (t *TxInput) readFrom(r *blockchain.Reader) (err error) { | ||
137 | 136 | return err |
138 | 137 | } |
139 | 138 | |
140 | - assetID, err = t.readCommitment(r) | |
141 | - return err | |
139 | + return t.readCommitment(r) | |
142 | 140 | }) |
143 | 141 | if err != nil { |
144 | 142 | return err |
@@ -146,7 +144,7 @@ func (t *TxInput) readFrom(r *blockchain.Reader) (err error) { | ||
146 | 144 | |
147 | 145 | t.WitnessSuffix, err = blockchain.ReadExtensibleString(r, func(r *blockchain.Reader) error { |
148 | 146 | if t.AssetVersion == 1 { |
149 | - return t.readWitness(r, assetID) | |
147 | + return t.readWitness(r) | |
150 | 148 | } |
151 | 149 | |
152 | 150 | return nil |
@@ -46,7 +46,7 @@ func (vi *VetoInput) AssetID() bc.AssetID { | ||
46 | 46 | // InputType is the interface function for return the input type. |
47 | 47 | func (vi *VetoInput) InputType() uint8 { return VetoInputType } |
48 | 48 | |
49 | -func (vi *VetoInput) readCommitment(r *blockchain.Reader) (assetID bc.AssetID, err error) { | |
49 | +func (vi *VetoInput) readCommitment(r *blockchain.Reader) (err error) { | |
50 | 50 | if vi.VetoCommitmentSuffix, err = vi.SpendCommitment.readFrom(r, 1); err != nil { |
51 | 51 | return |
52 | 52 | } |
@@ -55,7 +55,7 @@ func (vi *VetoInput) readCommitment(r *blockchain.Reader) (assetID bc.AssetID, e | ||
55 | 55 | return |
56 | 56 | } |
57 | 57 | |
58 | -func (vi *VetoInput) readWitness(r *blockchain.Reader, _ bc.AssetID) (err error) { | |
58 | +func (vi *VetoInput) readWitness(r *blockchain.Reader) (err error) { | |
59 | 59 | vi.Arguments, err = blockchain.ReadVarstrList(r) |
60 | 60 | return err |
61 | 61 | } |