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

Method WriteInputCommitment

protocol/bc/legacy/txinput.go:234–270  ·  view source on GitHub ↗
(w io.Writer, serflags uint8)

Source from the content-addressed store, hash-verified

232}
233
234func (t *TxInput) WriteInputCommitment(w io.Writer, serflags uint8) error {
235 if t.AssetVersion != 1 {
236 return nil
237 }
238 switch inp := t.TypedInput.(type) {
239 case *IssuanceInput:
240 _, err := w.Write([]byte{0}) // issuance type
241 if err != nil {
242 return err
243 }
244 _, err = blockchain.WriteVarstr31(w, inp.Nonce)
245 if err != nil {
246 return err
247 }
248 assetID := t.AssetID()
249 _, err = assetID.WriteTo(w)
250 if err != nil {
251 return err
252 }
253 _, err = blockchain.WriteVarint63(w, inp.Amount)
254 return err
255
256 case *SpendInput:
257 _, err := w.Write([]byte{1}) // spend type
258 if err != nil {
259 return err
260 }
261 if serflags&SerPrevout != 0 {
262 err = inp.SpendCommitment.writeExtensibleString(w, inp.SpendCommitmentSuffix, t.AssetVersion)
263 } else {
264 prevouthash := inp.SpendCommitment.Hash(inp.SpendCommitmentSuffix, t.AssetVersion)
265 _, err = prevouthash.WriteTo(w)
266 }
267 return err
268 }
269 return nil
270}
271
272func (t *TxInput) writeInputWitness(w io.Writer) error {
273 if t.AssetVersion != 1 {

Callers 1

writeToMethod · 0.95

Calls 5

AssetIDMethod · 0.95
WriteMethod · 0.45
WriteToMethod · 0.45
writeExtensibleStringMethod · 0.45
HashMethod · 0.45

Tested by

no test coverage detected