make 'createrawtx' command not require wallet

This commit is contained in:
ThomasV 2016-05-16 14:39:01 +02:00
parent 8a5221ed9a
commit 31e9670502
2 changed files with 28 additions and 22 deletions

View file

@ -184,10 +184,6 @@ def init_cmdline(config_options):
if cmdname in ['payto', 'paytomany'] and config.get('broadcast'): if cmdname in ['payto', 'paytomany'] and config.get('broadcast'):
cmd.requires_network = True cmd.requires_network = True
if cmdname in ['createrawtx'] and config.get('unsigned'):
cmd.requires_password = False
cmd.requires_wallet = False
# instanciate wallet for command-line # instanciate wallet for command-line
storage = WalletStorage(config.get_wallet_path()) storage = WalletStorage(config.get_wallet_path())

View file

@ -192,25 +192,35 @@ class Commands:
r = self.network.synchronous_get(('blockchain.utxo.get_address', [txid, pos])) r = self.network.synchronous_get(('blockchain.utxo.get_address', [txid, pos]))
return {'address': r} return {'address': r}
@command('wp') @command('')
def createrawtx(self, inputs, outputs, unsigned=False): def createrawtx(self, inputs, outputs):
"""Create a transaction from json inputs. The syntax is similar to bitcoind.""" """Create a transaction from json inputs. Inputs must have a redeemPubkey. Outputs must be a list of (address, value).
coins = self.wallet.get_spendable_coins(exclude_frozen = False) """
tx_inputs = [] keypairs = {}
for i in inputs: for txin in inputs:
prevout_hash = i['txid'] if txin.get('output'):
prevout_n = i['vout'] prevout_hash, prevout_n = txin['output'].split(':')
for c in coins: txin['prevout_n'] = int(prevout_n)
if c['prevout_hash'] == prevout_hash and c['prevout_n'] == prevout_n: txin['prevout_hash'] = prevout_hash
self.wallet.add_input_info(c)
tx_inputs.append(c)
break
else: else:
raise BaseException('Transaction output not in wallet', prevout_hash+":%d"%prevout_n) raise BaseException('Output point missing', txin)
outputs = map(lambda x: (TYPE_ADDRESS, x[0], int(COIN*x[1])), outputs.items()) if txin.get('redeemPubkey'):
tx = Transaction.from_io(tx_inputs, outputs) pubkey = txin['redeemPubkey']
if not unsigned: txin['pubkeys'] = [pubkey]
self.wallet.sign_transaction(tx, self._password) txin['x_pubkeys'] = [pubkey]
txin['signatures'] = [None]
txin['num_sig'] = 1
privkey = txin.get('privkey')
if privkey:
keypairs[pubkey] = privkey
elif txin.get('redeemScript'):
raise BaseException('Not implemented')
else:
raise BaseException('No redeem script')
outputs = map(lambda x: (TYPE_ADDRESS, x[0], int(COIN*Decimal(x[1]))), outputs)
tx = Transaction.from_io(inputs, outputs)
tx.sign(keypairs)
return tx.as_dict() return tx.as_dict()
@command('wp') @command('wp')