IssuanceProgram chainjson.HexBytes `json:"issue_program"`
RawDefinitionByte chainjson.HexBytes `json:"raw_definition_byte"`
Definition *json.RawMessage `json:"definition"`
- LimitHeight int64 `json:"limit_height"`
+ LimitHeight uint64 `json:"limit_height"`
}
//AnnotatedSigner means an annotated signer for asset.
if err != nil {
return nil, err
}
- res = append(res, PushdataBytes(bytes)...)
+ res = append(res, PushDataBytes(bytes)...)
} else if len(token) >= 2 && token[0] == '\'' && token[len(token)-1] == '\'' {
bytes := make([]byte, 0, len(token)-2)
var b int
bytes = append(bytes, token[i])
b++
}
- res = append(res, PushdataBytes(bytes)...)
+ res = append(res, PushDataBytes(bytes)...)
} else if num, ok := checked.NewUInt256(token); ok {
- res = append(res, PushdataBytes(BigIntBytes(num))...)
+ res = append(res, PushDataBytes(BigIntBytes(num))...)
} else {
return nil, errors.Wrap(ErrToken, token)
}
if err != nil {
return err
}
- amount, err := vm.popInt64(true)
+ amountInt, err := vm.popBigInt(true)
if err != nil {
return err
}
- if amount < 0 {
+
+ amount, overflow := amountInt.Uint64WithOverflow()
+ if overflow {
return ErrBadValue
}
+
index, err := vm.popInt64(true)
if err != nil {
return err
return ErrContext
}
- ok, err := vm.context.CheckOutput(uint64(index), uint64(amount), assetID, uint64(vmVersion), code, vm.expansionReserved)
+ ok, err := vm.context.CheckOutput(uint64(index), amount, assetID, uint64(vmVersion), code, vm.expansionReserved)
if err != nil {
return err
}
if vm.context.Amount == nil {
return ErrContext
}
- return vm.pushInt64(int64(*vm.context.Amount), true)
+
+ return vm.pushBigInt(uint256.NewInt().SetUint64(*vm.context.Amount), true)
}
func opProgram(vm *virtualMachine) error {
return vm.applyCost(1)
}
-func PushdataBytes(in []byte) []byte {
+// PushDataBytes push bytes to stack
+func PushDataBytes(in []byte) []byte {
l := len(in)
if l == 0 {
return []byte{byte(OP_0)}
return append([]byte{byte(OP_PUSHDATA4), b[0], b[1], b[2], b[3]}, in...)
}
-func PushdataInt64(n int64) []byte {
+// PushDataInt64 push int64 to stack
+func PushDataInt64(n int64) []byte {
if n == 0 {
return []byte{byte(OP_0)}
}
if n >= 1 && n <= 16 {
return []byte{uint8(OP_1) + uint8(n) - 1}
}
- return PushdataBytes(Int64Bytes(n))
+ return PushDataBytes(Int64Bytes(n))
}
}
for _, c := range cases {
- got := PushdataBytes(c.data)
+ got := PushDataBytes(c.data)
dl := len(c.data)
if dl > 10 {
dl = 10
}
if !bytes.Equal(got, c.want) {
- t.Errorf("PushdataBytes(%x...) = %x...[%d] want %x...[%d]", c.data[:dl], got[:dl], len(got), c.want[:dl], len(c.want))
+ t.Errorf("PushDataBytes(%x...) = %x...[%d] want %x...[%d]", c.data[:dl], got[:dl], len(got), c.want[:dl], len(c.want))
}
}
}
}
for _, c := range cases {
- got := PushdataInt64(c.num)
+ got := PushDataInt64(c.num)
if !bytes.Equal(got, c.want) {
- t.Errorf("PushdataInt64(%d) = %x want %x", c.num, got, c.want)
+ t.Errorf("PushDataInt64(%d) = %x want %x", c.num, got, c.want)
}
}
}
return err
}
vm.deferCost(-lens)
- return vm.push(append(a, PushdataBytes(b)...), true)
+ return vm.push(append(a, PushDataBytes(b)...), true)
}
// AddInt64 adds a pushdata instruction for an integer value.
func (b *Builder) AddInt64(n int64) *Builder {
- b.program = append(b.program, vm.PushdataInt64(n)...)
+ b.program = append(b.program, vm.PushDataInt64(n)...)
return b
}
// AddData adds a pushdata instruction for a given byte string.
func (b *Builder) AddData(data []byte) *Builder {
- b.program = append(b.program, vm.PushdataBytes(data)...)
+ b.program = append(b.program, vm.PushDataBytes(data)...)
return b
}
// GetIssuanceProgramRestrictHeight return issuance program restrict height
// if height invalid return 0
-func GetIssuanceProgramRestrictHeight(program []byte) int64 {
+func GetIssuanceProgramRestrictHeight(program []byte) uint64 {
insts, err := vm.ParseProgram(program)
if err != nil {
return 0
}
if len(insts) >= 4 && insts[0].IsPushdata() && insts[1].Op == vm.OP_BLOCKHEIGHT && insts[2].Op == vm.OP_GREATERTHAN && insts[3].Op == vm.OP_VERIFY {
- height, err := vm.AsInt64(insts[0].Data)
+ heightInt, err := vm.AsBigInt(insts[0].Data)
if err != nil {
return 0
}
+ height, overflow := heightInt.Uint64WithOverflow()
+ if overflow {
+ return 0
+ }
+
return height
}
return 0
func TestGetIssuanceProgramRestrictHeight(t *testing.T) {
tests := []struct {
issuanceProgram string
- wantHeight int64
+ wantHeight uint64
}{
{
issuanceProgram: "",
issuanceProgram: "01c8cda069ae20f44dd85be89de08b0f894476ccc7b3eebcf0a288c79504fa7e4c8033f5b7338020c86dc682ce3ecac64e165d9b5f8cca9ee05bd0d4df07adbfd11251ad7e88f1685152ad",
wantHeight: 200,
},
+ {
+ issuanceProgram: "08c8c8c8c8c8c8c8c8cda069ae20f44dd85be89de08b0f894476ccc7b3eebcf0a288c79504fa7e4c8033f5b7338020c86dc682ce3ecac64e165d9b5f8cca9ee05bd0d4df07adbfd11251ad7e88f1685152ad",
+ wantHeight: 14468034567615334600,
+ },
}
for i, test := range tests {