4 "github.com/vapor/protocol/bc"
5 "github.com/vapor/protocol/vm"
6 "github.com/vapor/protocol/vm/vmutil"
9 // Constraint types express a constraint on an input of a proposed
10 // transaction, and know how to turn that constraint into part of a
11 // signature program in that input's witness.
12 type constraint interface {
13 // Code produces bytecode expressing the constraint. The code, when
14 // executed, must consume nothing from the stack and leave a new
15 // boolean value on top of it.
19 // outpointConstraint requires the outputID (and therefore, the outpoint) being spent to equal the
21 type outputIDConstraint bc.Hash
23 func (o outputIDConstraint) code() []byte {
24 builder := vmutil.NewBuilder()
25 builder.AddData(bc.Hash(o).Bytes())
26 builder.AddOp(vm.OP_OUTPUTID)
27 builder.AddOp(vm.OP_EQUAL)
28 prog, _ := builder.Build() // error is impossible
32 // PayConstraint requires the transaction to include a given output
33 // at the given index, optionally with the given refdatahash.
34 type payConstraint struct {
40 func (p payConstraint) code() []byte {
41 builder := vmutil.NewBuilder()
42 builder.AddInt64(int64(p.Index))
43 builder.AddInt64(int64(p.Amount)).AddData(p.AssetId.Bytes()).AddInt64(1).AddData(p.Program)
44 builder.AddOp(vm.OP_CHECKOUTPUT)
45 prog, _ := builder.Build() // error is impossible