| 71 | } |
| 72 | |
| 73 | func opSplit(vm *VM) { |
| 74 | amount := vm.popInt() |
| 75 | if amount < 0 { |
| 76 | panic(errors.Wrap(errors.WithData(ErrNegAmount, "amount", amount), "split")) |
| 77 | } |
| 78 | |
| 79 | a := vm.popValue() |
| 80 | if int64(amount) > a.amount { |
| 81 | panic(errors.WithData(ErrSplit, "a.amount", a.amount, "b.amount", amount)) |
| 82 | } |
| 83 | |
| 84 | anchor1 := VMHash("Split1", a.anchor[:]) |
| 85 | b := vm.createValue(a.amount-int64(amount), a.assetID, anchor1[:]) |
| 86 | |
| 87 | anchor2 := VMHash("Split2", a.anchor[:]) |
| 88 | c := vm.createValue(int64(amount), a.assetID, anchor2[:]) |
| 89 | |
| 90 | vm.push(b) |
| 91 | vm.push(c) |
| 92 | } |
| 93 | |
| 94 | func opMerge(vm *VM) { |
| 95 | a := vm.popValue() |