Skip to content

Commit

Permalink
global var rename: g.rpch -> g.rpc
Browse files Browse the repository at this point in the history
  • Loading branch information
mmgen committed May 10, 2020
1 parent 57f12cd commit 78a199c
Show file tree
Hide file tree
Showing 12 changed files with 71 additions and 71 deletions.
10 changes: 5 additions & 5 deletions mmgen/addr.py
Original file line number Diff line number Diff line change
Expand Up @@ -1050,12 +1050,12 @@ def coinaddr2mmaddr(self,coinaddr):
@classmethod
def get_tw_data(cls,wallet=None):
vmsg('Getting address data from tracking wallet')
if 'label_api' in g.rpch.caps:
accts = g.rpch.listlabels()
alists = [list(a.keys()) for a in g.rpch.getaddressesbylabel([[k] for k in accts],batch=True)]
if 'label_api' in g.rpc.caps:
accts = g.rpc.listlabels()
alists = [list(a.keys()) for a in g.rpc.getaddressesbylabel([[k] for k in accts],batch=True)]
else:
accts = g.rpch.listaccounts(0,True)
alists = g.rpch.getaddressesbyaccount([[k] for k in accts],batch=True)
accts = g.rpc.listaccounts(0,True)
alists = g.rpc.getaddressesbyaccount([[k] for k in accts],batch=True)
return list(zip(accts,alists))

def add_tw_data(self,wallet):
Expand Down
12 changes: 6 additions & 6 deletions mmgen/altcoins/eth/contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def do_call(self,method_sig,method_args='',toUnit=False):
data = create_method_id(method_sig) + method_args
if g.debug:
msg('ETH_CALL {}: {}'.format(method_sig,'\n '.join(parse_abi(data))))
ret = g.rpch.eth_call({ 'to': '0x'+self.addr, 'data': '0x'+data })
ret = g.rpc.eth_call({ 'to': '0x'+self.addr, 'data': '0x'+data })
if toUnit:
return int(ret,16) * self.base_unit
else:
Expand Down Expand Up @@ -108,7 +108,7 @@ def info(self):
'total supply:', self.total_supply())

def code(self):
return g.rpch.eth_getCode('0x'+self.addr)[2:]
return g.rpc.eth_getCode('0x'+self.addr)[2:]

def create_data(self,to_addr,amt,method_sig='transfer(address,uint256)',from_addr=None):
from_arg = from_addr.rjust(64,'0') if from_addr else ''
Expand All @@ -131,8 +131,8 @@ def txsign(self,tx_in,key,from_addr,chain_id=None):
from .pyethereum.transactions import Transaction

if chain_id is None:
chain_id_method = ('parity_chainId','eth_chainId')['eth_chainId' in g.rpch.caps]
chain_id = int(g.rpch.request(chain_id_method),16)
chain_id_method = ('parity_chainId','eth_chainId')['eth_chainId' in g.rpc.caps]
chain_id = int(g.rpc.request(chain_id_method),16)
tx = Transaction(**tx_in).sign(key,chain_id)
hex_tx = rlp.encode(tx).hex()
coin_txid = CoinTxID(tx.hash.hex())
Expand All @@ -148,7 +148,7 @@ def txsign(self,tx_in,key,from_addr,chain_id=None):
# The following are used for token deployment only:

def txsend(self,hex_tx):
return g.rpch.eth_sendRawTransaction('0x'+hex_tx).replace('0x','',1)
return g.rpc.eth_sendRawTransaction('0x'+hex_tx).replace('0x','',1)

def transfer( self,from_addr,to_addr,amt,key,start_gas,gasPrice,
method_sig='transfer(address,uint256)',
Expand All @@ -157,7 +157,7 @@ def transfer( self,from_addr,to_addr,amt,key,start_gas,gasPrice,
tx_in = self.make_tx_in(
from_addr,to_addr,amt,
start_gas,gasPrice,
nonce = int(g.rpch.parity_nextNonce('0x'+from_addr),16),
nonce = int(g.rpc.parity_nextNonce('0x'+from_addr),16),
method_sig = method_sig,
from_addr2 = from_addr2 )
(hex_tx,coin_txid) = self.txsign(tx_in,key,from_addr)
Expand Down
2 changes: 1 addition & 1 deletion mmgen/altcoins/eth/tw.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def add_token_params_fields():
def rpc_init(self): pass

def rpc_get_balance(self,addr):
return ETHAmt(int(g.rpch.eth_getBalance('0x'+addr),16),'wei')
return ETHAmt(int(g.rpc.eth_getBalance('0x'+addr),16),'wei')

@write_mode
def import_address(self,addr,label,foo):
Expand Down
22 changes: 11 additions & 11 deletions mmgen/altcoins/eth/tx.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def __init__(self,*args,**kwargs):

@classmethod
def get_exec_status(cls,txid,silent=False):
d = g.rpch.eth_getTransactionReceipt('0x'+txid)
d = g.rpc.eth_getTransactionReceipt('0x'+txid)
if not silent:
if 'contractAddress' in d and d['contractAddress']:
msg('Contract address: {}'.format(d['contractAddress'].replace('0x','')))
Expand Down Expand Up @@ -121,18 +121,18 @@ def check_txfile_hex_data(self):
return d # 'token_addr','decimals' required by Token subclass

def get_nonce(self):
return ETHNonce(int(g.rpch.parity_nextNonce('0x'+self.inputs[0].addr),16))
return ETHNonce(int(g.rpc.parity_nextNonce('0x'+self.inputs[0].addr),16))

def make_txobj(self): # called by create_raw()
chain_id_method = ('parity_chainId','eth_chainId')['eth_chainId' in g.rpch.caps]
chain_id_method = ('parity_chainId','eth_chainId')['eth_chainId' in g.rpc.caps]
self.txobj = {
'from': self.inputs[0].addr,
'to': self.outputs[0].addr if self.outputs else Str(''),
'amt': self.outputs[0].amt if self.outputs else ETHAmt('0'),
'gasPrice': self.usr_rel_fee or self.fee_abs2rel(self.fee,to_unit='eth'),
'startGas': self.start_gas,
'nonce': self.get_nonce(),
'chainId': Int(g.rpch.request(chain_id_method),16),
'chainId': Int(g.rpc.request(chain_id_method),16),
'data': self.usr_contract_data,
}

Expand All @@ -157,7 +157,7 @@ def update_txid(self):
self.txid = MMGenTxID(make_chksum_6(self.hex).upper())

def get_blockcount(self):
return Int(g.rpch.eth_blockNumber(),16)
return Int(g.rpc.eth_blockNumber(),16)

def process_cmd_args(self,cmd_args,ad_f,ad_w):
lc = len(cmd_args)
Expand Down Expand Up @@ -195,7 +195,7 @@ def fee_abs2rel(self,abs_fee,to_unit='Gwei'):

# get rel_fee (gas price) from network, return in native wei
def get_rel_fee_from_network(self):
return Int(g.rpch.eth_gasPrice(),16),'eth_gasPrice' # ==> rel_fee,fe_type
return Int(g.rpc.eth_gasPrice(),16),'eth_gasPrice' # ==> rel_fee,fe_type

# given rel fee and units, return absolute fee using tx_gas
def convert_fee_spec(self,foo,units,amt,unit):
Expand Down Expand Up @@ -327,14 +327,14 @@ def get_status(self,status=False):
class r(object): pass

def is_in_mempool():
if not 'full_node' in g.rpch.caps:
if not 'full_node' in g.rpc.caps:
return False
return '0x'+self.coin_txid in [x['hash'] for x in g.rpch.parity_pendingTransactions()]
return '0x'+self.coin_txid in [x['hash'] for x in g.rpc.parity_pendingTransactions()]

def is_in_wallet():
d = g.rpch.eth_getTransactionReceipt('0x'+self.coin_txid)
d = g.rpc.eth_getTransactionReceipt('0x'+self.coin_txid)
if d and 'blockNumber' in d and d['blockNumber'] is not None:
r.confs = 1 + int(g.rpch.eth_blockNumber(),16) - int(d['blockNumber'],16)
r.confs = 1 + int(g.rpc.eth_blockNumber(),16) - int(d['blockNumber'],16)
r.exec_status = int(d['status'],16)
return True
return False
Expand Down Expand Up @@ -372,7 +372,7 @@ def send(self,prompt_user=True,exit_on_fail=False):
if prompt_user:
self.confirm_send()

ret = None if g.bogus_send else g.rpch.eth_sendRawTransaction('0x'+self.hex,on_fail='return')
ret = None if g.bogus_send else g.rpc.eth_sendRawTransaction('0x'+self.hex,on_fail='return')

from mmgen.rpc import rpc_error,rpc_errmsg
if rpc_error(ret):
Expand Down
2 changes: 1 addition & 1 deletion mmgen/globalvars.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def die(ev=0,s=''):
monero_wallet_rpc_user = 'monero'
monero_wallet_rpc_password = ''
rpc_fail_on_command = ''
rpch = None # global RPC handle
rpc = None # global RPC handle
use_cached_balances = False

# regtest:
Expand Down
2 changes: 1 addition & 1 deletion mmgen/main_split.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@
opt.no_blank = True

gmsg("Creating timelocked transaction for long chain ({})".format(g.coin))
locktime = int(opt.locktime or 0) or g.rpch.getblockcount()
locktime = int(opt.locktime or 0) or g.rpc.getblockcount()
tx1.create(mmids[0],locktime)

tx1.format()
Expand Down
2 changes: 1 addition & 1 deletion mmgen/rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ def resolve_token_arg(token_arg):
conn.caps += ('full_node',)

if g.token:
g.rpch = conn # set g.rpch so rpc_init() will return immediately
g.rpc = conn # set g.rpc so rpc_init() will return immediately
(g.token,g.dcoin) = resolve_token_arg(g.token)

return conn
Expand Down
44 changes: 22 additions & 22 deletions mmgen/tw.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ def get_tw_label(s):
except: return None

_date_formatter = {
'days': lambda secs: (g.rpch.cur_date - secs) // 86400,
'days': lambda secs: (g.rpc.cur_date - secs) // 86400,
'date': lambda secs: '{}-{:02}-{:02}'.format(*time.gmtime(secs)[:3])[2:],
'date_time': lambda secs: '{}-{:02}-{:02} {:02}:{:02}'.format(*time.gmtime(secs)[:5]),
}

def _set_dates(us):
if us and us[0].date is None:
# 'blocktime' differs from 'time', is same as getblockheader['time']
dates = [o['blocktime'] for o in g.rpch.calls('gettransaction',[(o.txid,) for o in us])]
dates = [o['blocktime'] for o in g.rpc.calls('gettransaction',[(o.txid,) for o in us])]
for o,date in zip(us,dates):
o.date = date

Expand Down Expand Up @@ -149,7 +149,7 @@ def get_unspent_rpc(self):

# for now, self.addrs is just an empty list for Bitcoin and friends
add_args = (9999999,self.addrs) if self.addrs else ()
return g.rpch.listunspent(self.minconf,*add_args)
return g.rpc.listunspent(self.minconf,*add_args)

def get_unspent_data(self):
if g.bogus_wallet_data: # for debugging purposes only
Expand All @@ -159,7 +159,7 @@ def get_unspent_data(self):

if not us_rpc: die(0,self.wmsg['no_spendable_outputs'])
tr_rpc = []
lbl_id = ('account','label')['label_api' in g.rpch.caps]
lbl_id = ('account','label')['label_api' in g.rpc.caps]
for o in us_rpc:
if not lbl_id in o:
continue # coinbase outputs have no account field
Expand Down Expand Up @@ -325,16 +325,16 @@ def format_for_printing(self,color=False,show_confs=True):
A=i.amt.fmt(color=color),
A2=(i.amt2.fmt(color=color) if i.amt2 is not None else ''),
c=i.confs,
b=g.rpch.blockcount - (i.confs - 1),
b=g.rpc.blockcount - (i.confs - 1),
D=self.age_disp(i,'date_time'),
l=i.label.hl(color=color) if i.label else
TwComment.fmtc('',color=color,nullrepl='-',width=max_lbl_len)).rstrip())

fs = '{} (block #{}, {} UTC)\nSort order: {}\n{}\n\nTotal {}: {}\n'
self.fmt_print = fs.format(
capfirst(self.desc),
g.rpch.blockcount,
make_timestr(g.rpch.cur_date),
g.rpc.blockcount,
make_timestr(g.rpc.cur_date),
' '.join(self.sort_info(include_group=False)),
'\n'.join(out),
g.dcoin,
Expand Down Expand Up @@ -454,7 +454,7 @@ def age_disp(self,o,age_fmt):
if age_fmt == 'confs':
return o.confs
elif age_fmt == 'block':
return g.rpch.blockcount - (o.confs - 1)
return g.rpc.blockcount - (o.confs - 1)
else:
return _date_formatter[age_fmt](o.date)

Expand Down Expand Up @@ -492,8 +492,8 @@ def check_addr_array_lens(acct_pairs):
self.total = g.proto.coin_amt('0')
rpc_init()

lbl_id = ('account','label')['label_api' in g.rpch.caps]
for d in g.rpch.listunspent(0):
lbl_id = ('account','label')['label_api' in g.rpc.caps]
for d in g.rpc.listunspent(0):
if not lbl_id in d: continue # skip coinbase outputs with missing account
if d['confirmations'] < minconf: continue
label = get_tw_label(d[lbl_id])
Expand All @@ -519,12 +519,12 @@ def check_addr_array_lens(acct_pairs):
if showempty or all_labels:
# for compatibility with old mmids, must use raw RPC rather than native data for matching
# args: minconf,watchonly, MUST use keys() so we get list, not dict
if 'label_api' in g.rpch.caps:
acct_list = g.rpch.listlabels()
acct_addrs = [list(a.keys()) for a in g.rpch.getaddressesbylabel([[k] for k in acct_list],batch=True)]
if 'label_api' in g.rpc.caps:
acct_list = g.rpc.listlabels()
acct_addrs = [list(a.keys()) for a in g.rpc.getaddressesbylabel([[k] for k in acct_list],batch=True)]
else:
acct_list = list(g.rpch.listaccounts(0,True).keys()) # raw list, no 'L'
acct_addrs = g.rpch.getaddressesbyaccount([[a] for a in acct_list],batch=True) # use raw list here
acct_list = list(g.rpc.listaccounts(0,True).keys()) # raw list, no 'L'
acct_addrs = g.rpc.getaddressesbyaccount([[a] for a in acct_list],batch=True) # use raw list here
acct_labels = MMGenList([get_tw_label(a) for a in acct_list])
check_dup_mmid(acct_labels)
assert len(acct_list) == len(acct_addrs),(
Expand Down Expand Up @@ -753,11 +753,11 @@ def mmid_ordered_dict(self):

@write_mode
def import_address(self,addr,label,rescan):
return g.rpch.importaddress(addr,label,rescan,timeout=(False,3600)[rescan])
return g.rpc.importaddress(addr,label,rescan,timeout=(False,3600)[rescan])

@write_mode
def batch_import_address(self,arg_list):
return g.rpch.importaddress(arg_list,batch=True)
return g.rpc.importaddress(arg_list,batch=True)

def force_write(self):
mode_save = self.mode
Expand Down Expand Up @@ -796,13 +796,13 @@ def is_in_wallet(self,addr):
def set_label(self,coinaddr,lbl):
# bitcoin-abc 'setlabel' RPC is broken, so use old 'importaddress' method to set label
# broken behavior: new label is set OK, but old label gets attached to another address
if 'label_api' in g.rpch.caps and g.coin != 'BCH':
return g.rpch.setlabel(coinaddr,lbl,on_fail='return')
if 'label_api' in g.rpc.caps and g.coin != 'BCH':
return g.rpc.setlabel(coinaddr,lbl,on_fail='return')
else:
# NOTE: this works because importaddress() removes the old account before
# associating the new account with the address.
# RPC args: addr,label,rescan[=true],p2sh[=none]
return g.rpch.importaddress(coinaddr,lbl,False,on_fail='return')
return g.rpc.importaddress(coinaddr,lbl,False,on_fail='return')

# returns on failure
@write_mode
Expand Down Expand Up @@ -885,8 +885,8 @@ def __init__(self,minconf,quiet):

def create_data(self):
# 0: unconfirmed, 1: below minconf, 2: confirmed, 3: spendable (privkey in wallet)
lbl_id = ('account','label')['label_api' in g.rpch.caps]
for d in g.rpch.listunspent(0):
lbl_id = ('account','label')['label_api' in g.rpc.caps]
for d in g.rpc.listunspent(0):
lbl = get_tw_label(d[lbl_id])
if lbl:
if lbl.mmid.type == 'mmgen':
Expand Down

0 comments on commit 78a199c

Please sign in to comment.