Created
May 28, 2013 20:13
-
-
Save anonymous/5665725 to your computer and use it in GitHub Desktop.
Coinlock client
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import datetime | |
import time | |
import sys | |
import pickle | |
import json | |
import jsonrpclib | |
import jsonrpc | |
def register(hour_limit, day_limit, week_limit, safe_address): | |
client_address = bitcoind.getnewaddress() | |
print 'created new address', client_address | |
client_pubkey = bitcoind.validateaddress(client_address)['pubkey'] | |
r = server.register(client_pubkey, AmountToJSON(hour_limit), AmountToJSON(day_limit), AmountToJSON(week_limit), safe_add\ | |
ress) | |
print 'created new multisig address', r[0] | |
def send_from_output(to_address, amount, txid, vout): | |
unspent = {} | |
unspent['txid'] = txid | |
unspent['vout'] = vout | |
destination = {} | |
destination[to_address] = AmountToJSON(amount) | |
transaction = bitcoind.createrawtransaction([unspent], destination) | |
signed = bitcoind.signrawtransaction(transaction) | |
out_txid = bitcoind.sendrawtransaction(signed['hex']) | |
print 'sent transaction', out_txid | |
return out_txid | |
def send(to_address, from_address, client_address, amount): | |
t = server.send_to_address(client_address, from_address, amount) | |
signed = bitcoind.signrawtransaction(t['0']['hex'], t['1'], [bitcoind.dumpprivkey(client_address)]) | |
txid = bitcoind.sendrawtransaction(signed['hex']) | |
print 'sent transaction', txid | |
def print_usage(): | |
print 'new <bitcoind_password> <server_address> <hour_limit> <day_limit> <week_limit> <safe_address> - create new shared\ | |
address' | |
print 'send <bitcoind_password> <server_address> <to> <from> <client_address> <amount> - send bitcoins' | |
print 'balance <server_address> <multisig_address> - display shared address balance and limits' | |
def JSONtoAmount(value): | |
return long(round(value * 1e8)) | |
def AmountToJSON(amount): | |
return float(amount / 1e8) | |
if len(sys.argv) == 8 and sys.argv[1] == "new": | |
bitcoind = jsonrpc.AuthServiceProxy('http://bitcoinrpc:' + sys.argv[2] + '@127.0.0.1:8332') | |
server = jsonrpclib.Server('http://' + sys.argv[3] + ':8080') | |
register(long(sys.argv[4]), long(sys.argv[5]), long(sys.argv[6]), sys.argv[7]) | |
elif len(sys.argv) == 8 and sys.argv[1] == 'send': | |
bitcoind = jsonrpc.AuthServiceProxy('http://bitcoinrpc:' + sys.argv[2] + '@127.0.0.1:8332') | |
server = jsonrpclib.Server('http://' + sys.argv[3] + ':8080') | |
send(sys.argv[4], sys.argv[5], sys.argv[6], long(sys.argv[7])) | |
elif len(sys.argv) == 4 and sys.argv[1] == "balance": | |
server = jsonrpclib.Server('http://' + sys.argv[2] + ':8080') | |
address = sys.argv[3] | |
print 'balance', server.get_balance(address) | |
print 'remaining, hour', server.get_remaining_hour(address) | |
print 'remaining, day', server.get_remaining_day(address) | |
print 'remaining, week', server.get_remaining_week(address) | |
else: | |
print_usage() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment