Browse Source

lnpeer: code factorization

hard-fail-on-bad-server-string
ThomasV 5 years ago
parent
commit
7472eba78c
  1. 48
      electrum/lnpeer.py

48
electrum/lnpeer.py

@ -580,18 +580,9 @@ class Peer(Logger):
funding_index = funding_tx.outputs().index(funding_output)
# remote commitment transaction
channel_id, funding_txid_bytes = channel_id_from_funding_tx(funding_txid, funding_index)
chan_dict = {
"node_id": self.pubkey,
"channel_id": channel_id,
"short_channel_id": None,
"funding_outpoint": Outpoint(funding_txid, funding_index),
"remote_config": remote_config,
"local_config": local_config,
"constraints": ChannelConstraints(capacity=funding_sat, is_initiator=True, funding_txn_minimum_depth=funding_txn_minimum_depth),
"remote_update": None,
"state": channel_states.PREOPENING.name,
"revocation_store": {},
}
outpoint = Outpoint(funding_txid, funding_index)
constraints = ChannelConstraints(capacity=funding_sat, is_initiator=True, funding_txn_minimum_depth=funding_txn_minimum_depth)
chan_dict = self.create_channel_storage(channel_id, outpoint, local_config, remote_config, constraints)
chan = Channel(chan_dict,
sweep_address=self.lnworker.sweep_address,
lnworker=self.lnworker,
@ -609,6 +600,21 @@ class Peer(Logger):
chan.open_with_first_pcp(remote_per_commitment_point, remote_sig)
return chan, funding_tx
def create_channel_storage(self, channel_id, outpoint, local_config, remote_config, constraints):
chan_dict = {
"node_id": self.pubkey.hex(),
"channel_id": channel_id.hex(),
"short_channel_id": None,
"funding_outpoint": outpoint,
"remote_config": remote_config,
"local_config": local_config,
"constraints": constraints,
"remote_update": None,
"state": channel_states.PREOPENING.name,
"revocation_store": {},
}
return chan_dict
async def on_open_channel(self, payload):
# payload['channel_flags']
if payload['chain_hash'] != constants.net.rev_genesis_bytes():
@ -647,12 +653,7 @@ class Peer(Logger):
remote_balance_sat = funding_sat * 1000 - push_msat
remote_dust_limit_sat = int.from_bytes(payload['dust_limit_satoshis'], byteorder='big') # TODO validate
remote_reserve_sat = self.validate_remote_reserve(payload['channel_reserve_satoshis'], remote_dust_limit_sat, funding_sat)
chan_dict = {
"node_id": self.pubkey,
"channel_id": channel_id,
"short_channel_id": None,
"funding_outpoint": Outpoint(funding_txid, funding_idx),
"remote_config": RemoteConfig(
remote_config = RemoteConfig(
payment_basepoint=OnlyPubkeyKeypair(payload['payment_basepoint']),
multisig_key=OnlyPubkeyKeypair(payload['funding_pubkey']),
htlc_basepoint=OnlyPubkeyKeypair(payload['htlc_basepoint']),
@ -667,13 +668,10 @@ class Peer(Logger):
htlc_minimum_msat=int.from_bytes(payload['htlc_minimum_msat'], 'big'), # TODO validate
next_per_commitment_point=payload['first_per_commitment_point'],
current_per_commitment_point=None,
),
"local_config": local_config,
"constraints": ChannelConstraints(capacity=funding_sat, is_initiator=False, funding_txn_minimum_depth=min_depth),
"remote_update": None,
"state": channel_states.PREOPENING.name,
"revocation_store": {},
}
)
constraints = ChannelConstraints(capacity=funding_sat, is_initiator=False, funding_txn_minimum_depth=min_depth)
outpoint = Outpoint(funding_txid, funding_idx)
chan_dict = self.create_channel_storage(channel_id, outpoint, local_config, remote_config, constraints)
chan = Channel(chan_dict,
sweep_address=self.lnworker.sweep_address,
lnworker=self.lnworker,

Loading…
Cancel
Save