Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Simple Console gui bitcoin core for calculate the amount on the an address
from bitcoinrpc.authproxy import AuthServiceProxy, JSONRPCException
rpc_user = 'vincent'
rpc_password = 'vincent'
rpc_connection = AuthServiceProxy("http://%s:%s@127.0.0.1:18332"%(rpc_user, rpc_password))
def createNewAddress():
address = rpc_connection.getnewaddress();
print("The new address is: ", address)
def getListTransaction(address):
if address is None:
raise Exception("Address null")
listTransactions = rpc_connection.listunspent();
transactionAddress = [];
for transaction in listTransactions:
if address == transaction['address']:
transactionAddress.append(transaction)
print("The transacrions address: ", transactionAddress)
print("The num transaction address is", len(transactionAddress))
for tx in transactionAddress:
print("----------- Transaction -----------")
print("Address: ", tx['address'])
print("Label: ", tx['label'])
print("Ammount: ", tx['amount'])
def getAmmount(address):
if address is None:
raise Exception("Address null")
listTransactions = rpc_connection.listunspent();
ammountAddress = float(format(0, '.8f'));
for transaction in listTransactions:
if address == transaction['address']:
ammountAddress = format(float(ammountAddress) + float(transaction['amount']), '.8f');
print("Address: ", address, "have ", ammountAddress)
def consoleGUI():
print(" _____________ BITCOIN CORE CONSOLE ___________")
print("| 1. Create new Address |")
print("| 2. List Transaction address |")
print("| 3. Get ammount |")
print("| 0. Exit |")
print("|______________________________________________|")
print("\nChoise -> ");
num = input();
if (int(num) < 0) and (int(num) > 3):
print("Error choise")
return None
else:
return num
if __name__ == '__main__':
while True:
value = consoleGUI();
if int(value) == 0:
print("Bey")
break
if int(value) == 1:
createNewAddress()
if int(value) == 2:
print("Insert address -> ")
addr = input()
getListTransaction(addr)
if int(value) == 3:
print("Insert address -> ")
addr = input()
getAmmount(addr)
@vincenzopalazzo

This comment has been minimized.

Copy link
Owner Author

vincenzopalazzo commented Sep 6, 2019

The code use python3 and this library

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.