package txbuilder
import (
+ "github.com/bytom/crypto/sha3pool"
"github.com/bytom/protocol/bc"
"github.com/bytom/protocol/vm"
"github.com/bytom/protocol/vm/vmutil"
return prog
}
+// refdataConstraint requires the refdatahash of the transaction (if
+// tx is true) or the input (if tx is false) to match that of the
+// given data.
+type refdataConstraint struct {
+ data []byte
+ tx bool
+}
+
+func (r refdataConstraint) code() []byte {
+ var h [32]byte
+ sha3pool.Sum256(h[:], r.data)
+ builder := vmutil.NewBuilder()
+ builder.AddData(h[:])
+ if r.tx {
+ builder.AddOp(vm.OP_TXDATA)
+ } else {
+ builder.AddOp(vm.OP_ENTRYDATA)
+ }
+ builder.AddOp(vm.OP_EQUAL)
+ prog, _ := builder.Build() // error is impossible
+ return prog
+}
// PayConstraint requires the transaction to include a given output
// at the given index, optionally with the given refdatahash.
Index int
bc.AssetAmount
Program []byte
+ RefDataHash *bc.Hash
}
func (p payConstraint) code() []byte {
builder := vmutil.NewBuilder()
builder.AddInt64(int64(p.Index))
+ if p.RefDataHash == nil {
+ builder.AddData([]byte{})
+ } else {
+ builder.AddData(p.RefDataHash.Bytes())
+ }
builder.AddInt64(int64(p.Amount)).AddData(p.AssetId.Bytes()).AddInt64(1).AddData(p.Program)
builder.AddOp(vm.OP_CHECKOUTPUT)
prog, _ := builder.Build() // error is impossible