github.com/Bytom/bytom@v1.1.2-0.20210127130405-ae40204c0b09/protocol/vm/introspection.go (about) 1 package vm 2 3 func opCheckOutput(vm *virtualMachine) error { 4 err := vm.applyCost(16) 5 if err != nil { 6 return err 7 } 8 9 code, err := vm.pop(true) 10 if err != nil { 11 return err 12 } 13 vmVersion, err := vm.popInt64(true) 14 if err != nil { 15 return err 16 } 17 if vmVersion < 0 { 18 return ErrBadValue 19 } 20 assetID, err := vm.pop(true) 21 if err != nil { 22 return err 23 } 24 amount, err := vm.popInt64(true) 25 if err != nil { 26 return err 27 } 28 if amount < 0 { 29 return ErrBadValue 30 } 31 index, err := vm.popInt64(true) 32 if err != nil { 33 return err 34 } 35 if index < 0 { 36 return ErrBadValue 37 } 38 39 if vm.context.CheckOutput == nil { 40 return ErrContext 41 } 42 43 ok, err := vm.context.CheckOutput(uint64(index), uint64(amount), assetID, uint64(vmVersion), code, vm.expansionReserved) 44 if err != nil { 45 return err 46 } 47 return vm.pushBool(ok, true) 48 } 49 50 func opAsset(vm *virtualMachine) error { 51 err := vm.applyCost(1) 52 if err != nil { 53 return err 54 } 55 56 if vm.context.AssetID == nil { 57 return ErrContext 58 } 59 return vm.push(*vm.context.AssetID, true) 60 } 61 62 func opAmount(vm *virtualMachine) error { 63 err := vm.applyCost(1) 64 if err != nil { 65 return err 66 } 67 68 if vm.context.Amount == nil { 69 return ErrContext 70 } 71 return vm.pushInt64(int64(*vm.context.Amount), true) 72 } 73 74 func opProgram(vm *virtualMachine) error { 75 err := vm.applyCost(1) 76 if err != nil { 77 return err 78 } 79 80 return vm.push(vm.context.Code, true) 81 } 82 83 func opIndex(vm *virtualMachine) error { 84 err := vm.applyCost(1) 85 if err != nil { 86 return err 87 } 88 89 if vm.context.DestPos == nil { 90 return ErrContext 91 } 92 return vm.pushInt64(int64(*vm.context.DestPos), true) 93 } 94 95 func opEntryID(vm *virtualMachine) error { 96 err := vm.applyCost(1) 97 if err != nil { 98 return err 99 } 100 return vm.push(vm.context.EntryID, true) 101 } 102 103 func opOutputID(vm *virtualMachine) error { 104 err := vm.applyCost(1) 105 if err != nil { 106 return err 107 } 108 109 if vm.context.SpentOutputID == nil { 110 return ErrContext 111 } 112 return vm.push(*vm.context.SpentOutputID, true) 113 } 114 115 func opBlockHeight(vm *virtualMachine) error { 116 err := vm.applyCost(1) 117 if err != nil { 118 return err 119 } 120 121 if vm.context.BlockHeight == nil { 122 return ErrContext 123 } 124 return vm.pushInt64(int64(*vm.context.BlockHeight), true) 125 }