コード例 #1
0
ファイル: token.py プロジェクト: openchatproject/safeos
 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())
コード例 #2
0
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)
コード例 #3
0
ファイル: vmstore.py プロジェクト: openchatproject/safeos
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)
コード例 #4
0
ファイル: storage.py プロジェクト: openchatproject/safeos
 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)
コード例 #5
0
ファイル: storage.py プロジェクト: openchatproject/safeos
    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)
コード例 #6
0
ファイル: backyard.py プロジェクト: openchatproject/safeos
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])
コード例 #7
0
ファイル: hello.py プロジェクト: openchatproject/safeos
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)
コード例 #8
0
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)
コード例 #9
0
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)
コード例 #10
0
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)
コード例 #11
0
ファイル: storage.py プロジェクト: openchatproject/safeos
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)
コード例 #12
0
 def __setitem__(self, index, val):
     db.update_i64(index, self.code, self.pack(val))
コード例 #13
0
 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))