2011-10-04 01:10:03 +02:00
|
|
|
from jsonrpc import ServiceProxy
|
|
|
|
import sys
|
|
|
|
import string
|
|
|
|
|
|
|
|
# ===== BEGIN USER SETTINGS =====
|
|
|
|
# if you do not set these you will be prompted for a password for every command
|
|
|
|
rpcuser = ""
|
|
|
|
rpcpass = ""
|
|
|
|
# ====== END USER SETTINGS ======
|
|
|
|
|
|
|
|
|
|
|
|
if rpcpass == "":
|
2014-02-26 17:40:18 +01:00
|
|
|
access = ServiceProxy("http://127.0.0.1:8332")
|
2011-10-04 01:10:03 +02:00
|
|
|
else:
|
2014-02-26 17:40:18 +01:00
|
|
|
access = ServiceProxy("http://"+rpcuser+":"+rpcpass+"@127.0.0.1:8332")
|
2011-10-04 01:10:03 +02:00
|
|
|
cmd = sys.argv[1].lower()
|
|
|
|
|
|
|
|
if cmd == "backupwallet":
|
2014-02-26 17:40:18 +01:00
|
|
|
try:
|
|
|
|
path = raw_input("Enter destination path/filename: ")
|
|
|
|
print access.backupwallet(path)
|
|
|
|
except:
|
|
|
|
print "\n---An error occurred---\n"
|
2011-10-04 01:10:03 +02:00
|
|
|
|
|
|
|
elif cmd == "getaccount":
|
2014-02-26 17:40:18 +01:00
|
|
|
try:
|
|
|
|
addr = raw_input("Enter a Bitcoin address: ")
|
|
|
|
print access.getaccount(addr)
|
|
|
|
except:
|
|
|
|
print "\n---An error occurred---\n"
|
2011-10-04 01:10:03 +02:00
|
|
|
|
|
|
|
elif cmd == "getaccountaddress":
|
2014-02-26 17:40:18 +01:00
|
|
|
try:
|
|
|
|
acct = raw_input("Enter an account name: ")
|
|
|
|
print access.getaccountaddress(acct)
|
|
|
|
except:
|
|
|
|
print "\n---An error occurred---\n"
|
2011-10-04 01:10:03 +02:00
|
|
|
|
|
|
|
elif cmd == "getaddressesbyaccount":
|
2014-02-26 17:40:18 +01:00
|
|
|
try:
|
|
|
|
acct = raw_input("Enter an account name: ")
|
|
|
|
print access.getaddressesbyaccount(acct)
|
|
|
|
except:
|
|
|
|
print "\n---An error occurred---\n"
|
2011-10-04 01:10:03 +02:00
|
|
|
|
|
|
|
elif cmd == "getbalance":
|
2014-02-26 17:40:18 +01:00
|
|
|
try:
|
|
|
|
acct = raw_input("Enter an account (optional): ")
|
|
|
|
mc = raw_input("Minimum confirmations (optional): ")
|
|
|
|
try:
|
|
|
|
print access.getbalance(acct, mc)
|
|
|
|
except:
|
|
|
|
print access.getbalance()
|
|
|
|
except:
|
|
|
|
print "\n---An error occurred---\n"
|
2011-10-04 01:10:03 +02:00
|
|
|
|
|
|
|
elif cmd == "getblockbycount":
|
2014-02-26 17:40:18 +01:00
|
|
|
try:
|
|
|
|
height = raw_input("Height: ")
|
|
|
|
print access.getblockbycount(height)
|
|
|
|
except:
|
|
|
|
print "\n---An error occurred---\n"
|
2011-10-04 01:10:03 +02:00
|
|
|
|
|
|
|
elif cmd == "getblockcount":
|
2014-02-26 17:40:18 +01:00
|
|
|
try:
|
|
|
|
print access.getblockcount()
|
|
|
|
except:
|
|
|
|
print "\n---An error occurred---\n"
|
2011-10-04 01:10:03 +02:00
|
|
|
|
|
|
|
elif cmd == "getblocknumber":
|
2014-02-26 17:40:18 +01:00
|
|
|
try:
|
|
|
|
print access.getblocknumber()
|
|
|
|
except:
|
|
|
|
print "\n---An error occurred---\n"
|
2011-10-04 01:10:03 +02:00
|
|
|
|
|
|
|
elif cmd == "getconnectioncount":
|
2014-02-26 17:40:18 +01:00
|
|
|
try:
|
|
|
|
print access.getconnectioncount()
|
|
|
|
except:
|
|
|
|
print "\n---An error occurred---\n"
|
2011-10-04 01:10:03 +02:00
|
|
|
|
|
|
|
elif cmd == "getdifficulty":
|
2014-02-26 17:40:18 +01:00
|
|
|
try:
|
|
|
|
print access.getdifficulty()
|
|
|
|
except:
|
|
|
|
print "\n---An error occurred---\n"
|
2011-10-04 01:10:03 +02:00
|
|
|
|
|
|
|
elif cmd == "getgenerate":
|
2014-02-26 17:40:18 +01:00
|
|
|
try:
|
|
|
|
print access.getgenerate()
|
|
|
|
except:
|
|
|
|
print "\n---An error occurred---\n"
|
2011-10-04 01:10:03 +02:00
|
|
|
|
|
|
|
elif cmd == "gethashespersec":
|
2014-02-26 17:40:18 +01:00
|
|
|
try:
|
|
|
|
print access.gethashespersec()
|
|
|
|
except:
|
|
|
|
print "\n---An error occurred---\n"
|
2011-10-04 01:10:03 +02:00
|
|
|
|
|
|
|
elif cmd == "getinfo":
|
2014-02-26 17:40:18 +01:00
|
|
|
try:
|
|
|
|
print access.getinfo()
|
|
|
|
except:
|
|
|
|
print "\n---An error occurred---\n"
|
2011-10-04 01:10:03 +02:00
|
|
|
|
|
|
|
elif cmd == "getnewaddress":
|
2014-02-26 17:40:18 +01:00
|
|
|
try:
|
|
|
|
acct = raw_input("Enter an account name: ")
|
|
|
|
try:
|
|
|
|
print access.getnewaddress(acct)
|
|
|
|
except:
|
|
|
|
print access.getnewaddress()
|
|
|
|
except:
|
|
|
|
print "\n---An error occurred---\n"
|
2011-10-04 01:10:03 +02:00
|
|
|
|
|
|
|
elif cmd == "getreceivedbyaccount":
|
2014-02-26 17:40:18 +01:00
|
|
|
try:
|
|
|
|
acct = raw_input("Enter an account (optional): ")
|
|
|
|
mc = raw_input("Minimum confirmations (optional): ")
|
|
|
|
try:
|
|
|
|
print access.getreceivedbyaccount(acct, mc)
|
|
|
|
except:
|
|
|
|
print access.getreceivedbyaccount()
|
|
|
|
except:
|
|
|
|
print "\n---An error occurred---\n"
|
2011-10-04 01:10:03 +02:00
|
|
|
|
|
|
|
elif cmd == "getreceivedbyaddress":
|
2014-02-26 17:40:18 +01:00
|
|
|
try:
|
|
|
|
addr = raw_input("Enter a Bitcoin address (optional): ")
|
|
|
|
mc = raw_input("Minimum confirmations (optional): ")
|
|
|
|
try:
|
|
|
|
print access.getreceivedbyaddress(addr, mc)
|
|
|
|
except:
|
|
|
|
print access.getreceivedbyaddress()
|
|
|
|
except:
|
|
|
|
print "\n---An error occurred---\n"
|
2011-10-04 01:10:03 +02:00
|
|
|
|
|
|
|
elif cmd == "gettransaction":
|
2014-02-26 17:40:18 +01:00
|
|
|
try:
|
|
|
|
txid = raw_input("Enter a transaction ID: ")
|
|
|
|
print access.gettransaction(txid)
|
|
|
|
except:
|
|
|
|
print "\n---An error occurred---\n"
|
2011-10-04 01:10:03 +02:00
|
|
|
|
|
|
|
elif cmd == "getwork":
|
2014-02-26 17:40:18 +01:00
|
|
|
try:
|
|
|
|
data = raw_input("Data (optional): ")
|
|
|
|
try:
|
|
|
|
print access.gettransaction(data)
|
|
|
|
except:
|
|
|
|
print access.gettransaction()
|
|
|
|
except:
|
|
|
|
print "\n---An error occurred---\n"
|
2011-10-04 01:10:03 +02:00
|
|
|
|
|
|
|
elif cmd == "help":
|
2014-02-26 17:40:18 +01:00
|
|
|
try:
|
|
|
|
cmd = raw_input("Command (optional): ")
|
|
|
|
try:
|
|
|
|
print access.help(cmd)
|
|
|
|
except:
|
|
|
|
print access.help()
|
|
|
|
except:
|
|
|
|
print "\n---An error occurred---\n"
|
2011-10-04 01:10:03 +02:00
|
|
|
|
|
|
|
elif cmd == "listaccounts":
|
2014-02-26 17:40:18 +01:00
|
|
|
try:
|
|
|
|
mc = raw_input("Minimum confirmations (optional): ")
|
|
|
|
try:
|
|
|
|
print access.listaccounts(mc)
|
|
|
|
except:
|
|
|
|
print access.listaccounts()
|
|
|
|
except:
|
|
|
|
print "\n---An error occurred---\n"
|
2011-10-04 01:10:03 +02:00
|
|
|
|
|
|
|
elif cmd == "listreceivedbyaccount":
|
2014-02-26 17:40:18 +01:00
|
|
|
try:
|
|
|
|
mc = raw_input("Minimum confirmations (optional): ")
|
|
|
|
incemp = raw_input("Include empty? (true/false, optional): ")
|
|
|
|
try:
|
|
|
|
print access.listreceivedbyaccount(mc, incemp)
|
|
|
|
except:
|
|
|
|
print access.listreceivedbyaccount()
|
|
|
|
except:
|
|
|
|
print "\n---An error occurred---\n"
|
2011-10-04 01:10:03 +02:00
|
|
|
|
|
|
|
elif cmd == "listreceivedbyaddress":
|
2014-02-26 17:40:18 +01:00
|
|
|
try:
|
|
|
|
mc = raw_input("Minimum confirmations (optional): ")
|
|
|
|
incemp = raw_input("Include empty? (true/false, optional): ")
|
|
|
|
try:
|
|
|
|
print access.listreceivedbyaddress(mc, incemp)
|
|
|
|
except:
|
|
|
|
print access.listreceivedbyaddress()
|
|
|
|
except:
|
|
|
|
print "\n---An error occurred---\n"
|
2011-10-04 01:10:03 +02:00
|
|
|
|
|
|
|
elif cmd == "listtransactions":
|
2014-02-26 17:40:18 +01:00
|
|
|
try:
|
|
|
|
acct = raw_input("Account (optional): ")
|
|
|
|
count = raw_input("Number of transactions (optional): ")
|
|
|
|
frm = raw_input("Skip (optional):")
|
|
|
|
try:
|
|
|
|
print access.listtransactions(acct, count, frm)
|
|
|
|
except:
|
|
|
|
print access.listtransactions()
|
|
|
|
except:
|
|
|
|
print "\n---An error occurred---\n"
|
2011-10-04 01:10:03 +02:00
|
|
|
|
|
|
|
elif cmd == "move":
|
2014-02-26 17:40:18 +01:00
|
|
|
try:
|
|
|
|
frm = raw_input("From: ")
|
|
|
|
to = raw_input("To: ")
|
|
|
|
amt = raw_input("Amount:")
|
|
|
|
mc = raw_input("Minimum confirmations (optional): ")
|
|
|
|
comment = raw_input("Comment (optional): ")
|
|
|
|
try:
|
|
|
|
print access.move(frm, to, amt, mc, comment)
|
|
|
|
except:
|
|
|
|
print access.move(frm, to, amt)
|
|
|
|
except:
|
|
|
|
print "\n---An error occurred---\n"
|
2011-10-04 01:10:03 +02:00
|
|
|
|
|
|
|
elif cmd == "sendfrom":
|
2014-02-26 17:40:18 +01:00
|
|
|
try:
|
|
|
|
frm = raw_input("From: ")
|
|
|
|
to = raw_input("To: ")
|
|
|
|
amt = raw_input("Amount:")
|
|
|
|
mc = raw_input("Minimum confirmations (optional): ")
|
|
|
|
comment = raw_input("Comment (optional): ")
|
|
|
|
commentto = raw_input("Comment-to (optional): ")
|
|
|
|
try:
|
|
|
|
print access.sendfrom(frm, to, amt, mc, comment, commentto)
|
|
|
|
except:
|
|
|
|
print access.sendfrom(frm, to, amt)
|
|
|
|
except:
|
|
|
|
print "\n---An error occurred---\n"
|
2011-10-04 01:10:03 +02:00
|
|
|
|
|
|
|
elif cmd == "sendmany":
|
2014-02-26 17:40:18 +01:00
|
|
|
try:
|
|
|
|
frm = raw_input("From: ")
|
|
|
|
to = raw_input("To (in format address1:amount1,address2:amount2,...): ")
|
|
|
|
mc = raw_input("Minimum confirmations (optional): ")
|
|
|
|
comment = raw_input("Comment (optional): ")
|
|
|
|
try:
|
|
|
|
print access.sendmany(frm,to,mc,comment)
|
|
|
|
except:
|
|
|
|
print access.sendmany(frm,to)
|
|
|
|
except:
|
|
|
|
print "\n---An error occurred---\n"
|
2011-10-04 01:10:03 +02:00
|
|
|
|
|
|
|
elif cmd == "sendtoaddress":
|
2014-02-26 17:40:18 +01:00
|
|
|
try:
|
|
|
|
to = raw_input("To (in format address1:amount1,address2:amount2,...): ")
|
|
|
|
amt = raw_input("Amount:")
|
|
|
|
comment = raw_input("Comment (optional): ")
|
|
|
|
commentto = raw_input("Comment-to (optional): ")
|
|
|
|
try:
|
|
|
|
print access.sendtoaddress(to,amt,comment,commentto)
|
|
|
|
except:
|
|
|
|
print access.sendtoaddress(to,amt)
|
|
|
|
except:
|
|
|
|
print "\n---An error occurred---\n"
|
2011-10-04 01:10:03 +02:00
|
|
|
|
|
|
|
elif cmd == "setaccount":
|
2014-02-26 17:40:18 +01:00
|
|
|
try:
|
|
|
|
addr = raw_input("Address: ")
|
|
|
|
acct = raw_input("Account:")
|
|
|
|
print access.setaccount(addr,acct)
|
|
|
|
except:
|
|
|
|
print "\n---An error occurred---\n"
|
2011-10-04 01:10:03 +02:00
|
|
|
|
|
|
|
elif cmd == "setgenerate":
|
2014-02-26 17:40:18 +01:00
|
|
|
try:
|
|
|
|
gen= raw_input("Generate? (true/false): ")
|
|
|
|
cpus = raw_input("Max processors/cores (-1 for unlimited, optional):")
|
|
|
|
try:
|
|
|
|
print access.setgenerate(gen, cpus)
|
|
|
|
except:
|
|
|
|
print access.setgenerate(gen)
|
|
|
|
except:
|
|
|
|
print "\n---An error occurred---\n"
|
2011-10-04 01:10:03 +02:00
|
|
|
|
|
|
|
elif cmd == "settxfee":
|
2014-02-26 17:40:18 +01:00
|
|
|
try:
|
|
|
|
amt = raw_input("Amount:")
|
|
|
|
print access.settxfee(amt)
|
|
|
|
except:
|
|
|
|
print "\n---An error occurred---\n"
|
2011-10-04 01:10:03 +02:00
|
|
|
|
|
|
|
elif cmd == "stop":
|
2014-02-26 17:40:18 +01:00
|
|
|
try:
|
|
|
|
print access.stop()
|
|
|
|
except:
|
|
|
|
print "\n---An error occurred---\n"
|
2011-10-04 01:10:03 +02:00
|
|
|
|
|
|
|
elif cmd == "validateaddress":
|
2014-02-26 17:40:18 +01:00
|
|
|
try:
|
|
|
|
addr = raw_input("Address: ")
|
|
|
|
print access.validateaddress(addr)
|
|
|
|
except:
|
|
|
|
print "\n---An error occurred---\n"
|
2011-10-04 01:10:03 +02:00
|
|
|
|
|
|
|
elif cmd == "walletpassphrase":
|
2014-02-26 17:40:18 +01:00
|
|
|
try:
|
|
|
|
pwd = raw_input("Enter wallet passphrase: ")
|
|
|
|
access.walletpassphrase(pwd, 60)
|
|
|
|
print "\n---Wallet unlocked---\n"
|
|
|
|
except:
|
|
|
|
print "\n---An error occurred---\n"
|
2011-10-04 01:10:03 +02:00
|
|
|
|
|
|
|
elif cmd == "walletpassphrasechange":
|
2014-02-26 17:40:18 +01:00
|
|
|
try:
|
|
|
|
pwd = raw_input("Enter old wallet passphrase: ")
|
|
|
|
pwd2 = raw_input("Enter new wallet passphrase: ")
|
|
|
|
access.walletpassphrasechange(pwd, pwd2)
|
|
|
|
print
|
|
|
|
print "\n---Passphrase changed---\n"
|
|
|
|
except:
|
|
|
|
print
|
|
|
|
print "\n---An error occurred---\n"
|
|
|
|
print
|
2011-10-04 01:10:03 +02:00
|
|
|
|
|
|
|
else:
|
2014-02-26 17:40:18 +01:00
|
|
|
print "Command not found or not supported"
|