'unfreeze':'',
'prioritize':'',
'unprioritize':'',
+ 'createmultisig':'similar to bitcoind\'s command',
+ 'createrawtransaction':'similar to bitcoind\'s command',
+ 'decoderawtransaction':'similar to bitcoind\'s command',
+ 'signrawtransaction':'similar to bitcoind\'s command',
}
'importprivkey', 'seed',
'deseed','reseed',
'freeze','unfreeze',
- 'prioritize','unprioritize']
+ 'prioritize','unprioritize',
+ 'createmultisig', 'createrawtransaction', 'decoderawtransaction', 'signrawtransaction'
+ ]
-protected_commands = ['payto', 'password', 'mktx', 'signtx', 'seed', 'importprivkey','signmessage' ]
+protected_commands = ['payto', 'password', 'mktx', 'signtx', 'seed', 'importprivkey','signmessage', 'signrawtransaction' ]
# get password routine
def prompt_password(prompt, confirm=True):
print_msg(wallet.unprioritize(addr))
+ elif cmd == 'createmultisig':
+ import ast
+ from lib.bitcoin import *
+ num = int(args[1])
+ pubkeys = ast.literal_eval(args[2])
+ assert isinstance(pubkeys,list)
+ s = multisig_script(pubkeys, num)
+ out = { "address": hash_160_to_bc_address(hash_160(s.decode('hex')), 5), "redeemScript":s }
+ print_json(out)
+
+
+ elif cmd == 'createrawtransaction':
+ import ast
+ inputs = ast.literal_eval(args[1])
+ outputs = ast.literal_eval(args[2])
+ inputs = map(lambda x: (None, None, x["txid"], x["vout"], None, None), inputs)
+ outputs = map(lambda x: (x[0],int(x[1]*1e8)), outputs.items())
+ tx = raw_tx(inputs, outputs, for_sig = -1) # for_sig=-1 means do not sign
+ print_msg( tx )
+
+
+ elif cmd == 'decoderawtransaction':
+ print_json( bitcoin.deserialize(args[1]) )
+
+
+ elif cmd == 'signrawtransaction':
+ d = bitcoin.deserialize(args[1])
+ txouts = args[2] if len(args)>2 else []
+ private_keys = args[3] if len(args)>3 else []
+
+ inputs = []
+ for x in d['inputs']:
+ txid = x["prevout_hash"]
+ nout = x["prevout_n"]
+ tx = wallet.transactions.get(txid)
+ txout = tx['outputs'][nout]
+ addr = txout['address']
+ v = txout['value']
+ inputs.append( (addr, v, txid, nout, txout['raw_output_script'], [(None,None)] ) )
+
+ outputs = map(lambda x: (x['address'],x['value']), d['outputs'])
+ print_error("inputs", inputs)
+ print_error("outputs", outputs)
+
+ tx = wallet.signed_tx( inputs, outputs, password )
+ print_msg(tx)
+
+
if cmd not in offline_commands and not options.offline:
synchronizer.stop()
s += var_int( len(tx_filter(script))/2 ) # script length
s += script # script
s += int_to_hex(0,4) # lock time
- if for_sig is not None: s += int_to_hex(1, 4) # hash type
+ if for_sig is not None and for_sig != 1: s += int_to_hex(1, 4) # hash type
return tx_filter(s)
-def multisig_script(public_keys):
+def deserialize(raw_tx):
+ import deserialize
+ vds = deserialize.BCDataStream()
+ vds.write(raw_tx.decode('hex'))
+ return deserialize.parse_Transaction(vds)
+
+
+def multisig_script(public_keys, num=None):
# supports only "2 of 2", and "2 of 3" transactions
n = len(public_keys)
- s = '52'
+
+ if num is None:
+ num = n
+
+ assert num <= n and n <= 3 and n >= 2
+
+ if num==2:
+ s = '52'
+ elif num == 3:
+ s = '53'
+ else:
+ raise
+
for k in public_keys:
s += var_int(len(k)/2)
s += k