• R/O
  • HTTP
  • SSH
  • HTTPS

bytom: Commit

Official Go implementation of the Bytom protocol


Commit MetaInfo

Révision0252d7f508fc5a71f0f5bf54567f6052fccc7597 (tree)
l'heure2021-06-10 12:58:19
Auteurpaladz <colt@Colt...>
Commiterpaladz

Message de Log

edit issuance

Change Summary

Modification

--- a/protocol/bc/types/coinbase.go
+++ b/protocol/bc/types/coinbase.go
@@ -28,12 +28,12 @@ func (cb *CoinbaseInput) AssetID() bc.AssetID {
2828 // InputType is the interface function for return the input type
2929 func (cb *CoinbaseInput) InputType() uint8 { return CoinbaseInputType }
3030
31-func (cb *CoinbaseInput) readCommitment(r *blockchain.Reader) (_ bc.AssetID, err error) {
31+func (cb *CoinbaseInput) readCommitment(r *blockchain.Reader) (err error) {
3232 cb.Arbitrary, err = blockchain.ReadVarstr31(r)
3333 return
3434 }
3535
36-func (cb *CoinbaseInput) readWitness(_ *blockchain.Reader, _ bc.AssetID) error { return nil }
36+func (cb *CoinbaseInput) readWitness(_ *blockchain.Reader) error { return nil }
3737
3838 func (cb *CoinbaseInput) writeCommitment(w io.Writer, _ uint64) error {
3939 if _, err := w.Write([]byte{CoinbaseInputType}); err != nil {
--- a/protocol/bc/types/issuance.go
+++ b/protocol/bc/types/issuance.go
@@ -17,6 +17,8 @@ type IssuanceInput struct {
1717 VMVersion uint64
1818 IssuanceProgram []byte
1919 Arguments [][]byte
20+
21+ assetId bc.AssetID
2022 }
2123
2224 // NewIssuanceInput create a new IssuanceInput struct.
@@ -45,8 +47,11 @@ func (ii *IssuanceInput) AssetDefinitionHash() (defhash bc.Hash) {
4547
4648 // AssetID calculate the assetID of the issuance input.
4749 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
5055 }
5156
5257 // InputType is the interface function for return the input type.
@@ -61,12 +66,17 @@ func (ii *IssuanceInput) NonceHash() (hash bc.Hash) {
6166 return hash
6267 }
6368
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) {
6575 if ii.Nonce, err = blockchain.ReadVarstr31(r); err != nil {
6676 return
6777 }
6878
69- if _, err = assetID.ReadFrom(r); err != nil {
79+ if _, err = ii.assetId.ReadFrom(r); err != nil {
7080 return
7181 }
7282
@@ -74,7 +84,7 @@ func (ii *IssuanceInput) readCommitment(r *blockchain.Reader) (assetID bc.AssetI
7484 return
7585 }
7686
77-func (ii *IssuanceInput) readWitness(r *blockchain.Reader, assetID bc.AssetID) (err error) {
87+func (ii *IssuanceInput) readWitness(r *blockchain.Reader) (err error) {
7888 if ii.AssetDefinition, err = blockchain.ReadVarstr31(r); err != nil {
7989 return err
8090 }
@@ -87,7 +97,7 @@ func (ii *IssuanceInput) readWitness(r *blockchain.Reader, assetID bc.AssetID) (
8797 return err
8898 }
8999
90- if ii.AssetID() != assetID {
100+ if ii.calcAssetID() != ii.assetId {
91101 return errBadAssetID
92102 }
93103
--- a/protocol/bc/types/spend.go
+++ b/protocol/bc/types/spend.go
@@ -44,12 +44,12 @@ func (si *SpendInput) AssetID() bc.AssetID {
4444 // InputType is the interface function for return the input type.
4545 func (si *SpendInput) InputType() uint8 { return SpendInputType }
4646
47-func (si *SpendInput) readCommitment(r *blockchain.Reader) (assetID bc.AssetID, err error) {
47+func (si *SpendInput) readCommitment(r *blockchain.Reader) (err error) {
4848 si.SpendCommitmentSuffix, err = si.SpendCommitment.readFrom(r, 1)
4949 return
5050 }
5151
52-func (si *SpendInput) readWitness(r *blockchain.Reader, _ bc.AssetID) (err error) {
52+func (si *SpendInput) readWitness(r *blockchain.Reader) (err error) {
5353 si.Arguments, err = blockchain.ReadVarstrList(r)
5454 return err
5555 }
--- a/protocol/bc/types/txinput.go
+++ b/protocol/bc/types/txinput.go
@@ -51,8 +51,8 @@ type (
5151 TypedInput interface {
5252 InputType() uint8
5353 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
5656 writeCommitment(io.Writer, uint64) error
5757 writeWitness(w io.Writer) error
5858 }
@@ -127,7 +127,6 @@ func (t *TxInput) readFrom(r *blockchain.Reader) (err error) {
127127 return err
128128 }
129129
130- var assetID bc.AssetID
131130 t.CommitmentSuffix, err = blockchain.ReadExtensibleString(r, func(r *blockchain.Reader) error {
132131 if t.AssetVersion != 1 {
133132 return nil
@@ -137,8 +136,7 @@ func (t *TxInput) readFrom(r *blockchain.Reader) (err error) {
137136 return err
138137 }
139138
140- assetID, err = t.readCommitment(r)
141- return err
139+ return t.readCommitment(r)
142140 })
143141 if err != nil {
144142 return err
@@ -146,7 +144,7 @@ func (t *TxInput) readFrom(r *blockchain.Reader) (err error) {
146144
147145 t.WitnessSuffix, err = blockchain.ReadExtensibleString(r, func(r *blockchain.Reader) error {
148146 if t.AssetVersion == 1 {
149- return t.readWitness(r, assetID)
147+ return t.readWitness(r)
150148 }
151149
152150 return nil
--- a/protocol/bc/types/veto_input.go
+++ b/protocol/bc/types/veto_input.go
@@ -46,7 +46,7 @@ func (vi *VetoInput) AssetID() bc.AssetID {
4646 // InputType is the interface function for return the input type.
4747 func (vi *VetoInput) InputType() uint8 { return VetoInputType }
4848
49-func (vi *VetoInput) readCommitment(r *blockchain.Reader) (assetID bc.AssetID, err error) {
49+func (vi *VetoInput) readCommitment(r *blockchain.Reader) (err error) {
5050 if vi.VetoCommitmentSuffix, err = vi.SpendCommitment.readFrom(r, 1); err != nil {
5151 return
5252 }
@@ -55,7 +55,7 @@ func (vi *VetoInput) readCommitment(r *blockchain.Reader) (assetID bc.AssetID, e
5555 return
5656 }
5757
58-func (vi *VetoInput) readWitness(r *blockchain.Reader, _ bc.AssetID) (err error) {
58+func (vi *VetoInput) readWitness(r *blockchain.Reader) (err error) {
5959 vi.Arguments, err = blockchain.ReadVarstrList(r)
6060 return err
6161 }
Afficher sur ancien navigateur de dépôt.