本文整理汇总了Python中bitcoinrpc.authproxy.AuthServiceProxy方法的典型用法代码示例。如果您正苦于以下问题:Python authproxy.AuthServiceProxy方法的具体用法?Python authproxy.AuthServiceProxy怎么用?Python authproxy.AuthServiceProxy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bitcoinrpc.authproxy
的用法示例。
在下文中一共展示了authproxy.AuthServiceProxy方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __call__
# 需要导入模块: from bitcoinrpc import authproxy [as 别名]
# 或者: from bitcoinrpc.authproxy import AuthServiceProxy [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
示例2: do_RPC
# 需要导入模块: from bitcoinrpc import authproxy [as 别名]
# 或者: from bitcoinrpc.authproxy import AuthServiceProxy [as 别名]
def do_RPC(env, send_resp):
_,args,cur = urlparse.parse_qs(env['QUERY_STRING']), env['PATH_INFO'].split('/')[2:], sqc.dbpool.get().cursor()
send_resp('200 OK', [('Content-Type', 'application/json')])
result = []
if args[0] == "getblockcount":
result = json.dumps(sqc.cfg['block'])
elif args[0] == "getinfo":
result = json.dumps( { 'blocks':sqc.cfg['block'], 'difficulty':bits2diff(gethdr(sqc.cfg['block'], sqc.cfg, 'bits')) } )
elif args[0] == "getdifficulty":
result = json.dumps( bits2diff(gethdr(sqc.cfg['block'], sqc.cfg, 'bits')) )
else:
rpc = AuthServiceProxy(sqc.cfg['rpc'])
if args[0] == "getblock":
result = json.dumps( rpc.getblock(args[1]), cls=btcEncoder )
elif args[0] == "getblockhash":
result = json.dumps( rpc.getblockhash(int(args[1])) )
elif args[0] == "getrawtransaction":
result = json.dumps( rpc.getrawtransaction(args[1], 1), cls=btcEncoder )
elif args[0] == "gettxout":
result = json.dumps( rpcTxOut(cur, args[1], args[2]) )
elif args[0] == "getmempoolinfo":
result = json.dumps( rpc.getmempoolinfo(), cls=btcEncoder )
elif args[0] == "getrawmempool":
result = json.dumps( rpc.getrawmempool(False), cls=btcEncoder )
return result
示例3: reload_address
# 需要导入模块: from bitcoinrpc import authproxy [as 别名]
# 或者: from bitcoinrpc.authproxy import AuthServiceProxy [as 别名]
def reload_address(address, rpconn, times=1):
"""
Sends necessary satoshis for a Spool transaction.
Args:
address (str): receiving bitcoin address
rpconn (AuthServiceProxy): JSON-RPC connection
(:class:`AuthServiceProxy` instance) to bitcoin regtest
"""
from spool import Spool
for _ in range(times):
rpconn.sendtoaddress(address, Spool.FEE/100000000)
rpconn.sendtoaddress(address, Spool.TOKEN/100000000)
rpconn.sendtoaddress(address, Spool.TOKEN/100000000)
rpconn.sendtoaddress(address, Spool.TOKEN/100000000)
rpconn.generate(1)
示例4: __init__
# 需要导入模块: from bitcoinrpc import authproxy [as 别名]
# 或者: from bitcoinrpc.authproxy import AuthServiceProxy [as 别名]
def __init__(self, uri):
logger.debug("init")
self.uri = uri
self.rpc = AuthServiceProxy(uri,timeout=600)
# wait for rpc to be ready
last_exc = None
for _ in xrange(30):
try:
logger.info("best block: %s"%self.rpc.getbestblockhash())
#logger.info("block count: %s" % self.rpc.getblockcount())
break
except Exception, e:
last_exc = e
logger.info("trying to connect ...")
time.sleep(2)
示例5: query_transactions
# 需要导入模块: from bitcoinrpc import authproxy [as 别名]
# 或者: from bitcoinrpc.authproxy import AuthServiceProxy [as 别名]
def query_transactions(ticker=None):
if not ticker:
for c in Currency.objects.all():
query_transactions.delay(c.ticker)
return
currency = Currency.objects.select_for_update().get(ticker=ticker)
coin = AuthServiceProxy(currency.api_url)
current_block = coin.getblockcount()
block_hash = coin.getblockhash(currency.last_block)
transactions = coin.listsinceblock(block_hash)['transactions']
for tx in transactions:
if tx['category'] not in ('receive', 'generate', 'immature'):
continue
process_deposite_transaction(tx, ticker)
currency.last_block = current_block
currency.save()
for tx in Transaction.objects.filter(processed=False, currency=currency):
query_transaction(ticker, tx.txid)
示例6: __init__
# 需要导入模块: from bitcoinrpc import authproxy [as 别名]
# 或者: from bitcoinrpc.authproxy import AuthServiceProxy [as 别名]
def __init__(self, conf_dir=None, rpcuser=None, rpcpassword=None, rpcport=None, rpchost='127.0.0.1', network="main"):
if rpcport is None:
rpcport = {'main':8332,'test':18332,'stn':9332, 'regtest':18332}[network]
if conf_dir is None:
if platform.system() == 'Darwin':
conf_dir = os.path.expanduser('~/Library/Application Support/Bitcoin/')
elif platform.system() == 'Windows':
conf_dir = os.path.join(os.environ['APPDATA'], 'Bitcoin')
else:
conf_dir = os.path.expanduser('~/.bitcoin')
if network == 'regtest':
conf_dir = os.path.join(conf_dir, 'regtest')
if network == 'test':
conf_dir = os.path.join(conf_dir, 'testnet3')
elif network == 'stn':
conf_dir = os.path.join(conf_dir, 'stn')
if rpcuser is None:
cookie = os.path.join(conf_dir, '.cookie')
with open(cookie) as f:
rpcuserpass = f.read()
# Use cookie if no rpcuser specified
if rpcuser:
uri = "http://{}:{}@{}:{}".format(rpcuser, rpcpassword, rpchost, rpcport)
else:
uri = "http://{}@{}:{}".format(rpcuserpass, rpchost, rpcport)
self.network = network
self.conf_dir = conf_dir
self.uri = uri
self.rpc = AuthServiceProxy(self.uri)
self.rpcport = rpcport
self.rpchost = rpchost
self.network = network
rpcnet = self.rpc.getblockchaininfo()['chain']
if rpcnet != network:
raise ValueError("rpc server is on '%s' network, you passed '%s'" % (rpcnet, network))
示例7: rpc_connect
# 需要导入模块: from bitcoinrpc import authproxy [as 别名]
# 或者: from bitcoinrpc.authproxy import AuthServiceProxy [as 别名]
def rpc_connect(self):
return AuthServiceProxy(self.uri)
示例8: rpc_reconnect
# 需要导入模块: from bitcoinrpc import authproxy [as 别名]
# 或者: from bitcoinrpc.authproxy import AuthServiceProxy [as 别名]
def rpc_reconnect(self):
self.rpc = AuthServiceProxy(self.uri)
示例9: __init__
# 需要导入模块: from bitcoinrpc import authproxy [as 别名]
# 或者: from bitcoinrpc.authproxy import AuthServiceProxy [as 别名]
def __init__(self, window,
on_connection_initiated_callback=None,
on_connection_failed_callback=None,
on_connection_successful_callback=None,
on_connection_disconnected_callback=None):
WndUtils.__init__(self, app_config=None)
self.app_config = None
self.db_intf = None
self.connections = []
self.cur_conn_index = 0
self.cur_conn_def: Optional['DashNetworkConnectionCfg'] = None
# below is the connection with which particular RPC call has started; if connection is switched because of
# problems with some nodes, switching stops if we close round and return to the starting connection
self.starting_conn = None
self.masternodes = [] # cached list of all masternodes (Masternode object)
self.masternodes_by_ident = {}
self.masternodes_by_ip_port = {}
self.protx_by_mn_ident: Dict[str, Dict] = {}
self.ssh = None
self.window = window
self.active = False
self.rpc_url = None
self.proxy = None
self.http_conn = None # HTTPConnection object passed to the AuthServiceProxy (for convinient connection reset)
self.on_connection_initiated_callback = on_connection_initiated_callback
self.on_connection_failed_callback = on_connection_failed_callback
self.on_connection_successful_callback = on_connection_successful_callback
self.on_connection_disconnected_callback = on_connection_disconnected_callback
self.last_error_message = None
self.mempool_txes:Dict[str, Dict] = {}
self.http_lock = threading.RLock()
示例10: connect_to_bitcoin_server
# 需要导入模块: from bitcoinrpc import authproxy [as 别名]
# 或者: from bitcoinrpc.authproxy import AuthServiceProxy [as 别名]
def connect_to_bitcoin_server(server_ip, port,user, password):
global access
access = AuthServiceProxy("http://%s:%s@%s:%s"%(user,password,server_ip,port))
pass
示例11: rpc_connection
# 需要导入模块: from bitcoinrpc import authproxy [as 别名]
# 或者: from bitcoinrpc.authproxy import AuthServiceProxy [as 别名]
def rpc_connection(self):
return AuthServiceProxy("http://{0}:{1}@{2}:{3}".format(*self.creds))
示例12: connect
# 需要导入模块: from bitcoinrpc import authproxy [as 别名]
# 或者: from bitcoinrpc.authproxy import AuthServiceProxy [as 别名]
def connect(self):
protocol = 'http'
if ('rpcssl' in self.config and
bool(self.config['rpcssl']) and
int(self.config['rpcssl']) > 0):
protocol = 'https'
serverURL = protocol + '://' + self.config['rpcuser'] + ':' + \
self.config['rpcpassword'] + '@' + str(self.config['rpcbind']) + \
':' + str(self.config['rpcport'])
self._proxy = AuthServiceProxy(serverURL)
return self._proxy
示例13: bitcoind_agrees_on_transaction_validity
# 需要导入模块: from bitcoinrpc import authproxy [as 别名]
# 或者: from bitcoinrpc.authproxy import AuthServiceProxy [as 别名]
def bitcoind_agrees_on_transaction_validity(bitcoind_url, tx):
connection = AuthServiceProxy(bitcoind_url)
tx.check_unspents()
unknown_tx_outs = [unspent_to_bitcoind_dict(tx_in, tx_out)
for tx_in, tx_out in zip(tx.txs_in, tx.unspents)]
signed = connection.signrawtransaction(tx.as_hex(), unknown_tx_outs, [])
is_ok = [tx.is_signature_ok(idx) for idx in range(len(tx.txs_in))]
return all(is_ok) == signed.get("complete")
示例14: apiRPC
# 需要导入模块: from bitcoinrpc import authproxy [as 别名]
# 或者: from bitcoinrpc.authproxy import AuthServiceProxy [as 别名]
def apiRPC(cmd, arg):
rpc = AuthServiceProxy(sqc.cfg['rpc'])
if cmd =='estimatefee':
return int(rpc.estimatefee(int(arg)))
if cmd =='send':
return rpc.sendrawtransaction(arg)
示例15: rpconn
# 需要导入模块: from bitcoinrpc import authproxy [as 别名]
# 或者: from bitcoinrpc.authproxy import AuthServiceProxy [as 别名]
def rpconn(rpcurl):
return AuthServiceProxy(rpcurl)