(b *txvmutil.Builder, stack []stackItem, amount int64, assetID bc.Hash)
| 739 | } |
| 740 | |
| 741 | func valueToTop(b *txvmutil.Builder, stack []stackItem, amount int64, assetID bc.Hash) ([]stackItem, error) { |
| 742 | if len(stack) == 0 { |
| 743 | return nil, errors.New("empty stack") |
| 744 | } |
| 745 | for { |
| 746 | top := stack[len(stack)-1] |
| 747 | if top.amount > 0 && top.assetID == assetID { |
| 748 | if top.amount == amount { |
| 749 | return stack, nil |
| 750 | } |
| 751 | if top.amount > amount { |
| 752 | // con stack is [... val(orig - amount) val(amount)] |
| 753 | return split(b, stack, amount), nil |
| 754 | } |
| 755 | if len(stack) > 1 { |
| 756 | second := stack[len(stack)-2] |
| 757 | if second.amount > 0 && second.assetID == assetID { |
| 758 | stack = merge(b, stack, amount) |
| 759 | continue |
| 760 | } |
| 761 | } |
| 762 | } |
| 763 | |
| 764 | stack = findAndRoll(b, stack, func(i int, item stackItem) bool { |
| 765 | return i != len(stack)-1 && item.amount > 0 && item.assetID == assetID |
| 766 | }) |
| 767 | if stack == nil { |
| 768 | return nil, errors.WithDetailf(ErrInsufficientValue, "amount=%d, assetID=%x", amount, assetID.Bytes()) |
| 769 | } |
| 770 | } |
| 771 | } |
no test coverage detected