|
17 | 17 | from electrum import lnutil |
18 | 18 | from electrum.plugin import run_hook |
19 | 19 | from electrum.i18n import _ |
20 | | -from electrum.ravencoin import COIN |
| 20 | +from electrum.ravencoin import COIN, make_op_return |
21 | 21 | from electrum.util import (AssetAmountModified, UserFacingException, get_asyncio_loop, bh2u, |
22 | 22 | InvalidBitcoinURI, maybe_extract_lightning_payment_identifier, NotEnoughFunds, |
23 | 23 | NoDynamicFeeEstimates, InvoiceError, parse_max_spend, RavenValue) |
@@ -340,21 +340,20 @@ def pay_onchain_dialog( |
340 | 340 | op_return_raw: str = self.op_return_e.text() |
341 | 341 | if len(op_return_raw) > 0: |
342 | 342 | try: |
| 343 | + if len(op_return_raw) <= 1: |
| 344 | + raise ValueError() |
343 | 345 | if len(op_return_raw) % 2 == 0: |
344 | 346 | text_to_encode = op_return_raw |
345 | 347 | else: |
| 348 | + self.show_warning(_('OP_RETURN predicted hex value has an odd number of characters; truncating by 1 to maintain a proper hex value.')) |
346 | 349 | text_to_encode = op_return_raw[:-1] |
347 | 350 | op_return_encoded = bytes.fromhex(text_to_encode) |
348 | 351 | except ValueError: |
349 | 352 | op_return_encoded = op_return_raw.encode('utf8') |
350 | | - |
351 | 353 | outputs.append( |
352 | 354 | PartialTxOutput( |
353 | 355 | value=0, |
354 | | - scriptpubkey= |
355 | | - b'\x6a' + |
356 | | - len(op_return_encoded).to_bytes(1, 'big', signed=False) + |
357 | | - op_return_encoded |
| 356 | + scriptpubkey=make_op_return(op_return_encoded) |
358 | 357 | )) |
359 | 358 |
|
360 | 359 | make_tx = lambda fee_est: self.wallet.make_unsigned_transaction( |
|
0 commit comments