Browse Source

Change withdraw_tx to accept scriptpubkey rather than plain address.

ppa-0.6.1
ZmnSCPxj 7 years ago
committed by Rusty Russell
parent
commit
5fd74f9933
  1. 7
      common/withdraw_tx.c
  2. 4
      common/withdraw_tx.h
  3. 4
      hsmd/hsm.c
  4. 11
      wallet/walletrpc.c

7
common/withdraw_tx.c

@ -6,16 +6,16 @@
#include <common/permute_tx.h>
#include <common/utxo.h>
#include <wally_bip32.h>
#include <string.h>
struct bitcoin_tx *withdraw_tx(const tal_t *ctx,
const struct utxo **utxos,
const struct bitcoin_address *destination,
u8 *destination,
const u64 withdraw_amount,
const struct pubkey *changekey,
const u64 changesat,
const struct ext_key *bip32_base)
{
u8 *script;
struct bitcoin_tx *tx =
bitcoin_tx(ctx, tal_count(utxos), changekey ? 2 : 1);
for (size_t i = 0; i < tal_count(utxos); i++) {
@ -30,8 +30,7 @@ struct bitcoin_tx *withdraw_tx(const tal_t *ctx,
}
}
tx->output[0].amount = withdraw_amount;
script = scriptpubkey_p2pkh(ctx, destination);
tx->output[0].script = script;
tx->output[0].script = destination;
if (changesat != 0) {
const void *map[2];

4
common/withdraw_tx.h

@ -16,7 +16,7 @@ struct utxo;
*
* @ctx: context to tal from.
* @utxos: (in/out) tal_arr of UTXO pointers to spend (permuted to match)
* @destination: (in) bitcoin_address to send to.
* @destination: (in) tal_arr of u8, scriptPubKey to send to.
* @amount: (in) satoshis to send to the destination
* @changekey: (in) key to send change to (only used if change_satoshis != 0).
* @changesat: (in) amount to send as change.
@ -24,7 +24,7 @@ struct utxo;
*/
struct bitcoin_tx *withdraw_tx(const tal_t *ctx,
const struct utxo **utxos,
const struct bitcoin_address *destination,
u8 *destination,
const u64 withdraw_amount,
const struct pubkey *changekey,
const u64 changesat,

4
hsmd/hsm.c

@ -606,6 +606,7 @@ static void sign_withdrawal_tx(struct daemon_conn *master, const u8 *msg)
struct bitcoin_tx *tx;
struct ext_key ext;
struct pubkey changekey;
u8 *scriptpubkey;
if (!fromwire_hsm_sign_withdrawal(tmpctx, msg, NULL, &satoshi_out,
&change_out, &change_keyindex,
@ -623,8 +624,9 @@ static void sign_withdrawal_tx(struct daemon_conn *master, const u8 *msg)
}
pubkey_from_der(ext.pub_key, sizeof(ext.pub_key), &changekey);
scriptpubkey = scriptpubkey_p2pkh(tmpctx, &destination);
tx = withdraw_tx(
tmpctx, to_utxoptr_arr(tmpctx, utxos), &destination, satoshi_out,
tmpctx, to_utxoptr_arr(tmpctx, utxos), scriptpubkey, satoshi_out,
&changekey, change_out, NULL);
/* Now generate signatures. */

11
wallet/walletrpc.c

@ -20,7 +20,7 @@
struct withdrawal {
u64 amount, changesatoshi;
struct bitcoin_address destination;
u8 *destination;
const struct utxo **utxos;
u64 change_key_index;
struct command *cmd;
@ -91,6 +91,7 @@ static void json_withdraw(struct command *cmd,
struct pubkey changekey;
secp256k1_ecdsa_signature *sigs;
struct bitcoin_tx *tx;
struct bitcoin_address p2pkh_destination;
if (!json_get_params(buffer, params,
"destination", &desttok,
@ -107,7 +108,7 @@ static void json_withdraw(struct command *cmd,
command_fail(cmd, "Invalid satoshis");
return;
}
if (!bitcoin_from_base58(&testnet, &withdraw->destination,
if (!bitcoin_from_base58(&testnet, &p2pkh_destination,
buffer + desttok->start,
desttok->end - desttok->start)) {
command_fail(cmd, "Could not parse destination address");
@ -147,7 +148,7 @@ static void json_withdraw(struct command *cmd,
withdraw->amount,
withdraw->changesatoshi,
withdraw->change_key_index,
withdraw->destination.addr.u.u8,
p2pkh_destination.addr.u.u8,
utxos);
tal_free(utxos);
@ -169,7 +170,9 @@ static void json_withdraw(struct command *cmd,
}
pubkey_from_der(ext.pub_key, sizeof(ext.pub_key), &changekey);
tx = withdraw_tx(withdraw, withdraw->utxos, &withdraw->destination,
withdraw->destination
= scriptpubkey_p2pkh(withdraw, &p2pkh_destination);
tx = withdraw_tx(withdraw, withdraw->utxos, withdraw->destination,
withdraw->amount, &changekey, withdraw->changesatoshi,
cmd->ld->wallet->bip32_base);

Loading…
Cancel
Save