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