Skip to content

Commit

Permalink
convert invoices in json_db
Browse files Browse the repository at this point in the history
  • Loading branch information
ecdsa committed Dec 4, 2019
1 parent 566ce9c commit 779b66d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
14 changes: 12 additions & 2 deletions electrum/json_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@
import jsonpatch

from . import util, bitcoin
from .util import profiler, WalletFileException, multisig_type, TxMinedInfo, bfh
from .util import profiler, WalletFileException, multisig_type, TxMinedInfo, bfh, PR_TYPE_ONCHAIN
from .keystore import bip44_derivation
from .transaction import Transaction, TxOutpoint
from .transaction import Transaction, TxOutpoint, PartialTxOutput
from .logging import Logger

# seed_version is now used for the version of the wallet file
Expand Down Expand Up @@ -1020,6 +1020,16 @@ def _load_transactions(self):
# convert tx_fees tuples to NamedTuples
for tx_hash, tuple_ in self.tx_fees.items():
self.tx_fees.__setitem__(tx_hash, TxFeesValue(*tuple_), patch=False)
# convert invoices
# TODO invoices being these contextual dicts even internally,
# where certain keys are only present depending on values of other keys...
# it's horrible. we need to change this, at least for the internal representation,
# to something that can be typed.
self.invoices = self.get_dict('invoices')
for invoice_key, invoice in self.invoices.items():
if invoice.get('type') == PR_TYPE_ONCHAIN:
outputs = [PartialTxOutput.from_legacy_tuple(*output) for output in invoice.get('outputs')]
invoice.__setitem__('outputs', outputs, patch=False)

@modifier
def clear_history(self):
Expand Down
10 changes: 1 addition & 9 deletions electrum/wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,15 +244,7 @@ def __init__(self, storage: WalletStorage, *, config: SimpleConfig):
self.fiat_value = storage.db.get_dict('fiat_value')
self.receive_requests = storage.db.get_dict('payment_requests')
self.invoices = storage.db.get_dict('invoices')
# convert invoices
# TODO invoices being these contextual dicts even internally,
# where certain keys are only present depending on values of other keys...
# it's horrible. we need to change this, at least for the internal representation,
# to something that can be typed.
for invoice_key, invoice in self.invoices.items():
if invoice.get('type') == PR_TYPE_ONCHAIN:
outputs = [PartialTxOutput.from_legacy_tuple(*output) for output in invoice.get('outputs')]
invoice['outputs'] = outputs

self._prepare_onchain_invoice_paid_detection()
self.calc_unused_change_addresses()
# save wallet type the first time
Expand Down

0 comments on commit 779b66d

Please sign in to comment.