IssuanceInputType uint8 = iota
SpendInputType
CoinbaseInputType
+ UnvoteInputType
)
type (
switch inp := t.TypedInput.(type) {
case *SpendInput:
return inp.AssetAmount
+
+ case *UnvoteInput:
+ return inp.AssetAmount
}
return bc.AssetAmount{}
}
case *SpendInput:
return *inp.AssetId
+ case *UnvoteInput:
+ return *inp.AssetId
}
return bc.AssetID{}
}
switch inp := t.TypedInput.(type) {
case *SpendInput:
return inp.Amount
+
+ case *UnvoteInput:
+ return inp.Amount
}
return 0
}
// ControlProgram return the control program of the spend input
func (t *TxInput) ControlProgram() []byte {
- if si, ok := t.TypedInput.(*SpendInput); ok {
- return si.ControlProgram
+ switch inp := t.TypedInput.(type) {
+ case *SpendInput:
+ return inp.ControlProgram
+
+ case *UnvoteInput:
+ return inp.ControlProgram
}
+
return nil
}
switch inp := t.TypedInput.(type) {
case *SpendInput:
return inp.Arguments
+
+ case *UnvoteInput:
+ return inp.Arguments
}
return nil
}
switch inp := t.TypedInput.(type) {
case *SpendInput:
inp.Arguments = args
+
+ case *UnvoteInput:
+ inp.Arguments = args
}
}
// SpentOutputID calculate the hash of spended output
func (t *TxInput) SpentOutputID() (o bc.Hash, err error) {
- if si, ok := t.TypedInput.(*SpendInput); ok {
- o, err = ComputeOutputID(&si.SpendCommitment)
+ switch inp := t.TypedInput.(type) {
+ case *SpendInput:
+ o, err = ComputeOutputID(&inp.SpendCommitment, SpendInputType, nil)
+
+ case *UnvoteInput:
+ o, err = ComputeOutputID(&inp.SpendCommitment, UnvoteInputType, inp.Vote)
}
+
return o, err
}
return err
}
+ case UnvoteInputType:
+ ui := new(UnvoteInput)
+ t.TypedInput = ui
+ if ui.UnvoteCommitmentSuffix, err = ui.SpendCommitment.readFrom(r, 1); err != nil {
+ return err
+ }
+
default:
return fmt.Errorf("unsupported input type %d", icType[0])
}
if inp.Arguments, err = blockchain.ReadVarstrList(r); err != nil {
return err
}
+
+ case *UnvoteInput:
+ if inp.Arguments, err = blockchain.ReadVarstrList(r); err != nil {
+ return err
+ }
+ if inp.Vote, err = blockchain.ReadVarstr31(r); err != nil {
+ return err
+ }
+
}
return nil
})
if _, err = blockchain.WriteVarstr31(w, inp.Arbitrary); err != nil {
return errors.Wrap(err, "writing coinbase arbitrary")
}
+
+ case *UnvoteInput:
+ if _, err = w.Write([]byte{UnvoteInputType}); err != nil {
+ return err
+ }
+ return inp.SpendCommitment.writeExtensibleString(w, inp.UnvoteCommitmentSuffix, t.AssetVersion)
}
return nil
}
case *SpendInput:
_, err := blockchain.WriteVarstrList(w, inp.Arguments)
return err
+
+ case *UnvoteInput:
+ if _, err := blockchain.WriteVarstrList(w, inp.Arguments); err != nil {
+ return err
+ }
+ _, err := blockchain.WriteVarstr31(w, inp.Vote)
+ return err
}
return nil
}