def _get_all_channels_filter_sender_recipient_group( self, sender, recipient, group_id): sender_padded = pad_hex(sender.lower(), 256) recipient_padded = pad_hex(recipient.lower(), 256) group_id_hex = "0x" + group_id.hex() return self._get_all_filtered_channels( [sender_padded, recipient_padded, group_id_hex])
def print_all_channels_filter_group_sender(self): address = self.get_address_from_arg_or_ident(self.args.sender) address_padded = pad_hex(address.lower(), 256) metadata = self._get_service_metadata_from_registry() group_id = metadata.get_group_id(self.args.group_name) group_id_hex = "0x" + group_id.hex() channels_ids = self._get_all_filtered_channels([address_padded, None, group_id_hex]) self._print_channels_from_blockchain(channels_ids)
def argument_encoding(contract_method_ID, arg): """ concatenate method ID + padded parameter """ arg_hex = w3.toHex(arg) arg_hex_padded = pad_hex(arg_hex, bit_size=256) data = contract_method_ID + arg_hex_padded[2:] return data
def print_all_channels_filter_group_sender(self): address = self.get_address_from_arg_or_ident(self.args.sender) address_padded = pad_hex(address.lower(), 256) metadata = self._get_service_metadata_from_registry() group_id = metadata.get_group_id(self.args.group_name) group_id_hex = "0x" + group_id.hex() channels_ids = self._get_all_filtered_channels( [address_padded, None, group_id_hex]) self._print_channels_from_blockchain(channels_ids)
def print_all_channels_filter_group_sender(self): address = self.get_address_from_arg_or_ident(self.args.sender) address_padded = pad_hex(address.lower(), 256) metadata = self._get_organization_metadata_from_registry( self.args.org_id) group_id = base64.b64decode( metadata.get_group_id_by_group_name(self.args.group_name)) group_id_hex = "0x" + group_id.hex() channels_ids = self._get_all_filtered_channels( [address_padded, None, group_id_hex]) self._print_channels_from_blockchain(channels_ids)
def print_my_channels(self): # TODO: check that it is faster to use events to get all channels with the given sender (instead of using channels directly) event_signature = self.ident.w3.sha3(text="EventChannelOpen(uint256,address,address,uint256)").hex() my_address_padded = pad_hex(self.ident.address.lower(), 256) logs = self.ident.w3.eth.getLogs({"fromBlock" : self.args.from_block, "address" : self.args.mpe_address.lower(), "topics" : [event_signature, my_address_padded]}) # If we are sure that ABI will be fixed forever we can do like this: # channels_ids = [int(l['data'],16) for l in logs] abi = get_contract_def("MultiPartyEscrow") event_abi = abi_get_element_by_name(abi, "EventChannelOpen") channels_ids = [get_event_data(event_abi, l)["args"]["channelId"] for l in logs] channel_abi = abi_get_element_by_name(abi, "channels") self._printout("#id nonce recipient groupId value expiration(blocks)") for i in channels_ids: channel = self.call_contract_command("MultiPartyEscrow", self.args.mpe_address, "channels", [i]) channel = abi_decode_struct_to_dict(channel_abi, channel) self._printout("%i %i %s %i %i %i"%(i, channel["nonce"], channel["recipient"], channel["groupId"], channel["value"], channel["expiration"]))
def print_all_channels_my(self): # TODO: check that it is faster to use events to get all channels with the given sender (instead of using channels directly) mpe_address = self.get_mpe_address() event_signature = self.ident.w3.sha3( text= "ChannelOpen(uint256,address,address,bytes32,address,uint256,uint256)" ).hex() my_address_padded = pad_hex(self.ident.address.lower(), 256) logs = self.ident.w3.eth.getLogs({ "fromBlock": self.args.from_block, "address": mpe_address, "topics": [event_signature, my_address_padded] }) # If we are sure that ABI will be fixed forever we can do like this: # channels_ids = [int(l['data'],16) for l in logs] abi = get_contract_def("MultiPartyEscrow") event_abi = abi_get_element_by_name(abi, "ChannelOpen") channels_ids = [ get_event_data(event_abi, l)["args"]["channelId"] for l in logs ] self._print_channels_from_blockchain(channels_ids)
def _get_all_channels_filter_sender(self, sender): sender_padded = pad_hex(sender.lower(), 256) channels_ids = self._get_all_filtered_channels([sender_padded]) return channels_ids
def print_all_channels_filter_recipient(self): address = self.get_address_from_arg_or_ident(self.args.recipient) address_padded = pad_hex(address.lower(), 256) channels_ids = self._get_all_filtered_channels([None, address_padded]) self._print_channels_from_blockchain(channels_ids)
def _get_all_channels_filter_sender_recipient_group(self, sender, recipient, group_id): sender_padded = pad_hex(sender.lower(), 256) recipient_padded = pad_hex(recipient.lower(), 256) group_id_hex = "0x" + group_id.hex() return self._get_all_filtered_channels([sender_padded, recipient_padded, group_id_hex])
def _get_all_channels_filter_sender(self, sender): sender_padded = pad_hex(sender.lower(), 256) channels_ids = self._get_all_filtered_channels([sender_padded]) return channels_ids
def print_all_channels_filter_recipient(self): address = self.get_address_from_arg_or_ident(self.args.recipient) address_padded = pad_hex(address.lower(), 256) channels_ids = self._get_all_filtered_channels([None,address_padded]) self._print_channels_from_blockchain(channels_ids)