本文整理汇总了Python中bitcoinrpc.authproxy.JSONRPCException方法的典型用法代码示例。如果您正苦于以下问题:Python authproxy.JSONRPCException方法的具体用法?Python authproxy.JSONRPCException怎么用?Python authproxy.JSONRPCException使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bitcoinrpc.authproxy
的用法示例。
在下文中一共展示了authproxy.JSONRPCException方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: block_height_to_epoch
# 需要导入模块: from bitcoinrpc import authproxy [as 别名]
# 或者: from bitcoinrpc.authproxy import JSONRPCException [as 别名]
def block_height_to_epoch(self, height):
"""
Get the epoch for a given block height, or estimate it if the block hasn't
been mined yet. Call this method instead of `estimate_block_time`.
"""
epoch = -1
try:
bhash = self.rpc_command('getblockhash', height)
block = self.rpc_command('getblock', bhash)
epoch = block['time']
except JSONRPCException as e:
if e.message == 'Block height out of range':
epoch = self.estimate_block_time(height)
else:
print("error: %s" % e)
raise e
return epoch
示例2: __call__
# 需要导入模块: from bitcoinrpc import authproxy [as 别名]
# 或者: from bitcoinrpc.authproxy import JSONRPCException [as 别名]
def __call__(self, *args):
name = self.name
start = time.time()
wait = 3
rpc_lock.release()
rpc_obj = AuthServiceProxy(self.url, None, self.timeout, None)
while True:
try:
result = rpc_obj.__getattr__(name)(*args)
break
except JSONRPCException as e:
if e.code == -5:
return None
except Exception as e: # pylint:disable=broad-except
log( 'RPC Error ' + str(e) + ' (retrying in %d seconds)' % wait )
print "===>", name, args
rpc_obj = AuthServiceProxy(self.url, None, self.timeout, None) # maybe broken, make new connection
if time.time()-start > 300: # max wait time
return None
wait = min(wait*2,60)
time.sleep(wait) # slow down, in case gone away
return result
示例3: test_withdraw_error
# 需要导入模块: from bitcoinrpc import authproxy [as 别名]
# 或者: from bitcoinrpc.authproxy import JSONRPCException [as 别名]
def test_withdraw_error(self):
wallet_before = Wallet.objects.create(currency=self.currency, balance=Decimal('21000000'))
wallet_before.withdraw_to_address('yT58gFY67LNSb1wG9TYsvMx4W4wt93cej9', Decimal('21000000'))
try:
tasks.process_withdraw_transactions('tdsh')
except JSONRPCException:
pass
wallet_after1 = Wallet.objects.get(id=wallet_before.id)
self.assertEqual(wallet_after1.balance, Decimal('0'))
self.assertEqual(wallet_after1.holded, Decimal('21000000'))
wtx = WithdrawTransaction.objects.last()
wallet_after1 = Wallet.objects.get(id=wallet_before.id)
self.assertEqual(wtx.state, wtx.ERROR)
示例4: test_withdraw_error
# 需要导入模块: from bitcoinrpc import authproxy [as 别名]
# 或者: from bitcoinrpc.authproxy import JSONRPCException [as 别名]
def test_withdraw_error(self):
wallet_before = Wallet.objects.create(currency=self.currency, balance=Decimal('21000000'))
wallet_before.withdraw_to_address('mvEnyQ9b9iTA11QMHAwSVtHUrtD4CTfiDB', Decimal('21000000'))
try:
tasks.process_withdraw_transactions('tbtc')
except JSONRPCException:
pass
wallet_after1 = Wallet.objects.get(id=wallet_before.id)
self.assertEqual(wallet_after1.balance, Decimal('0'))
self.assertEqual(wallet_after1.holded, Decimal('21000000'))
wtx = WithdrawTransaction.objects.last()
wallet_after1 = Wallet.objects.get(id=wallet_before.id)
self.assertEqual(wtx.state, wtx.ERROR)
示例5: test_withdraw_error
# 需要导入模块: from bitcoinrpc import authproxy [as 别名]
# 或者: from bitcoinrpc.authproxy import JSONRPCException [as 别名]
def test_withdraw_error(self):
wallet_before = Wallet.objects.create(currency=self.currency, balance=Decimal('21000000'))
wallet_before.withdraw_to_address('tmGa4dwQrtw6ctnijug586PwXt9h8JExguc', Decimal('21000000'))
try:
tasks.process_withdraw_transactions('tzec')
except JSONRPCException:
pass
wallet_after1 = Wallet.objects.get(id=wallet_before.id)
self.assertEqual(wallet_after1.balance, Decimal('0'))
self.assertEqual(wallet_after1.holded, Decimal('21000000'))
wtx = WithdrawTransaction.objects.last()
wallet_after1 = Wallet.objects.get(id=wallet_before.id)
self.assertEqual(wtx.state, wtx.ERROR)
示例6: is_dashd_port_open
# 需要导入模块: from bitcoinrpc import authproxy [as 别名]
# 或者: from bitcoinrpc.authproxy import JSONRPCException [as 别名]
def is_dashd_port_open(dashd):
# test socket open before beginning, display instructive message to MN
# operators if it's not
port_open = False
try:
info = dashd.rpc_command('getgovernanceinfo')
port_open = True
except (socket.error, JSONRPCException) as e:
print("%s" % e)
return port_open
示例7: get_current_masternode_vin
# 需要导入模块: from bitcoinrpc import authproxy [as 别名]
# 或者: from bitcoinrpc.authproxy import JSONRPCException [as 别名]
def get_current_masternode_vin(self):
from dashlib import parse_masternode_status_vin
my_vin = None
try:
status = self.rpc_command('masternode', 'status')
mn_outpoint = status.get('outpoint') or status.get('vin')
my_vin = parse_masternode_status_vin(mn_outpoint)
except JSONRPCException as e:
pass
return my_vin
示例8: submit
# 需要导入模块: from bitcoinrpc import authproxy [as 别名]
# 或者: from bitcoinrpc.authproxy import JSONRPCException [as 别名]
def submit(self, dashd):
# don't attempt to submit a superblock unless a masternode
# note: will probably re-factor this, this has code smell
if (self.only_masternode_can_submit and not dashd.is_masternode()):
print("Not a masternode. Only masternodes may submit these objects")
return
try:
object_hash = dashd.rpc_command(*self.get_submit_command())
printdbg("Submitted: [%s]" % object_hash)
except JSONRPCException as e:
print("Unable to submit: %s" % e.message)
示例9: did_we_vote
# 需要导入模块: from bitcoinrpc import authproxy [as 别名]
# 或者: from bitcoinrpc.authproxy import JSONRPCException [as 别名]
def did_we_vote(output):
from bitcoinrpc.authproxy import JSONRPCException
# sentinel
voted = False
err_msg = ''
try:
detail = output.get('detail').get('dash.conf')
result = detail.get('result')
if 'errorMessage' in detail:
err_msg = detail.get('errorMessage')
except JSONRPCException as e:
result = 'failed'
err_msg = e.message
# success, failed
printdbg("result = [%s]" % result)
if err_msg:
printdbg("err_msg = [%s]" % err_msg)
voted = False
if result == 'success':
voted = True
# in case we spin up a new instance or server, but have already voted
# on the network and network has recorded those votes
m_old = re.match(r'^time between votes is too soon', err_msg)
m_new = re.search(r'Masternode voting too often', err_msg, re.M)
if result == 'failed' and (m_old or m_new):
printdbg("DEBUG: Voting too often, need to sync w/network")
voted = False
return voted
示例10: sendtoaddress
# 需要导入模块: from bitcoinrpc import authproxy [as 别名]
# 或者: from bitcoinrpc.authproxy import JSONRPCException [as 别名]
def sendtoaddress(self, addr, amount):
p = self.dashrpc._proxy
try:
p.sendtoaddress(addr, amount)
except JSONRPCException:
warn("**********************************************************")
warn("INSUFFICIENT FUNDS TO PROCESS REFUND/BOUNCE FOR")
warn(" %s to %s " % (amount, addr))
warn(" wallet balance: %s" % (p.getbalance()))
warn("**********************************************************")
示例11: setUpClass
# 需要导入模块: from bitcoinrpc import authproxy [as 别名]
# 或者: from bitcoinrpc.authproxy import JSONRPCException [as 别名]
def setUpClass(cls):
super().setUpClass()
cls.coin = AuthServiceProxy(URL)
starting = True
while starting:
try:
cls.coin.generate(101)
except JSONRPCException as e:
if e.code != -28:
raise
else:
starting = False
sleep(1)
示例12: ready
# 需要导入模块: from bitcoinrpc import authproxy [as 别名]
# 或者: from bitcoinrpc.authproxy import JSONRPCException [as 别名]
def ready(self):
self.responding = False
self.synchronised = False
self.get_cpu_average()
try:
self._proxy.getinfo()
self.responding = True
except (ValueError, socket.error, httplib.CannotSendRequest) as e:
# print "daemon offline"
pass
except JSONRPCException as e:
# "loading block index"
# print str(e.error['message'])
pass
try:
resp = self._proxy.masternode('debug')
if 'Node just started' not in resp:
self.synchronised = True
except (ValueError, socket.error, httplib.CannotSendRequest) as e:
# print "daemon offline"
pass
except JSONRPCException as e:
resp = str(e.error['message'])
if 'masternode' in resp:
if self.get_cpu_average() < 50:
self.synchronised = True
logmsg = self.responding and 'responding, ' or 'not responding, '
logmsg += self.synchronised and 'synchronised, ' or 'not synchronised, '
logmsg += 'cpu: ' + "{0:.2f}".format(self.get_cpu_average())
info(logmsg)
return (self.responding and self.synchronised)
# doesn't work due to
# name = "%s.%s" % (self.__service_name, name)
# return AuthServiceProxy(self.__service_url, name, connection=self.__conn) # noqa
# def __getattr__(self, attr):
# if getattr(self._proxy, attr):
# getattr(self._proxy, attr)()
# else:
# raise AttributeError