def main(): parser = argparse.ArgumentParser() parser.add_argument('-r', '--rpc-url', help='Bitcoin node URL, eg http://USERNAME:PASSWORD@HOST:PORT/wallet/WALLET', required=True) parser.add_argument('-n', '--network', help='Bitcoin network (mainnet, testnet)', required=True) parser.add_argument('-a', '--amount', help='Number of new addresses', required=True) args = parser.parse_args() rpc = RPCHost(args.rpc_url) # TODO: add checks res = {} res['network'] = args.network # TODO: add checks res['addresses'] = [] for i in range(1, int(args.amount)): address = rpc.call('getnewaddress') res['addresses'].append(address) print(json.dumps(res, indent=4))
config = configparser.RawConfigParser() config.read('caster.conf') rpcHost = config.get('BTC', 'host') rpcPort = config.get('BTC', 'port') rpcUser = config.get('BTC', 'username') rpcPassword = config.get('BTC', 'password') address = config.get('BTC', 'address') rpcWallet = config.get('BTC', 'wallet') serverURL = 'http://' + rpcUser + ':' + rpcPassword + '@' + rpcHost + ':' + str( rpcPort) + '/wallet/' + rpcWallet #serverURL = 'http://' + rpcUser + ':' + rpcPassword + '@'+rpcHost+':' + str(rpcPort) host = RPCHost(serverURL) res = host.call('createrawtransaction', [], {address: 0.001}) res = host.call('fundrawtransaction', res) res = host.call('signrawtransaction', res['hex']) ser = serial.Serial('/dev/cu.SLAB_USBtoUART', 115200, timeout=1) message = 'p' + res['hex'] + '!' for c in message: print(c.encode('utf8'), end='') ser.write(c.encode('utf8')) sleep(0.001) message = 'S' print(message.encode('utf8')) ser.write(message.encode('utf8'))
ampToken = config.get('AMP', 'token') ampUuid = config.get('AMP', 'assetuuid') gdkMnemonic = config.get('GDK', 'mnemonic') gdkSubaccount = config.get('GDK', 'subaccount') if (len(rpcWallet) > 0): serverURL = 'http://' + rpcUser + ':' + rpcPassword + '@' + rpcHost + ':' + str( rpcPort) + '/wallet/' + rpcWallet else: serverURL = 'http://' + rpcUser + ':' + rpcPassword + '@' + rpcHost + ':' + str( rpcPort) host = RPCHost(serverURL) if (len(rpcPassphrase) > 0): result = host.call('walletpassphrase', rpcPassphrase, 60) @app.route('/.well-known/<path:filename>') def wellKnownRoute(filename): print(app.root_path + '/well-known/' + filename) return send_from_directory(app.root_path + '/well-known/', filename, conditional=True) def stats(): info = host.call('getblockchaininfo') mem = host.call('getmempoolinfo') data = { 'height':
while (True): lock.acquire() try: for dev_id in list(messages): for message_id in list(messages[dev_id]): buff = "" message_complete = True for i in range( int(messages[dev_id][message_id]['message_tot']) + 1): try: buff += messages[dev_id][message_id][format( i, '02x')]['payload'] except: message_complete = False if (message_complete): #print(messages[dev_id]) messages[dev_id].pop(message_id) #print(messages[dev_id]) print(buff) tx = buff.strip() print(tx) res = host.call('decoderawtransaction', tx, True) print(res) res = host.call('sendrawtransaction', tx) print(res) finally: lock.release() time.sleep(10) mqtt_client.close()
from bitcoin_rpc_class import RPCHost # version 0.16 of bitcoind, default port for regtest network is changed from 18332 to 18443 # The port number depends on the one writtein the bitcoin.conf file rpcPort = '18443' # The RPC username and RPC password MUST match the one in your bitcoin.conf file rpcUser = '******' rpcPassword = '******' #Accessing the RPC local server serverURL = 'http://' + 'vinay' + ':' + 'fintech' + '@127.0.0.1:' + rpcPort print(serverURL) #Using the class defined in the bitcoin_rpc_class.py host = RPCHost(serverURL) print('123') hash = host.call('getbestblockhash') print(hash) #block = host.call('getblock', hash) #coin = block['tx'][0] #test = host.call('listreceivedbyaddress', 0, True) #print (test) #from jsonrpc import ServiceProxy #access = ServiceProxy("http://*****:*****@127.0.0.1:18446") #print( access.getinfo()) #access.listreceivedbyaddress(6) #access.sendtoaddress("11yEmxiMso2RsFVfBcCa616npBvGgxiBX", 10)