def store(self, payer): it = db.find_i64(self.code, self.scope, self.table_id, self.get_primary_key()) if it >= 0: db.update_i64(it, payer, self.pack()) else: db.store_i64(self.scope, self.table_id, payer, self.get_primary_key(), self.pack())
def deploy(account, src_code): code = N('native') print('++++++++++++deploy:account', account) itr = db.find_i64(code, code, code, account) if itr < 0: db.store_i64(code, code, code, account, src_code) else: db.update_i64(itr, code, src_code)
def deploy(scope, table, id, data): code = N('vmstore') payer = code print('++++++++++++deploy:scope', n2s(scope), n2s(table)) itr = db.find_i64(code, scope, table, id) if itr < 0: db.store_i64(scope, table, payer, id, data) else: db.update_i64(itr, payer, data)
def update_size(self): _value = int.to_bytes(self.list_size, 4, 'little') itr = db.find_i64(self.code, self.code, self.table_id, self.list_size_id) if itr < 0: db.store_i64(self.code, self.table_id, self.code, self.list_size_id, _value) else: db.update_i64(itr, self.code, _value)
def setitem(self, index, val): id = index if self.value_type: _value = self.value_type.pack(val) else: _value = self.pack(val) itr = db.find_i64(self.code, self.code, self.table_id, id) if itr < 0: db.store_i64(self.code, self.table_id, self.code, id, _value) else: db.update_i64(itr, self.code, _value)
def deploy(mod_name, src_code): code = N('backyard') print('++++++++++++deploy:mod_name', mod_name) id = hash64(mod_name) itr = db.find_i64(code, code, code, id) if itr < 0: db.store_i64(code, code, code, id, src_code) else: db.update_i64(itr, code, src_code) mod_name = mod_name.decode('utf8') if mod_name.endswith('.mpy'): __import__('backyard.' + mod_name[:-4]) elif mod_name.endswith('.py'): __import__('backyard.' + mod_name[:-3])
def count(): code = N('counter') counter_id = N('counter') itr = db.find_i64(code, code, code, counter_id) if itr >= 0: # value exists, update it counter = db.get_i64(itr) # print('old counter', int.from_bytes(counter, 'little')) counter = int.from_bytes(counter, 'little') counter += 1 counter = int.to_bytes(counter, 4, 'little') db.update_i64(itr, code, counter) else: counter = int.to_bytes(1, 4, 'little') db.store_i64(code, code, code, counter_id, counter)
def deploy(mod_name, src_code): code = N('kitties') print('++++++++++++deploy:mod_name', mod_name) id = hash64(mod_name) itr = db.find_i64(code, code, code, id) if itr < 0: db.store_i64(code, code, code, id, src_code) else: db.update_i64(itr, code, src_code) if mod_name.endswith('.mpy'): #try to remove py source to prevent micropython loading the wrong source mod_name = mod_name[:-3] + 'py' id = hash64(mod_name) itr = db.find_i64(code, code, code, id) if itr >= 0: db.remove_i64(itr)
def sayHello(): n = N('hello') id = N('name') name = read_action() print('hello', name) code = n scope = n table = n payer = n itr = db.find_i64(code, scope, table, id) if itr >= 0: # value exist, update it old_name = db.get_i64(itr) print('hello,', old_name) db.update_i64(itr, payer, name) else: db.store_i64(scope, table, payer, id, name)
def store(key, value): id = get_hash(key) value = to_raw_value(value) code = contract_owner itr = db.find_i64(receiver, receiver, g_table_id, id) if itr >= 0: value = db.update_i64(itr, receiver, value) else: db.store_i64(receiver, g_table_id, receiver, id, value)
def storage_set(code, table_id, key, value): itr = db.find_i64(code, code, table_id, key) if itr >= 0: db.update_i64(itr, code, value) else: db.store_i64(code, table_id, code, key, value)
def __setitem__(self, index, val): db.update_i64(index, self.code, self.pack(val))
def __setitem__(self, index, val): if index < 0 or index >= self.count: raise IndexError('list index out of range') db.update_i64(index, self.code, self.pack(val))