def _add_onchain_locksroot_to_channel_new_state_changes( storage: SQLiteStorage, ) -> None: """ Adds `onchain_locksroot` to our_state/partner_state in ContractReceiveChannelNew's channel_state object. """ batch_size = 50 batch_query = storage.batch_query_state_changes( batch_size=batch_size, filters=[("_type", "raiden.transfer.state_change.ContractReceiveChannelNew")], ) for state_changes_batch in batch_query: updated_state_changes = list() for state_change in state_changes_batch: state_change_data = json.loads(state_change.data) channel_state = state_change_data["channel_state"] msg = "v18 state changes cant contain onchain_locksroot" assert "onchain_locksroot" not in channel_state["our_state"], msg msg = "v18 state changes cant contain onchain_locksroot" assert "onchain_locksroot" not in channel_state[ "partner_state"], msg channel_state["our_state"]["onchain_locksroot"] = serialize_bytes( EMPTY_MERKLE_ROOT) channel_state["partner_state"][ "onchain_locksroot"] = serialize_bytes(EMPTY_MERKLE_ROOT) updated_state_changes.append( (json.dumps(state_change_data), state_change.state_change_identifier)) storage.update_state_changes(updated_state_changes)
def _add_onchain_locksroot_to_snapshot( raiden: RaidenService, storage: SQLiteStorage, snapshot_record: StateChangeRecord, ) -> str: """ Add `onchain_locksroot` to each NettingChannelEndState """ snapshot = json.loads(snapshot_record.data) for payment_network in snapshot.get('identifiers_to_paymentnetworks', dict()).values(): for token_network in payment_network.get('tokennetworks', list()): channelidentifiers_to_channels = token_network.get( 'channelidentifiers_to_channels', dict(), ) for channel in channelidentifiers_to_channels.values(): our_locksroot, partner_locksroot = _get_onchain_locksroots( raiden=raiden, storage=storage, token_network=token_network, channel=channel, ) channel['our_state']['onchain_locksroot'] = serialize_bytes( our_locksroot) channel['partner_state'][ 'onchain_locksroot'] = serialize_bytes(partner_locksroot) return json.dumps(snapshot, indent=4), snapshot_record.identifier
def _add_onchain_locksroot_to_snapshot( raiden: "RaidenService", storage: SQLiteStorage, snapshot_record: SnapshotRecord) -> Tuple[str, int]: """ Add `onchain_locksroot` to each NettingChannelEndState """ snapshot = json.loads(snapshot_record.data) for payment_network in snapshot.get("identifiers_to_paymentnetworks", dict()).values(): for token_network in payment_network.get("tokennetworks", list()): channelidentifiers_to_channels = token_network.get( "channelidentifiers_to_channels", dict()) for channel in channelidentifiers_to_channels.values(): our_locksroot, partner_locksroot = _get_onchain_locksroots( raiden=raiden, storage=storage, token_network=token_network, channel=channel) channel["our_state"]["onchain_locksroot"] = serialize_bytes( our_locksroot) channel["partner_state"][ "onchain_locksroot"] = serialize_bytes(partner_locksroot) return json.dumps(snapshot, indent=4), snapshot_record.identifier
def to_dict(self) -> Dict[str, Any]: return { "transaction_hash": serialize_bytes(self.transaction_hash), "payment_network": self.payment_network, "block_number": str(self.block_number), "block_hash": serialize_bytes(self.block_hash), }
def to_dict(self) -> Dict[str, Any]: return { "transaction_hash": serialize_bytes(self.transaction_hash), "canonical_identifier": self.canonical_identifier.to_dict(), "block_number": str(self.block_number), "block_hash": serialize_bytes(self.block_hash), }
def to_dict(self) -> typing.Dict[str, typing.Any]: return { 'message_identifier': self.message_identifier, 'secret': serialize_bytes(self.secret), 'balance_proof': self.balance_proof, 'balance_hash': serialize_bytes(self.balance_proof.balance_hash), }
def to_dict(self) -> Dict[str, Any]: return { "transaction_hash": serialize_bytes(self.transaction_hash), "channel_state": self.channel_state, "block_number": str(self.block_number), "block_hash": serialize_bytes(self.block_hash), }
def to_dict(self) -> Dict[str, Any]: return { 'transaction_hash': serialize_bytes(self.transaction_hash), 'payment_network': self.payment_network, 'block_number': str(self.block_number), 'block_hash': serialize_bytes(self.block_hash), }
def to_dict(self) -> Dict[str, Any]: return { "secret": serialize_bytes(self.secret), "secrethash": serialize_bytes(self.secrethash), "sender": to_checksum_address(self.sender), "secret_reveal_message": self.secret_reveal_message }
def to_dict(self) -> Dict[str, Any]: return { 'transaction_hash': serialize_bytes(self.transaction_hash), 'payment_network_identifier': to_checksum_address(self.payment_network_identifier), 'token_network': self.token_network, 'block_number': str(self.block_number), 'block_hash': serialize_bytes(self.block_hash), }
def to_dict(self) -> typing.Dict[str, typing.Any]: return { 'transaction_hash': serialize_bytes(self.transaction_hash), 'secret_registry_address': to_checksum_address(self.secret_registry_address), 'secrethash': serialize_bytes(self.secrethash), 'secret': serialize_bytes(self.secret), 'block_number': self.block_number, }
def to_dict(self) -> Dict[str, Any]: return { 'transaction_hash': serialize_bytes(self.transaction_hash), 'secret_registry_address': to_checksum_address(self.secret_registry_address), 'secrethash': serialize_bytes(self.secrethash), 'secret': serialize_bytes(self.secret), 'block_number': str(self.block_number), }
def to_dict(self) -> typing.Dict[str, typing.Any]: return { 'sender': to_checksum_address(self.sender), 'balance_proof': self.balance_proof, 'balance_hash': serialize_bytes(self.balance_proof.balance_hash), 'secrethash': serialize_bytes(self.secrethash), 'message_identifier': self.message_identifier, }
def to_dict(self) -> Dict[str, Any]: result = { 'expiration': str(self.expiration), 'secret': serialization.serialize_bytes(self.secret), 'triggered_by_block_hash': serialize_bytes(self.triggered_by_block_hash), } return result
def to_dict(self) -> Dict[str, Any]: return { 'transaction_hash': serialize_bytes(self.transaction_hash), 'token_network_identifier': to_checksum_address(self.token_network_identifier), 'channel_identifier': str(self.channel_identifier), 'deposit_transaction': self.deposit_transaction, 'block_number': str(self.block_number), 'block_hash': serialize_bytes(self.block_hash), }
def to_dict(self) -> Dict[str, Any]: return { "transaction_hash": serialize_bytes(self.transaction_hash), "canonical_identifier": self.canonical_identifier.to_dict(), "participant1": to_checksum_address(self.participant1), "participant2": to_checksum_address(self.participant2), "block_number": str(self.block_number), "block_hash": serialize_bytes(self.block_hash), }
def to_dict(self) -> Dict[str, Any]: return { 'transaction_hash': serialize_bytes(self.transaction_hash), 'token_network_identifier': to_checksum_address(self.token_network_identifier), 'channel_identifier': str(self.channel_identifier), 'our_onchain_locksroot': serialize_bytes(self.our_onchain_locksroot), 'partner_onchain_locksroot': serialize_bytes(self.partner_onchain_locksroot), 'block_number': str(self.block_number), 'block_hash': serialize_bytes(self.block_hash), }
def to_dict(self) -> typing.Dict[str, typing.Any]: result = { 'secrethash': serialization.serialize_bytes(self.secrethash), 'transfers_pair': self.transfers_pair, } if self.secret is not None: result['secret'] = serialization.serialize_bytes(self.secret) return result
def to_dict(self) -> typing.Dict[str, typing.Any]: return { 'transaction_hash': serialize_bytes(self.transaction_hash), 'token_network_identifier': to_checksum_address(self.token_network_identifier), 'participant': to_checksum_address(self.participant), 'partner': to_checksum_address(self.partner), 'locksroot': serialize_bytes(self.locksroot), 'unlocked_amount': self.unlocked_amount, 'returned_tokens': self.returned_tokens, 'block_number': self.block_number, }
def to_dict(self) -> typing.Dict[str, typing.Any]: result = { 'secrethash': serialization.serialize_bytes(self.secrethash), 'transfers_pair': self.transfers_pair, 'waiting_transfer': self.waiting_transfer, } if self.secret is not None: result['secret'] = serialization.serialize_bytes(self.secret) return result
def to_dict(self) -> Dict[str, Any]: result = { "expiration": str(self.expiration), "secret": serialization.serialize_bytes(self.secret), "triggered_by_block_hash": serialize_bytes(self.triggered_by_block_hash), } return result
def to_dict(self) -> Dict[str, Any]: return { 'transaction_hash': serialize_bytes(self.transaction_hash), 'token_network_identifier': to_checksum_address(self.token_network_identifier), 'participant': to_checksum_address(self.participant), 'partner': to_checksum_address(self.partner), 'locksroot': serialize_bytes(self.locksroot), 'unlocked_amount': str(self.unlocked_amount), 'returned_tokens': str(self.returned_tokens), 'block_number': str(self.block_number), }
def to_dict(self) -> Dict[str, Any]: result = { "secrethash": serialize_bytes(self.secrethash), "transfers_pair": self.transfers_pair, "waiting_transfer": self.waiting_transfer, "routes": self.routes, } if self.secret is not None: result["secret"] = serialize_bytes(self.secret) return result
def to_dict(self) -> Dict[str, Any]: return { "transaction_hash": serialize_bytes(self.transaction_hash), "canonical_identifier": self.canonical_identifier.to_dict(), "participant": to_checksum_address(self.participant), "partner": to_checksum_address(self.partner), "locksroot": serialize_bytes(self.locksroot), "unlocked_amount": str(self.unlocked_amount), "returned_tokens": str(self.returned_tokens), "block_number": str(self.block_number), "block_hash": serialize_bytes(self.block_hash), }
def to_dict(self) -> Dict[str, Any]: result = { 'secrethash': serialization.serialize_bytes(self.secrethash), 'transfers_pair': self.transfers_pair, 'waiting_transfer': self.waiting_transfer, 'routes': self.routes, } if self.secret is not None: result['secret'] = serialization.serialize_bytes(self.secret) return result
def to_dict(self) -> Dict[str, Any]: return { "transaction_hash": serialize_bytes(self.transaction_hash), "payment_network_identifier": to_checksum_address(self.payment_network_identifier), "token_network": self.token_network, "block_number": str(self.block_number), "block_hash": serialize_bytes(self.block_hash), }
def to_dict(self) -> Dict[str, Any]: return { "transaction_hash": serialize_bytes(self.transaction_hash), "secret_registry_address": to_checksum_address(self.secret_registry_address), "secrethash": serialize_bytes(self.secrethash), "secret": serialize_bytes(self.secret), "block_number": str(self.block_number), "block_hash": serialize_bytes(self.block_hash), }
def to_dict(self) -> Dict[str, Any]: return { "transaction_hash": serialize_bytes(self.transaction_hash), "our_onchain_locksroot": serialize_bytes(self.our_onchain_locksroot), "partner_onchain_locksroot": serialize_bytes(self.partner_onchain_locksroot), "canonical_identifier": self.canonical_identifier.to_dict(), "block_number": str(self.block_number), "block_hash": serialize_bytes(self.block_hash), }
def to_dict(self) -> typing.Dict[str, typing.Any]: result = { 'message_identifier': self.message_identifier, 'balance_proof': self.balance_proof, 'balance_hash': serialization.serialize_bytes(self.balance_proof.balance_hash), 'secrethash': serialization.serialize_bytes(self.secrethash), 'recipient': to_checksum_address(self.recipient), } return result
def _clean_non_serializables(data): copy = {} for key, value in data.items(): if callable(value): continue if hasattr(value, 'to_dict'): value = value.to_dict() if isinstance(value, dict): value = _clean_non_serializables(value) if isinstance(value, bytes): value = serialize_bytes(value) if isinstance(value, tuple): value = list(value) if isinstance(key, Enum): key = key.name if isinstance(value, Enum): value = value.value if value and not isinstance(value, builtin_types): try: pytoml.dumps({key: value}) except RuntimeError: continue copy[key] = value return copy
def to_dict(self) -> Dict[str, Any]: result = { 'expiration': str(self.expiration), 'secret': serialization.serialize_bytes(self.secret), } return result
def to_dict(self) -> Dict[str, Any]: return { 'transaction_hash': serialize_bytes(self.transaction_hash), 'payment_network_identifier': to_checksum_address(self.payment_network_identifier), 'token_network': self.token_network, 'block_number': str(self.block_number), }
def to_dict(self) -> Dict[str, Any]: return { 'secret': serialize_bytes(self.secret), 'routes': self.routes, 'transfer': self.transfer, 'balance_proof': self.balance_proof, }
def to_dict(self) -> typing.Dict[str, typing.Any]: return { 'secret': serialize_bytes(self.secret), 'sender': to_checksum_address(self.sender), 'routes': self.routes, 'transfer': self.transfer, }
def to_dict(self) -> Dict[str, Any]: result = { 'identifier': str(self.identifier), 'secrethash': serialization.serialize_bytes(self.secrethash), } return result
def to_dict(self) -> Dict[str, Any]: result = {"route": self.route, "transfer": self.transfer, "state": self.state} if self.secret is not None: result["secret"] = serialize_bytes(self.secret) return result
def to_dict(self) -> typing.Dict[str, typing.Any]: return { 'route': self.route, 'transfer': self.transfer, 'balance_proof': self.balance_proof, 'balance_hash': serialize_bytes(self.balance_proof.balance_hash), }
def to_dict(self) -> Dict[str, Any]: result = { 'secrethash': serialization.serialize_bytes(self.secrethash), 'reason': self.reason, } return result
def to_dict(self) -> Dict[str, Any]: return { 'transaction_hash': serialize_bytes(self.transaction_hash), 'token_network_identifier': to_checksum_address(self.token_network_identifier), 'channel_identifier': str(self.channel_identifier), 'deposit_transaction': self.deposit_transaction, 'block_number': str(self.block_number), }
def to_dict(self) -> Dict[str, Any]: result = { 'recipient': to_checksum_address(self.recipient), 'channel_identifier': str(self.queue_identifier.channel_identifier), 'message_identifier': str(self.message_identifier), 'secret': serialization.serialize_bytes(self.secret), } return result
def to_dict(self) -> Dict[str, Any]: result = { 'message_identifier': str(self.message_identifier), 'balance_proof': self.balance_proof, 'secrethash': serialization.serialize_bytes(self.secrethash), 'recipient': to_checksum_address(self.recipient), } return result
def to_dict(self) -> Dict[str, Any]: return { 'transaction_hash': serialize_bytes(self.transaction_hash), 'token_network_identifier': to_checksum_address(self.token_network_identifier), 'channel_identifier': str(self.channel_identifier), 'participant1': to_checksum_address(self.participant1), 'participant2': to_checksum_address(self.participant2), 'block_number': str(self.block_number), }
def to_dict(self) -> Dict[str, Any]: return { 'payment_identifier': str(self.payment_identifier), 'amount': str(self.amount), 'expiration': str(self.expiration), 'secrethash': serialize_bytes(self.secrethash), 'sender': to_checksum_address(self.sender), 'revealsecret': self.revealsecret, }
def to_dict(self) -> typing.Dict[str, typing.Any]: return { 'payment_network_identifier': to_checksum_address(self.payment_network_identifier), 'payment_identifier': str(self.payment_identifier), 'amount': str(self.amount), 'token_network_identifier': to_checksum_address(self.token_network_identifier), 'initiator': to_checksum_address(self.initiator), 'target': to_checksum_address(self.target), 'secret': serialization.serialize_bytes(self.secret), }
def to_dict(self) -> typing.Dict[str, typing.Any]: result = { 'route': self.route, 'transfer': self.transfer, 'state': self.state, } if self.secret is not None: result['secret'] = serialization.serialize_bytes(self.secret) return result
def to_dict(self) -> Dict[str, Any]: result = { 'recipient': to_checksum_address(self.recipient), 'channel_identifier': str(self.queue_identifier.channel_identifier), 'message_identifier': str(self.message_identifier), 'payment_identifier': str(self.payment_identifier), 'amount': str(self.amount), 'expiration': str(self.expiration), 'secrethash': serialization.serialize_bytes(self.secrethash), } return result
def to_dict(self) -> Dict[str, Any]: result = { 'recipient': to_checksum_address(self.recipient), 'channel_identifier': str(self.queue_identifier.channel_identifier), 'message_identifier': str(self.message_identifier), 'payment_identifier': str(self.payment_identifier), 'token_address': to_checksum_address(self.token), 'secret': serialization.serialize_bytes(self.secret), 'balance_proof': self.balance_proof, } return result
def get_event_with_balance_proof_by_balance_hash( storage: sqlite.SQLiteStorage, chain_id: ChainID, token_network_identifier: TokenNetworkID, channel_identifier: ChannelID, balance_hash: BalanceHash, ) -> sqlite.EventRecord: """ Returns the event which contains the corresponding balance proof. Use this function to find a balance proof for a call to settle, which only has the blinded balance proof data. """ return storage.get_latest_event_by_data_field({ 'balance_proof.chain_id': chain_id, 'balance_proof.token_network_identifier': to_checksum_address(token_network_identifier), 'balance_proof.channel_identifier': str(channel_identifier), 'balance_proof.balance_hash': serialize_bytes(balance_hash), })
def get_event_with_balance_proof_by_locksroot( storage: sqlite.SQLiteStorage, chain_id: ChainID, token_network_identifier: TokenNetworkID, channel_identifier: ChannelID, locksroot: Locksroot, ) -> sqlite.EventRecord: """ Returns the event which contains the corresponding balance proof. Use this function to find a balance proof for a call to unlock, which only happens after settle, so the channel has the unblinded version of the balance proof. """ return storage.get_latest_event_by_data_field({ 'balance_proof.chain_id': chain_id, 'balance_proof.token_network_identifier': to_checksum_address(token_network_identifier), 'balance_proof.channel_identifier': str(channel_identifier), 'balance_proof.locksroot': serialize_bytes(locksroot), })
def to_dict(self) -> Dict[str, Any]: return { 'secret': serialize_bytes(self.secret), 'secrethash': serialize_bytes(self.secrethash), 'sender': to_checksum_address(self.sender), }
def to_dict(self) -> Dict[str, Any]: return { 'message_identifier': str(self.message_identifier), 'secret': serialize_bytes(self.secret), 'balance_proof': self.balance_proof, }
def to_dict(self) -> Dict[str, Any]: return { 'block_number': str(self.block_number), 'gas_limit': self.gas_limit, 'block_hash': serialize_bytes(self.block_hash), }
def to_dict(self) -> Dict[str, Any]: return { 'transaction_hash': serialize_bytes(self.transaction_hash), 'payment_network': self.payment_network, 'block_number': str(self.block_number), }