def get_channels(self) -> Iterator[Channel]: for row in self.conn.execute("SELECT * FROM channel"): channel_dict = dict(zip(row.keys(), row)) channel_dict["fee_schedule1"] = json.loads( channel_dict["fee_schedule1"]) channel_dict["fee_schedule2"] = json.loads( channel_dict["fee_schedule2"]) yield Channel.Schema().load(channel_dict)
def upsert_channel(self, channel: Channel) -> None: channel_dict = Channel.Schema().dump(channel) for key in ( "channel_id", "settle_timeout", "capacity1", "reveal_timeout1", "update_nonce1", "capacity2", "reveal_timeout2", "update_nonce2", ): channel_dict[key] = hex256(int(channel_dict[key])) channel_dict["fee_schedule1"] = json.dumps(channel_dict["fee_schedule1"]) channel_dict["fee_schedule2"] = json.dumps(channel_dict["fee_schedule2"]) self.upsert("channel", channel_dict)