Skip to content

Instantly share code, notes, and snippets.

@vincenzopalazzo
Created September 6, 2019 21:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vincenzopalazzo/1f1245ab200ed59a0604dee134f42863 to your computer and use it in GitHub Desktop.
Save vincenzopalazzo/1f1245ab200ed59a0604dee134f42863 to your computer and use it in GitHub Desktop.
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
Copy link
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