commit db84de5493604a956c6d6492e7098e367b4b573f
parent 8ad6d5dddadda3df05da06a6a5634a8ebc5a8493
Author: SomberNight <somber.night@protonmail.com>
Date: Mon, 30 Mar 2020 02:42:07 +0200
trivial: use "chunks()" for htlc_sigs in lnchannel
Diffstat:
3 files changed, 6 insertions(+), 3 deletions(-)
diff --git a/electrum/lnchannel.py b/electrum/lnchannel.py
@@ -32,7 +32,7 @@ import attr
from . import ecc
from . import constants
-from .util import bfh, bh2u
+from .util import bfh, bh2u, chunks
from .bitcoin import redeem_script_to_address
from .crypto import sha256, sha256d
from .transaction import Transaction, PartialTransaction
@@ -628,7 +628,7 @@ class Channel(Logger):
def get_remote_htlc_sig_for_htlc(self, *, htlc_relative_idx: int) -> bytes:
data = self.config[LOCAL].current_htlc_signatures
- htlc_sigs = [data[i:i + 64] for i in range(0, len(data), 64)]
+ htlc_sigs = list(chunks(data, 64))
htlc_sig = htlc_sigs[htlc_relative_idx]
remote_htlc_sig = ecc.der_sig_from_sig_string(htlc_sig) + b'\x01'
return remote_htlc_sig
diff --git a/electrum/lnpeer.py b/electrum/lnpeer.py
@@ -1076,7 +1076,7 @@ class Peer(Logger):
if chan.hm.is_revack_pending(LOCAL):
raise RemoteMisbehaving('received commitment_signed before we revoked previous ctx')
data = payload["htlc_signature"]
- htlc_sigs = [data[i:i+64] for i in range(0, len(data), 64)]
+ htlc_sigs = list(chunks(data, 64))
chan.receive_new_commitment(payload["signature"], htlc_sigs)
self.send_revoke_and_ack(chan)
diff --git a/electrum/tests/test_util.py b/electrum/tests/test_util.py
@@ -108,6 +108,9 @@ class TestUtil(ElectrumTestCase):
def test_chunks(self):
self.assertEqual([[1, 2], [3, 4], [5]],
list(chunks([1, 2, 3, 4, 5], 2)))
+ self.assertEqual([], list(chunks(b'', 64)))
+ self.assertEqual([b'12', b'34', b'56'],
+ list(chunks(b'123456', 2)))
with self.assertRaises(ValueError):
list(chunks([1, 2, 3], 0))