mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-23 17:14:22 +01:00
Factor out scriptpubkey_from_address function from json_withdraw.
This commit is contained in:
@@ -69,6 +69,29 @@ static void wallet_withdrawal_broadcast(struct bitcoind *bitcoind,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* scriptpubkey_from_address - Determine scriptpubkey from a given address
|
||||||
|
*
|
||||||
|
* This processes the address and returns the equivalent scriptpubkey
|
||||||
|
* for the address. If fail to parse the address, return NULL. If can
|
||||||
|
* parse address, also sets the testnet flag if address is a testnet
|
||||||
|
* address or clears it if mainnet.
|
||||||
|
*/
|
||||||
|
static u8 *scriptpubkey_from_address(const tal_t *cxt, bool *testnet,
|
||||||
|
const char *addr, size_t addrlen)
|
||||||
|
{
|
||||||
|
struct bitcoin_address p2pkh_destination;
|
||||||
|
u8 *script = NULL;
|
||||||
|
|
||||||
|
if (bitcoin_from_base58(testnet, &p2pkh_destination,
|
||||||
|
addr, addrlen)) {
|
||||||
|
script = scriptpubkey_p2pkh(cxt, &p2pkh_destination);
|
||||||
|
}
|
||||||
|
/* TODO Insert other supported addresses here. */
|
||||||
|
|
||||||
|
return script;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* json_withdraw - Entrypoint for the withdrawal flow
|
* json_withdraw - Entrypoint for the withdrawal flow
|
||||||
*
|
*
|
||||||
@@ -91,7 +114,6 @@ static void json_withdraw(struct command *cmd,
|
|||||||
struct pubkey changekey;
|
struct pubkey changekey;
|
||||||
secp256k1_ecdsa_signature *sigs;
|
secp256k1_ecdsa_signature *sigs;
|
||||||
struct bitcoin_tx *tx;
|
struct bitcoin_tx *tx;
|
||||||
struct bitcoin_address p2pkh_destination;
|
|
||||||
|
|
||||||
if (!json_get_params(buffer, params,
|
if (!json_get_params(buffer, params,
|
||||||
"destination", &desttok,
|
"destination", &desttok,
|
||||||
@@ -109,15 +131,11 @@ static void json_withdraw(struct command *cmd,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
withdraw->destination = NULL;
|
/* Parse address. */
|
||||||
|
withdraw->destination
|
||||||
if (bitcoin_from_base58(&testnet, &p2pkh_destination,
|
= scriptpubkey_from_address(withdraw, &testnet,
|
||||||
buffer + desttok->start,
|
buffer + desttok->start,
|
||||||
desttok->end - desttok->start)) {
|
desttok->end - desttok->start);
|
||||||
withdraw->destination
|
|
||||||
= scriptpubkey_p2pkh(withdraw, &p2pkh_destination);
|
|
||||||
}
|
|
||||||
/* TODO Insert other supported addresses here. */
|
|
||||||
|
|
||||||
/* Check that destination address could be understood. */
|
/* Check that destination address could be understood. */
|
||||||
if (!withdraw->destination) {
|
if (!withdraw->destination) {
|
||||||
|
|||||||
Reference in New Issue
Block a user