def storage_put(self, config: Config, engine: ExecutionEngine): print("*********storage_put:") item = PushData.pop_interop_interface(engine) key = PushData.pop_bytearray(engine) value = PushData.pop_bytearray(engine) storage_map = config.get_storage_map() storage_map[item.value.hex() + key.hex()] = value.hex() date = time.strftime('%Y-%m-%d', time.localtime(time.time())) with open(date + '.json', "w") as f: json.dump(storage_map, f, default=lambda obj: dict(obj), indent=4)
def op_sub_str(engine): count = PushData.pop_int(engine) index = PushData.pop_int(engine) arr = PushData.pop_bytearray(engine) bs = arr[index:index + count] PushData.push_data(engine, bs) return VMState.NONE
def runtime_check_witness(self, config: Config, engine: ExecutionEngine): data = PushData.pop_bytearray(engine) if len(data) == 20: address = Address(data) l = config.get_signature_addresses() if address.b58encode() in l: PushData.push_data(engine, BoolItem(True)) else: PushData.push_data(engine, BoolItem(False))
def storage_get(self, config: Config, engine: ExecutionEngine): if len(engine.evaluation_stack.e) < 2: raise RuntimeError("evaluation stack size less than 2") item = PushData.pop_interop_interface(engine) key = PushData.pop_bytearray(engine) storage_map = config.get_storage_map() value = bytearray() if len(storage_map) != 0: temp = storage_map.get(item.value.hex() + key.hex(), '') value = bytearray.fromhex(temp) if value is None or value == '': value = bytearray() PushData.push_data(engine, value)
def op_hash(engine): x = PushData.pop_bytearray(engine) PushData.push_data(engine, PushData.hash(x, engine)) return VMState.NONE
def runtime_deserialize(self, config: Config, engine: ExecutionEngine): bys = PushData.pop_bytearray(engine) reader = VmReader(bys) items = self.__deserialize_stack_item(reader) PushData.push_data(engine, items)
def runtime_log(self, config: Config, engine: ExecutionEngine): item = PushData.pop_bytearray(engine) print("Runtimelog:", item.decode('utf-8'))
def op_cat(engine): bs2 = PushData.pop_bytearray(engine) bs1 = PushData.pop_bytearray(engine) r = PushData.concat(bs1, bs2) PushData.push_data(engine, r) return VMState.NONE
def op_size(engine): arr = PushData.pop_bytearray(engine) PushData.push_data(engine, len(arr)) return VMState.NONE
def op_right(engine): count = PushData.pop_int(engine) arr = PushData.pop_bytearray(engine) bs = arr[len(arr) - count:] PushData.push_data(engine, bs) return VMState.NONE
def op_left(engine): count = PushData.pop_int(engine) arr = PushData.pop_bytearray(engine) bs = arr[0:count] PushData.push_data(engine, bs) return VMState.NONE