Skip to content
This repository has been archived by the owner on Oct 27, 2024. It is now read-only.

Commit

Permalink
Use hex256 in MS database
Browse files Browse the repository at this point in the history
This makes lexicographic the same as numeric sorting. Sorting hexed
block numbers for scheduled events is simple and reliable, now.
  • Loading branch information
karlb committed May 16, 2019
1 parent dd4c393 commit cdf7680
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions src/monitoring_service/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
OnChainUpdateStatus,
)
from raiden.utils.typing import Address, BlockNumber, ChainID, ChannelID, TokenNetworkAddress
from raiden_libs.database import BaseDatabase
from raiden_libs.database import BaseDatabase, hex256

SubEvent = Union[ActionMonitoringTriggeredEvent, ActionClaimRewardTriggeredEvent]

Expand All @@ -33,14 +33,14 @@ class SharedDatabase(BaseDatabase):

def upsert_monitor_request(self, request: MonitorRequest) -> None:
values = [
hex(request.channel_identifier),
hex256(request.channel_identifier),
to_checksum_address(request.token_network_address),
request.balance_hash,
hex(request.nonce),
hex256(request.nonce),
request.additional_hash,
request.closing_signature,
request.non_closing_signature,
hex(request.reward_amount),
hex256(request.reward_amount),
request.reward_proof_signature,
to_checksum_address(request.non_closing_signer),
]
Expand All @@ -65,7 +65,7 @@ def get_monitor_request(
AND non_closing_signer = ?
""",
[
hex(channel_id),
hex256(channel_id),
to_checksum_address(token_network_address),
to_checksum_address(non_closing_signer),
],
Expand All @@ -83,20 +83,20 @@ def monitor_request_count(self) -> int:
def upsert_channel(self, channel: Channel) -> None:
values = [
to_checksum_address(channel.token_network_address),
hex(channel.identifier),
hex256(channel.identifier),
to_checksum_address(channel.participant1),
to_checksum_address(channel.participant2),
hex(channel.settle_timeout),
hex256(channel.settle_timeout),
channel.state,
hex(channel.closing_block) if channel.closing_block else None,
hex256(channel.closing_block) if channel.closing_block else None,
channel.closing_participant,
channel.closing_tx_hash,
channel.claim_tx_hash,
]
if channel.update_status:
values += [
to_checksum_address(channel.update_status.update_sender_address),
hex(channel.update_status.nonce),
hex256(channel.update_status.nonce),
]
else:
values += [None, None]
Expand All @@ -114,7 +114,7 @@ def get_channel(
SELECT * FROM channel
WHERE identifier = ? AND token_network_address = ?
""",
[hex(channel_id), to_checksum_address(token_network_address)],
[hex256(channel_id), to_checksum_address(token_network_address)],
).fetchone()

if row is None:
Expand All @@ -141,10 +141,10 @@ def channel_count(self) -> int:
def upsert_scheduled_event(self, event: ScheduledEvent) -> None:
contained_event: SubEvent = cast(SubEvent, event.event)
values = [
hex(event.trigger_block_number),
hex256(event.trigger_block_number),
EVENT_TYPE_ID_MAP[type(contained_event)],
to_checksum_address(contained_event.token_network_address),
hex(contained_event.channel_identifier),
hex256(contained_event.channel_identifier),
contained_event.non_closing_participant,
]
upsert_sql = "INSERT OR REPLACE INTO scheduled_events VALUES ({})".format(
Expand All @@ -158,7 +158,7 @@ def get_scheduled_events(self, max_trigger_block: BlockNumber) -> List[Scheduled
SELECT * FROM scheduled_events
WHERE trigger_block_number <= ?
""",
[hex(max_trigger_block)],
[hex256(max_trigger_block)],
).fetchall()

def create_scheduled_event(row: sqlite3.Row) -> ScheduledEvent:
Expand All @@ -178,9 +178,9 @@ def create_scheduled_event(row: sqlite3.Row) -> ScheduledEvent:
def remove_scheduled_event(self, event: ScheduledEvent) -> None:
contained_event: SubEvent = cast(SubEvent, event.event)
values = [
hex(event.trigger_block_number),
hex256(event.trigger_block_number),
to_checksum_address(contained_event.token_network_address),
hex(contained_event.channel_identifier),
hex256(contained_event.channel_identifier),
contained_event.non_closing_participant,
]
self.conn.execute(
Expand Down

0 comments on commit cdf7680

Please sign in to comment.