new modules: base_proto.{bitcoin,ethereum}.addrdata
This commit is contained in:
parent
2f7e022288
commit
d63cedfbdd
4 changed files with 45 additions and 32 deletions
|
|
@ -69,7 +69,7 @@ class AddrData(MMGenObject):
|
|||
class TwAddrData(AddrData,metaclass=AsyncInit):
|
||||
|
||||
def __new__(cls,proto,*args,**kwargs):
|
||||
return MMGenObject.__new__(base_proto_subclass(cls,proto,'tw','common'))
|
||||
return MMGenObject.__new__(base_proto_subclass(cls,proto,None,'addrdata'))
|
||||
|
||||
async def __init__(self,proto,wallet=None):
|
||||
from .rpc import rpc_init
|
||||
|
|
|
|||
39
mmgen/base_proto/bitcoin/addrdata.py
Executable file
39
mmgen/base_proto/bitcoin/addrdata.py
Executable file
|
|
@ -0,0 +1,39 @@
|
|||
#!/usr/bin/env python3
|
||||
#
|
||||
# mmgen = Multi-Mode GENerator, a command-line cryptocurrency wallet
|
||||
# Copyright (C)2013-2022 The MMGen Project <mmgen@tuta.io>
|
||||
# Licensed under the GNU General Public License, Version 3:
|
||||
# https://www.gnu.org/licenses
|
||||
# Public project repositories:
|
||||
# https://github.com/mmgen/mmgen
|
||||
# https://gitlab.com/mmgen/mmgen
|
||||
|
||||
"""
|
||||
base_proto.bitcoin.addrdata: Bitcoin base protocol addrdata classes
|
||||
"""
|
||||
|
||||
from ...addrdata import TwAddrData
|
||||
from ...util import vmsg
|
||||
|
||||
class BitcoinTwAddrData(TwAddrData):
|
||||
|
||||
msgs = {
|
||||
'multiple_acct_addrs': """
|
||||
ERROR: More than one address found for account: {acct!r}.
|
||||
Your 'wallet.dat' file appears to have been altered by a non-{proj} program.
|
||||
Please restore your tracking wallet from a backup or create a new one and
|
||||
re-import your addresses.
|
||||
"""
|
||||
}
|
||||
|
||||
async def get_tw_data(self,wallet=None):
|
||||
vmsg('Getting address data from tracking wallet')
|
||||
c = self.rpc
|
||||
if 'label_api' in c.caps:
|
||||
accts = await c.call('listlabels')
|
||||
ll = await c.batch_call('getaddressesbylabel',[(k,) for k in accts])
|
||||
alists = [list(a.keys()) for a in ll]
|
||||
else:
|
||||
accts = await c.call('listaccounts',0,True)
|
||||
alists = await c.batch_call('getaddressesbyaccount',[(k,) for k in accts])
|
||||
return list(zip(accts,alists))
|
||||
|
|
@ -11,29 +11,3 @@
|
|||
"""
|
||||
base_proto.bitcoin.tw: Bitcoin base protocol tracking wallet dependency classes
|
||||
"""
|
||||
|
||||
from ....addrdata import TwAddrData
|
||||
from ....util import vmsg
|
||||
|
||||
class BitcoinTwAddrData(TwAddrData):
|
||||
|
||||
msgs = {
|
||||
'multiple_acct_addrs': """
|
||||
ERROR: More than one address found for account: {acct!r}.
|
||||
Your 'wallet.dat' file appears to have been altered by a non-{proj} program.
|
||||
Please restore your tracking wallet from a backup or create a new one and
|
||||
re-import your addresses.
|
||||
"""
|
||||
}
|
||||
|
||||
async def get_tw_data(self,wallet=None):
|
||||
vmsg('Getting address data from tracking wallet')
|
||||
c = self.rpc
|
||||
if 'label_api' in c.caps:
|
||||
accts = await c.call('listlabels')
|
||||
ll = await c.batch_call('getaddressesbylabel',[(k,) for k in accts])
|
||||
alists = [list(a.keys()) for a in ll]
|
||||
else:
|
||||
accts = await c.call('listaccounts',0,True)
|
||||
alists = await c.batch_call('getaddressesbyaccount',[(k,) for k in accts])
|
||||
return list(zip(accts,alists))
|
||||
|
|
|
|||
|
|
@ -17,11 +17,11 @@
|
|||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
"""
|
||||
base_proto.ethereum.tw: Ethereum tracking wallet dependency classes
|
||||
base_proto.ethereum.addrdata: Ethereum TwAddrData classes
|
||||
"""
|
||||
|
||||
from ....addrdata import TwAddrData
|
||||
from ....util import vmsg
|
||||
from ...addrdata import TwAddrData
|
||||
from ...util import vmsg
|
||||
|
||||
class EthereumTwAddrData(TwAddrData):
|
||||
|
||||
|
|
@ -33,8 +33,8 @@ class EthereumTwAddrData(TwAddrData):
|
|||
}
|
||||
|
||||
async def get_tw_data(self,wallet=None):
|
||||
from ....tw.ctl import TrackingWallet
|
||||
from ....util import vmsg
|
||||
from ...tw.ctl import TrackingWallet
|
||||
from ...util import vmsg
|
||||
vmsg('Getting address data from tracking wallet')
|
||||
tw = (wallet or await TrackingWallet(self.proto)).mmid_ordered_dict
|
||||
# emulate the output of RPC 'listaccounts' and 'getaddressesbyaccount'
|
||||
Loading…
Add table
Add a link
Reference in a new issue