MCPcopy Create free account
hub / github.com/chain/Core / writeContents

Method writeContents

protocol/bc/legacy/spend.go:71–105  ·  view source on GitHub ↗
(w io.Writer, suffix []byte, assetVersion uint64)

Source from the content-addressed store, hash-verified

69}
70
71func (sc *SpendCommitment) writeContents(w io.Writer, suffix []byte, assetVersion uint64) (err error) {
72 if assetVersion == 1 {
73 _, err = sc.SourceID.WriteTo(w)
74 if err != nil {
75 return errors.Wrap(err, "writing source id")
76 }
77 _, err = sc.AssetAmount.WriteTo(w)
78 if err != nil {
79 return errors.Wrap(err, "writing asset amount")
80 }
81 _, err = blockchain.WriteVarint63(w, sc.SourcePosition)
82 if err != nil {
83 return errors.Wrap(err, "writing source position")
84 }
85 _, err = blockchain.WriteVarint63(w, sc.VMVersion)
86 if err != nil {
87 return errors.Wrap(err, "writing vm version")
88 }
89 _, err = blockchain.WriteVarstr31(w, sc.ControlProgram)
90 if err != nil {
91 return errors.Wrap(err, "writing control program")
92 }
93 _, err = sc.RefDataHash.WriteTo(w)
94 if err != nil {
95 return errors.Wrap(err, "writing reference data hash")
96 }
97 }
98 if len(suffix) > 0 {
99 _, err = w.Write(suffix)
100 if err != nil {
101 return errors.Wrap(err, "writing suffix")
102 }
103 }
104 return nil
105}
106
107func (sc *SpendCommitment) readFrom(r *blockchain.Reader, assetVersion uint64) (suffix []byte, err error) {
108 return blockchain.ReadExtensibleString(r, func(r *blockchain.Reader) error {

Callers 1

writeExtensibleStringMethod · 0.95

Calls 2

WriteToMethod · 0.45
WriteMethod · 0.45

Tested by

no test coverage detected