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

Commit

Permalink
Use insert and upsert helpers in more cases
Browse files Browse the repository at this point in the history
  • Loading branch information
karlb committed May 16, 2019
1 parent 82223f5 commit dd4c393
Showing 1 changed file with 3 additions and 52 deletions.
55 changes: 3 additions & 52 deletions src/pathfinding_service/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,24 +58,7 @@ def upsert_capacity_update(self, message: UpdatePFS) -> None:
updating_capacity=hex256(message.updating_capacity),
other_capacity=hex256(message.other_capacity),
)
self.conn.execute(
"""
INSERT OR REPLACE INTO capacity_update (
updating_participant,
token_network_address,
channel_id,
updating_capacity,
other_capacity
) VALUES (
:updating_participant,
:token_network_address,
:channel_id,
:updating_capacity,
:other_capacity
)
""",
capacity_update_dict,
)
self.upsert("capacity_update", capacity_update_dict)

def get_capacity_updates(
self,
Expand Down Expand Up @@ -169,27 +152,7 @@ def upsert_channel_view(self, channel_view: ChannelView) -> None:
"absolute_fee",
):
cv_dict[key] = hex256(cv_dict[key])
self.conn.execute(
"""
INSERT OR REPLACE INTO channel_view (
token_network_address, channel_id, participant1, participant2,
settle_timeout, capacity, reveal_timeout, deposit,
update_nonce, absolute_fee, relative_fee
) VALUES (
:token_network_address,
:channel_id,
:participant1, :participant2,
:settle_timeout,
:capacity,
:reveal_timeout,
:deposit,
:update_nonce,
:absolute_fee,
:relative_fee
)
""",
cv_dict,
)
self.upsert("channel_view", cv_dict)

def get_channel_views(self) -> Iterator[ChannelView]:
query = "SELECT * FROM channel_view"
Expand All @@ -212,19 +175,7 @@ def prepare_feedback(self, token: FeedbackToken, route: List[Address]) -> None:
token_network_address=to_checksum_address(token.token_network_address),
route=json.dumps(hexed_route),
)
self.conn.execute(
"""
INSERT INTO feedback (
token_id, creation_time, token_network_address, route
) VALUES (
:token_id,
:creation_time,
:token_network_address,
:route
)
""",
token_dict,
)
self.insert("feedback", token_dict)

def update_feedback(self, token: FeedbackToken, route: List[Address], successful: bool) -> int:
hexed_route = [to_checksum_address(e) for e in route]
Expand Down

0 comments on commit dd4c393

Please sign in to comment.