MCPcopy Create free account
hub / github.com/chain/txvm / opSplit

Function opSplit

protocol/txvm/values.go:73–92  ·  view source on GitHub ↗
(vm *VM)

Source from the content-addressed store, hash-verified

71}
72
73func 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
94func opMerge(vm *VM) {
95 a := vm.popValue()

Callers

nothing calls this directly

Calls 7

WrapFunction · 0.92
WithDataFunction · 0.92
VMHashFunction · 0.85
popIntMethod · 0.80
popValueMethod · 0.80
createValueMethod · 0.80
pushMethod · 0.45

Tested by

no test coverage detected