Пример #1
0
 def __init__(self):
     receiver = 'helloworld11'
     code = receiver
     scope = 'helloworld11'
     payer = receiver
     self.storage = db.ChainDBKey64(code, scope, name('table3'), type(self))
     self.primary_key = chain.s2n('counter')
     self.payer = payer
Пример #2
0
def apply(receiver, first_receiver, action):
    code = receiver
    scope = get_scope()
    table = name('table3')
    payer = receiver

    storage = db.ChainDBKey64(code, scope, table, MyDataI64)
    d = MyDataI64(1, 2, 3, 5.0)
    d.payer = payer
    storage.store(d)

    primary_key = 1
    data = storage.load(primary_key)
    print(data)

    primary_key = 2
    data = storage.load(primary_key)
    print(data)
Пример #3
0
def apply(receiver, first_receiver, action):
    if action == name('exec'):
        data = chain.read_action_data()
        code, method = struct.unpack('QQ', data[:16])
        if method == chain.s2n('creategroup'):
            account, group_name = struct.unpack('QQ', data[16:32])

            chain.require_auth(account)

            group = ChatGroup(group_name)
            group.payer = account
            assert chat_group_db.find(group_name) < 0, 'group already exists!'
            chat_group_db.store(group)

        elif method == chain.s2n('chat'):
            account, group_name, msg = data[16:24], data[24:32], data[32:]
            account = int.from_bytes(account, 'little')
            group_name = int.from_bytes(group_name, 'little')

            chat = ChatMessage(account, msg)
            chain.require_auth(chat.account)

            chat_group = chat_group_db.load(group_name)
            assert chat_group, 'group does not exists!'
            chat_group.count += 1
            chat_group.payer = 0
            chat_group_db.store(chat_group)

            scope = get_scope()
            chatdb = db.ChainDBKey64(self_contract, scope, name(group_name),
                                     ChatMessage)

            if len(chatdb) >= 10:
                itr = chatdb.lower_bound(0)
                if itr >= 0:
                    chatdb.remove_by_itr(itr)

            chat.index = chat_group.count
            chatdb.store(chat)
Пример #4
0
def apply(receiver, first_receiver, action):
    if action == name('creategroup'):
        data = chain.read_action_data()

        account = int.from_bytes(data[:8], 'little')
        group_name = int.from_bytes(data[8:], 'little')
        chain.require_auth(account)

        group = ChatGroup(group_name)
        group.payer = account
        assert chat_group_db.find(group_name) < 0, 'group already exists!'
        chat_group_db.store(group)

    elif action == name('chat'):
        data = chain.read_action_data()
        account, group_name, msg = data[:8], data[8:16], data[16:]
        account = int.from_bytes(account, 'little')
        group_name = int.from_bytes(group_name, 'little')

        chat = ChatMessage(account, msg)
        chain.require_auth(chat.account)

        chat_group = chat_group_db.load(group_name)
        assert chat_group, 'group does not exists!'
        chat_group.count += 1
        chat_group.payer = 0
        chat_group_db.store(chat_group)

        chatdb = db.ChainDBKey64(self_contract, self_contract,
                                 name(group_name), ChatMessage)

        if len(chatdb) >= 10:
            itr = chatdb.lower_bound(0)
            if itr >= 0:
                chatdb.remove_by_itr(itr)

        chat.index = chat_group.count
        chatdb.store(chat)
Пример #5
0
        account, time_seconds, msg = data[:8], data[8:16], data[16:]
        account = int.from_bytes(account, 'little')
        time_seconds = int.from_bytes(time_seconds, 'little')
        return cls(account, msg)

    def get_primary_key(self):
        return self.index

    def __str__(self):
        data = (self.index, self.account, self.msg)
        return json.dumps(data)


self_contract = chain.current_receiver()

chat_group_db = db.ChainDBKey64(self_contract, self_contract, name('groups'),
                                ChatGroup)


def apply(receiver, first_receiver, action):
    if action == name('creategroup'):
        data = chain.read_action_data()

        account = int.from_bytes(data[:8], 'little')
        group_name = int.from_bytes(data[8:], 'little')
        chain.require_auth(account)

        group = ChatGroup(group_name)
        group.payer = account
        assert chat_group_db.find(group_name) < 0, 'group already exists!'
        chat_group_db.store(group)
Пример #6
0
 def __init__(self):
     scope = get_scope()
     self.log_db = db.ChainDBKey64(self_contract, scope, name('log'), Log)