electrum

Electrum Bitcoin wallet
git clone https://git.parazyd.org/electrum
Log | Files | Refs | Submodules

commit 31e967050217cfe48514f18612347ed9f612bc53
parent 8a5221ed9a98fead578aa1ba54f808f6df334e54
Author: ThomasV <thomasv@electrum.org>
Date:   Mon, 16 May 2016 14:39:01 +0200

make 'createrawtx' command not require wallet

Diffstat:
Melectrum | 4----
Mlib/commands.py | 46++++++++++++++++++++++++++++------------------
2 files changed, 28 insertions(+), 22 deletions(-)

diff --git a/electrum b/electrum @@ -184,10 +184,6 @@ def init_cmdline(config_options): if cmdname in ['payto', 'paytomany'] and config.get('broadcast'): 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 storage = WalletStorage(config.get_wallet_path()) diff --git a/lib/commands.py b/lib/commands.py @@ -192,25 +192,35 @@ class Commands: r = self.network.synchronous_get(('blockchain.utxo.get_address', [txid, pos])) return {'address': r} - @command('wp') - def createrawtx(self, inputs, outputs, unsigned=False): - """Create a transaction from json inputs. The syntax is similar to bitcoind.""" - coins = self.wallet.get_spendable_coins(exclude_frozen = False) - tx_inputs = [] - for i in inputs: - prevout_hash = i['txid'] - prevout_n = i['vout'] - for c in coins: - if c['prevout_hash'] == prevout_hash and c['prevout_n'] == prevout_n: - self.wallet.add_input_info(c) - tx_inputs.append(c) - break + @command('') + def createrawtx(self, inputs, outputs): + """Create a transaction from json inputs. Inputs must have a redeemPubkey. Outputs must be a list of (address, value). + """ + keypairs = {} + for txin in inputs: + if txin.get('output'): + prevout_hash, prevout_n = txin['output'].split(':') + txin['prevout_n'] = int(prevout_n) + txin['prevout_hash'] = prevout_hash else: - raise BaseException('Transaction output not in wallet', prevout_hash+":%d"%prevout_n) - outputs = map(lambda x: (TYPE_ADDRESS, x[0], int(COIN*x[1])), outputs.items()) - tx = Transaction.from_io(tx_inputs, outputs) - if not unsigned: - self.wallet.sign_transaction(tx, self._password) + raise BaseException('Output point missing', txin) + if txin.get('redeemPubkey'): + pubkey = txin['redeemPubkey'] + txin['pubkeys'] = [pubkey] + 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() @command('wp')