type Nonce struct {
Program *Program `protobuf:"bytes,1,opt,name=program" json:"program,omitempty"`
- TimeRangeId *Hash `protobuf:"bytes,2,opt,name=time_range_id,json=timeRangeId" json:"time_range_id,omitempty"`
- ExtHash *Hash `protobuf:"bytes,3,opt,name=ext_hash,json=extHash" json:"ext_hash,omitempty"`
- WitnessArguments [][]byte `protobuf:"bytes,4,rep,name=witness_arguments,json=witnessArguments,proto3" json:"witness_arguments,omitempty"`
- WitnessAnchoredId *Hash `protobuf:"bytes,5,opt,name=witness_anchored_id,json=witnessAnchoredId" json:"witness_anchored_id,omitempty"`
+ ExtHash *Hash `protobuf:"bytes,2,opt,name=ext_hash,json=extHash" json:"ext_hash,omitempty"`
+ WitnessArguments [][]byte `protobuf:"bytes,3,rep,name=witness_arguments,json=witnessArguments,proto3" json:"witness_arguments,omitempty"`
+ WitnessAnchoredId *Hash `protobuf:"bytes,4,opt,name=witness_anchored_id,json=witnessAnchoredId" json:"witness_anchored_id,omitempty"`
}
func (m *Nonce) Reset() { *m = Nonce{} }
return nil
}
-func (m *Nonce) GetTimeRangeId() *Hash {
- if m != nil {
- return m.TimeRangeId
- }
- return nil
-}
-
func (m *Nonce) GetExtHash() *Hash {
if m != nil {
return m.ExtHash
message Nonce {
Program program = 1;
- Hash time_range_id = 2;
- Hash ext_hash = 3;
- repeated bytes witness_arguments = 4;
- Hash witness_anchored_id = 5;
+ Hash ext_hash = 2;
+ repeated bytes witness_arguments = 3;
+ Hash witness_anchored_id = 4;
}
message Coinbase {
)
if len(oldIss.Nonce) > 0 {
- tr := bc.NewTimeRange(tx.MinTime, tx.MaxTime)
- trID := addEntry(tr)
assetID := oldIss.AssetID()
builder := vmutil.NewBuilder()
builder.AddOp(vm.OP_ASSET).AddData(assetID.Bytes()).AddOp(vm.OP_EQUAL)
prog, _ := builder.Build() // error is impossible
- nonce := bc.NewNonce(&bc.Program{VmVersion: 1, Code: prog}, &trID)
+ nonce := bc.NewNonce(&bc.Program{VmVersion: 1, Code: prog})
anchorID = addEntry(nonce)
setAnchored = nonce.SetAnchored
} else if firstSpend != nil {
func (Nonce) typ() string { return "nonce1" }
func (n *Nonce) writeForHash(w io.Writer) {
mustWriteForHash(w, n.Program)
- mustWriteForHash(w, n.TimeRangeId)
mustWriteForHash(w, n.ExtHash)
}
// NewNonce creates a new Nonce.
-func NewNonce(p *Program, trID *Hash) *Nonce {
+func NewNonce(p *Program) *Nonce {
return &Nonce{
- Program: p,
- TimeRangeId: trID,
+ Program: p,
}
}
}
case *bc.Nonce:
+ //TODO: add block heigh range check on the control program
gasLeft, err := vm.Verify(NewTxVMContext(vs.tx, e, e.Program, e.WitnessArguments), int64(vs.gas.gasLeft))
vs.gas.updateUsage(gasLeft)
if err != nil {
return errors.Wrap(err, "checking nonce program")
}
- tr, err := vs.tx.TimeRange(*e.TimeRangeId)
- if err != nil {
- return errors.Wrap(err, "getting nonce timerange")
- }
- vs2 := *vs
- vs2.entryID = *e.TimeRangeId
- err = checkValid(&vs2, tr)
- if err != nil {
- return errors.Wrap(err, "checking nonce timerange")
- }
-
- if tr.MinTimeMs == 0 || tr.MaxTimeMs == 0 {
- return errZeroTime
- }
if vs.tx.Version == 1 && e.ExtHash != nil && !e.ExtHash.IsZero() {
return errNonemptyExtHash
return errNonemptyExtHash
}
- case *bc.TimeRange:
- if e.MinTimeMs > vs.tx.MinTimeMs {
- return errBadTimeRange
- }
- if e.MaxTimeMs > 0 && e.MaxTimeMs < vs.tx.MaxTimeMs {
- return errBadTimeRange
- }
- if vs.tx.Version == 1 && e.ExtHash != nil && !e.ExtHash.IsZero() {
- return errNonemptyExtHash
- }
-
case *bc.Issuance:
computedAssetID := e.WitnessAssetDefinition.ComputeAssetID()
if computedAssetID != *e.Value.AssetId {
},
},
{
- desc: "nonce timerange misordered",
- f: func() {
- iss := txIssuance(t, tx, 0)
- nonce := tx.Entries[*iss.AnchorId].(*bc.Nonce)
- tr := tx.Entries[*nonce.TimeRangeId].(*bc.TimeRange)
- tr.MinTimeMs = tr.MaxTimeMs + 1
- },
- err: errBadTimeRange,
- },
- {
- desc: "nonce timerange disagrees with tx timerange",
- f: func() {
- iss := txIssuance(t, tx, 0)
- nonce := tx.Entries[*iss.AnchorId].(*bc.Nonce)
- tr := tx.Entries[*nonce.TimeRangeId].(*bc.TimeRange)
- tr.MaxTimeMs = tx.MaxTimeMs - 1
- },
- err: errBadTimeRange,
- },
- {
- desc: "nonce timerange exthash nonempty",
- f: func() {
- iss := txIssuance(t, tx, 0)
- nonce := tx.Entries[*iss.AnchorId].(*bc.Nonce)
- tr := tx.Entries[*nonce.TimeRangeId].(*bc.TimeRange)
- tr.ExtHash = newHash(1)
- },
- err: errNonemptyExtHash,
- },
- {
- desc: "nonce timerange exthash nonempty, but that's OK",
- f: func() {
- tx.Version = 2
- iss := txIssuance(t, tx, 0)
- nonce := tx.Entries[*iss.AnchorId].(*bc.Nonce)
- tr := tx.Entries[*nonce.TimeRangeId].(*bc.TimeRange)
- tr.ExtHash = newHash(1)
- },
- },
- {
desc: "mismatched output source / mux dest position",
f: func() {
tx.Entries[*tx.ResultIds[0]].(*bc.Output).Source.Position = 1