def apply(receiver, first_receiver, action): if first_receiver == name( 'eosio.token'): #receive a notify from uuos.token print(receiver, first_receiver) if not action == name('transfer'): return data = chain.read_action_data() _from, to, amount, symbol = struct.unpack('QQQQ', data[:32]) if _from == int(name('helloworld11')): return assert name(to) == name('helloworld11') assert symbol == TOKEN_SYMBOL, 'bad token' assert amount >= 1_0000 memo = data[33:] account, pub_key = memo.split(b'-') assert len(pub_key) == 68 account = name(account.decode()) account = bytes(account) pub_key = binascii.unhexlify(pub_key) create_new_account(account, pub_key, amount) if action == name('newaccount'): chain.require_auth('hello') data = chain.read_action_data() account = data[:8] pub_key = data[8:8 + 34] create_new_account(account, pub_key) elif action == name('sayhello'): data = chain.read_action_data() print(data)
def apply(receiver, first_receiver, action): data = chain.read_action_data() notify_to = data[8:16] notify_to = name(notify_to) print('send notify:', notify_to) assert chain.is_account(notify_to), 'notify to account does not exists!' chain.require_recipient(notify_to)
def apply(receiver, first_receiver, action): signature = chain.read_action_data()[8:] digest = chain.sha256('hello,world') pub_key = chain.recover_key(digest, signature) print(pub_key) # raw public key, no checksum, 34 bytes assert pub_key == b'\x00\x02\xa8\x91\xe0\xddW\x13.\xd6\x83\xbc\x87]\xac\xc9a\xc6\xfd]\xfa\xe6\x80\x0b\xc6\x18\x1a\xb6\x8b\xb8H%\x1eR' chain.assert_recover_key(digest, signature, pub_key)
def apply(receiver, first_receiver, action): if not receiver == first_receiver: return if action == name('create'): # token_create( uint64_t issuer, int64_t maximum_supply, uint64_t sym) data = chain.read_action_data() issuer, maximum_supply, symbol = struct.unpack('QQQ', data) assert symbol == TOKEN_SYMBOL chain.token_create(issuer, maximum_supply, TOKEN_SYMBOL) elif action == name('issue'): # void token_issue( uint64_t to, int64_t quantity, uint64_t sym, const char* memo, size_t size2 ); data = chain.read_action_data() to, quantity, symbol = struct.unpack('QQQ', data[:24]) assert TOKEN_SYMBOL == symbol chain.token_issue(to, quantity, TOKEN_SYMBOL, data[25:]) elif action == name('transfer'): # void token_transfer( uint64_t from, uint64_t to, int64_t quantity, uint64_t sym, const char* memo, size_t size2); data = chain.read_action_data() _from, to, quantity, symbol = struct.unpack('QQQQ', data[:32]) assert TOKEN_SYMBOL == symbol chain.token_transfer(_from, to, quantity, TOKEN_SYMBOL, data[33:])
def apply(receiver, first_receiver, action): if action == name('testinline'): account = receiver action = name('sayhello') actor = receiver permission = name('active') data = b'hello,world' chain.send_inline(account, action, actor, permission, data) print('inline action sent') elif action == name('sayhello'): data = chain.read_action_data() print(data)
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)
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)
def get_scope(): return name(chain.read_action_data()[:8])
def apply(receiver, first_receiver, action): chain.enable_log(True) data = chain.read_action_data() print(data) logdb.log()