4 "github.com/bytom/protocol/bc"
5 "github.com/bytom/protocol/vm"
6 "github.com/bytom/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
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