mirror of
https://github.com/aljazceru/lightning.git
synced 2026-01-12 10:34:30 +01:00
bitcoind: remove the chainparams member
We now have a global constant, prefer to use it instead of having two variables with the same utility.
This commit is contained in:
committed by
Christian Decker
parent
fdd69af1f6
commit
f075b87137
@@ -3,6 +3,7 @@
|
||||
#include <common/json_command.h>
|
||||
#include <common/json_helpers.h>
|
||||
#include <common/jsonrpc_errors.h>
|
||||
#include <common/utils.h>
|
||||
#include <common/wallet_tx.h>
|
||||
#include <inttypes.h>
|
||||
#include <wallet/wallet.h>
|
||||
@@ -117,7 +118,7 @@ static struct command_result *check_amount(const struct wallet_tx *wtx,
|
||||
"Cannot afford transaction");
|
||||
}
|
||||
|
||||
if (amount_sat_less(amount, get_chainparams(wtx->cmd->ld)->dust_limit)) {
|
||||
if (amount_sat_less(amount, chainparams->dust_limit)) {
|
||||
return command_fail(wtx->cmd, FUND_OUTPUT_IS_DUST,
|
||||
"Output %s would be dust",
|
||||
type_to_string(tmpctx, struct amount_sat,
|
||||
@@ -177,7 +178,7 @@ struct command_result *wtx_select_utxos(struct wallet_tx *tx,
|
||||
if (res)
|
||||
return res;
|
||||
|
||||
if (amount_sat_less(tx->change, get_chainparams(tx->cmd->ld)->dust_limit)) {
|
||||
if (amount_sat_less(tx->change, chainparams->dust_limit)) {
|
||||
tx->change = AMOUNT_SAT(0);
|
||||
tx->change_key_index = 0;
|
||||
} else {
|
||||
@@ -224,7 +225,7 @@ struct command_result *wtx_from_utxos(struct wallet_tx *tx,
|
||||
&& !amount_sat_sub(&tx->change, total_amount, tx->amount))
|
||||
fatal("Overflow when computing change");
|
||||
|
||||
if (amount_sat_greater_eq(tx->change, get_chainparams(tx->cmd->ld)->dust_limit)) {
|
||||
if (amount_sat_greater_eq(tx->change, chainparams->dust_limit)) {
|
||||
/* Add the change output's weight */
|
||||
weight += (8 + 1 + out_len) * 4;
|
||||
}
|
||||
|
||||
@@ -42,9 +42,9 @@ static const char **gather_args(const struct bitcoind *bitcoind,
|
||||
const char **args = tal_arr(ctx, const char *, 1);
|
||||
const char *arg;
|
||||
|
||||
args[0] = bitcoind->cli ? bitcoind->cli : bitcoind->chainparams->cli;
|
||||
if (bitcoind->chainparams->cli_args)
|
||||
add_arg(&args, bitcoind->chainparams->cli_args);
|
||||
args[0] = bitcoind->cli ? bitcoind->cli : chainparams->cli;
|
||||
if (chainparams->cli_args)
|
||||
add_arg(&args, chainparams->cli_args);
|
||||
|
||||
if (bitcoind->datadir)
|
||||
add_arg(&args, tal_fmt(args, "-datadir=%s", bitcoind->datadir));
|
||||
@@ -379,7 +379,7 @@ static bool process_estimatefee(struct bitcoin_cli *bcli)
|
||||
* with the minimal fee even if the estimate didn't
|
||||
* work out. This is less disruptive than erring out
|
||||
* all the time. */
|
||||
if (get_chainparams(bcli->bitcoind->ld)->testnet)
|
||||
if (chainparams->testnet)
|
||||
efee->satoshi_per_kw[efee->i] = FEERATE_FLOOR;
|
||||
else
|
||||
efee->satoshi_per_kw[efee->i] = 0;
|
||||
@@ -467,7 +467,7 @@ static bool process_rawblock(struct bitcoin_cli *bcli)
|
||||
struct bitcoin_block *blk,
|
||||
void *arg) = bcli->cb;
|
||||
|
||||
blk = bitcoin_block_from_hex(bcli, bcli->bitcoind->chainparams,
|
||||
blk = bitcoin_block_from_hex(bcli, chainparams,
|
||||
bcli->output, bcli->output_bytes);
|
||||
if (!blk)
|
||||
fatal("%s: bad block '%.*s'?",
|
||||
@@ -986,7 +986,7 @@ static bool extract_numeric_version(struct bitcoin_cli *bcli,
|
||||
static bool process_getclientversion(struct bitcoin_cli *bcli)
|
||||
{
|
||||
u64 version;
|
||||
u64 min_version = bcli->bitcoind->chainparams->cli_min_supported_version;
|
||||
u64 min_version = chainparams->cli_min_supported_version;
|
||||
|
||||
if (!extract_numeric_version(bcli, bcli->output,
|
||||
bcli->output_bytes,
|
||||
@@ -1178,10 +1178,10 @@ static char* check_blockchain_from_bitcoincli(const tal_t *ctx,
|
||||
(int)output_bytes, output);
|
||||
|
||||
if(!json_tok_streq(output, valuetok,
|
||||
bitcoind->chainparams->bip70_name))
|
||||
chainparams->bip70_name))
|
||||
return tal_fmt(ctx, "Error blockchain for bitcoin-cli?"
|
||||
" Should be: %s",
|
||||
bitcoind->chainparams->bip70_name);
|
||||
chainparams->bip70_name);
|
||||
|
||||
is_bitcoind_synced_yet(bitcoind, output, output_bytes, tokens, true);
|
||||
return NULL;
|
||||
@@ -1249,8 +1249,6 @@ struct bitcoind *new_bitcoind(const tal_t *ctx,
|
||||
{
|
||||
struct bitcoind *bitcoind = tal(ctx, struct bitcoind);
|
||||
|
||||
/* Use testnet by default, change later if we want another network */
|
||||
bitcoind->chainparams = chainparams_for_network("testnet");
|
||||
bitcoind->cli = NULL;
|
||||
bitcoind->datadir = NULL;
|
||||
bitcoind->ld = ld;
|
||||
|
||||
@@ -46,9 +46,6 @@ struct bitcoind {
|
||||
/* Pending requests (high and low prio). */
|
||||
struct list_head pending[BITCOIND_NUM_PRIO];
|
||||
|
||||
/* What network are we on? */
|
||||
const struct chainparams *chainparams;
|
||||
|
||||
/* If non-zero, time we first hit a bitcoind error. */
|
||||
unsigned int error_count;
|
||||
struct timemono first_error_time;
|
||||
|
||||
@@ -746,7 +746,6 @@ static void have_new_block(struct bitcoind *bitcoind UNUSED,
|
||||
struct bitcoin_block *blk,
|
||||
struct chain_topology *topo)
|
||||
{
|
||||
const struct chainparams *chainparams = get_chainparams(topo->ld);
|
||||
/* Annotate all transactions with the chainparams */
|
||||
for (size_t i=0; i<tal_count(blk->tx); i++)
|
||||
blk->tx[i]->chainparams = chainparams;
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include <ccan/tal/str/str.h>
|
||||
#include <common/json_command.h>
|
||||
#include <common/jsonrpc_errors.h>
|
||||
#include <common/utils.h>
|
||||
#include <common/wire_error.h>
|
||||
#include <connectd/gen_connect_wire.h>
|
||||
#include <errno.h>
|
||||
@@ -234,7 +235,7 @@ struct channel *new_channel(struct peer *peer, u64 dbid,
|
||||
channel->msat_to_us_min = msat_to_us_min;
|
||||
channel->msat_to_us_max = msat_to_us_max;
|
||||
channel->last_tx = tal_steal(channel, last_tx);
|
||||
channel->last_tx->chainparams = get_chainparams(peer->ld);
|
||||
channel->last_tx->chainparams = chainparams;
|
||||
channel->last_tx_type = TX_UNKNOWN;
|
||||
channel->last_sig = *last_sig;
|
||||
channel->last_htlc_sigs = tal_steal(channel, last_htlc_sigs);
|
||||
|
||||
@@ -108,7 +108,7 @@ static void peer_received_closing_signature(struct channel *channel,
|
||||
tal_hex(msg, msg));
|
||||
return;
|
||||
}
|
||||
tx->chainparams = get_chainparams(channel->peer->ld);
|
||||
tx->chainparams = chainparams;
|
||||
|
||||
/* FIXME: Make sure signature is correct! */
|
||||
if (better_closing_fee(ld, channel, tx)) {
|
||||
|
||||
@@ -105,7 +105,7 @@ void hsm_init(struct lightningd *ld)
|
||||
|
||||
ld->hsm_fd = fds[0];
|
||||
if (!wire_sync_write(ld->hsm_fd, towire_hsm_init(tmpctx,
|
||||
&ld->topology->bitcoind->chainparams->bip32_key_version,
|
||||
&chainparams->bip32_key_version,
|
||||
chainparams,
|
||||
ld->config.keypass,
|
||||
IFDEV(ld->dev_force_privkey, NULL),
|
||||
|
||||
@@ -301,7 +301,7 @@ static struct command_result *parse_fallback(struct command *cmd,
|
||||
|
||||
fallback_parse
|
||||
= json_to_address_scriptpubkey(cmd,
|
||||
get_chainparams(cmd->ld),
|
||||
chainparams,
|
||||
buffer, fallback,
|
||||
fallback_script);
|
||||
if (fallback_parse == ADDRESS_PARSE_UNRECOGNIZED) {
|
||||
@@ -310,7 +310,7 @@ static struct command_result *parse_fallback(struct command *cmd,
|
||||
} else if (fallback_parse == ADDRESS_PARSE_WRONG_NETWORK) {
|
||||
return command_fail(cmd, LIGHTNINGD,
|
||||
"Fallback address does not match our network %s",
|
||||
get_chainparams(cmd->ld)->network_name);
|
||||
chainparams->network_name);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
@@ -683,7 +683,6 @@ static struct command_result *json_invoice(struct command *cmd,
|
||||
u64 *expiry;
|
||||
struct sha256 rhash;
|
||||
bool *exposeprivate;
|
||||
const struct chainparams *chainparams;
|
||||
#if DEVELOPER
|
||||
const jsmntok_t *routes;
|
||||
#endif
|
||||
@@ -720,7 +719,6 @@ static struct command_result *json_invoice(struct command *cmd,
|
||||
strlen(desc_val));
|
||||
}
|
||||
|
||||
chainparams = get_chainparams(cmd->ld);
|
||||
if (msatoshi_val
|
||||
&& amount_msat_greater(*msatoshi_val, chainparams->max_payment)) {
|
||||
return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include <common/node_id.h>
|
||||
#include <common/param.h>
|
||||
#include <common/type_to_string.h>
|
||||
#include <common/utils.h>
|
||||
#include <common/wallet_tx.h>
|
||||
#include <common/wireaddr.h>
|
||||
#include <gossipd/routing.h>
|
||||
@@ -552,7 +553,7 @@ struct command_result *param_bitcoin_address(struct command *cmd,
|
||||
{
|
||||
/* Parse address. */
|
||||
switch (json_to_address_scriptpubkey(cmd,
|
||||
get_chainparams(cmd->ld),
|
||||
chainparams,
|
||||
buffer, tok,
|
||||
scriptpubkey)) {
|
||||
case ADDRESS_PARSE_UNRECOGNIZED:
|
||||
@@ -563,7 +564,7 @@ struct command_result *param_bitcoin_address(struct command *cmd,
|
||||
case ADDRESS_PARSE_WRONG_NETWORK:
|
||||
return command_fail(cmd, LIGHTNINGD,
|
||||
"Destination address is not on network %s",
|
||||
get_chainparams(cmd->ld)->network_name);
|
||||
chainparams->network_name);
|
||||
case ADDRESS_PARSE_SUCCESS:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -475,17 +475,6 @@ static void shutdown_subdaemons(struct lightningd *ld)
|
||||
db_commit_transaction(ld->wallet->db);
|
||||
}
|
||||
|
||||
/*~ Chainparams are the parameters for eg. testnet vs mainnet. This wrapper
|
||||
* saves lots of struggles with our 80-column guideline! */
|
||||
const struct chainparams *get_chainparams(const struct lightningd *ld)
|
||||
{
|
||||
/* "The lightningd is connected to the blockchain."
|
||||
* "The blockchain is connected to the bitcoind API."
|
||||
* "The bitcoind API is connected chain parameters."
|
||||
* -- Worst childhood song ever. */
|
||||
return ld->topology->bitcoind->chainparams;
|
||||
}
|
||||
|
||||
/*~ Our wallet logic needs to know what outputs we might be interested in. We
|
||||
* use BIP32 (a.k.a. "HD wallet") to generate keys from a single seed, so we
|
||||
* keep the maximum-ever-used key index in the db, and add them all to the
|
||||
@@ -665,6 +654,10 @@ int main(int argc, char *argv[])
|
||||
* backtraces when we crash (if supported on this platform). */
|
||||
daemon_setup(argv[0], log_backtrace_print, log_backtrace_exit);
|
||||
|
||||
/*~ We use a global (in common/utils.h) for the chainparams.
|
||||
* We default to testnet for now. */
|
||||
chainparams = chainparams_for_network("testnet");
|
||||
|
||||
/*~ There's always a battle between what a constructor like this
|
||||
* should do, and what should be added later by the caller. In
|
||||
* general, because we use valgrind heavily for testing, we prefer not
|
||||
@@ -673,10 +666,6 @@ int main(int argc, char *argv[])
|
||||
* variables. */
|
||||
ld = new_lightningd(NULL);
|
||||
|
||||
/*~ The global chainparams is needed to init subdaemons, and defaults
|
||||
* to testnet. */
|
||||
chainparams = chainparams_for_network("testnet");
|
||||
|
||||
/* Figure out where our daemons are first. */
|
||||
ld->daemon_dir = find_daemon_dir(ld, argv[0]);
|
||||
if (!ld->daemon_dir)
|
||||
@@ -753,7 +742,7 @@ int main(int argc, char *argv[])
|
||||
/*~ Our default names, eg. for the database file, are not dependent on
|
||||
* the network. Instead, the db knows what chain it belongs to, and we
|
||||
* simple barf here if it's wrong. */
|
||||
if (!wallet_network_check(ld->wallet, get_chainparams(ld)))
|
||||
if (!wallet_network_check(ld->wallet, chainparams))
|
||||
errx(1, "Wallet network check failed.");
|
||||
|
||||
/*~ Initialize the transaction filter with our pubkeys. */
|
||||
|
||||
@@ -251,8 +251,6 @@ struct lightningd {
|
||||
* Use only on carefully tested code! */
|
||||
extern bool tal_oom_ok;
|
||||
|
||||
const struct chainparams *get_chainparams(const struct lightningd *ld);
|
||||
|
||||
/* Check we can run subdaemons, and check their versions */
|
||||
void test_subdaemons(const struct lightningd *ld);
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include <bitcoin/feerate.h>
|
||||
#include <bitcoin/script.h>
|
||||
#include <common/key_derive.h>
|
||||
#include <common/utils.h>
|
||||
#include <errno.h>
|
||||
#include <hsmd/gen_hsm_wire.h>
|
||||
#include <inttypes.h>
|
||||
@@ -187,7 +188,7 @@ static void handle_onchain_broadcast_tx(struct channel *channel, const u8 *msg)
|
||||
channel_internal_error(channel, "Invalid onchain_broadcast_tx");
|
||||
return;
|
||||
}
|
||||
tx->chainparams = get_chainparams(channel->peer->ld);
|
||||
tx->chainparams = chainparams;
|
||||
|
||||
bitcoin_txid(tx, &txid);
|
||||
wallet_transaction_add(w, tx, 0, 0);
|
||||
@@ -457,7 +458,6 @@ enum watch_result onchaind_funding_spent(struct channel *channel,
|
||||
struct pubkey final_key;
|
||||
int hsmfd;
|
||||
u32 feerate;
|
||||
const struct chainparams *chainparams;
|
||||
|
||||
channel_fail_permanent(channel, "Funding transaction spent");
|
||||
|
||||
@@ -531,8 +531,6 @@ enum watch_result onchaind_funding_spent(struct channel *channel,
|
||||
feerate = feerate_floor();
|
||||
}
|
||||
|
||||
chainparams = get_chainparams(channel->peer->ld);
|
||||
|
||||
msg = towire_onchain_init(channel,
|
||||
&channel->their_shachain.chain,
|
||||
chainparams,
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include <common/key_derive.h>
|
||||
#include <common/param.h>
|
||||
#include <common/per_peer_state.h>
|
||||
#include <common/utils.h>
|
||||
#include <common/wallet_tx.h>
|
||||
#include <common/wire_error.h>
|
||||
#include <connectd/gen_connect_wire.h>
|
||||
@@ -301,7 +302,7 @@ static void funding_started_success(struct funding_channel *fc,
|
||||
|
||||
response = json_stream_success(cmd);
|
||||
out = encode_scriptpubkey_to_addr(cmd,
|
||||
get_chainparams(cmd->ld),
|
||||
chainparams,
|
||||
scriptPubkey);
|
||||
if (out) {
|
||||
json_add_string(response, "funding_address", out);
|
||||
@@ -395,7 +396,7 @@ static void opening_funder_finished(struct subd *openingd, const u8 *resp,
|
||||
tal_hex(fc->cmd, resp)));
|
||||
goto cleanup;
|
||||
}
|
||||
remote_commit->chainparams = get_chainparams(openingd->ld);
|
||||
remote_commit->chainparams = chainparams;
|
||||
per_peer_state_set_fds_arr(pps, fds);
|
||||
|
||||
log_debug(ld->log,
|
||||
@@ -488,7 +489,7 @@ static void opening_fundee_finished(struct subd *openingd,
|
||||
goto failed;
|
||||
}
|
||||
|
||||
remote_commit->chainparams = get_chainparams(openingd->ld);
|
||||
remote_commit->chainparams = chainparams;
|
||||
per_peer_state_set_fds_arr(pps, fds);
|
||||
|
||||
/* openingd should never accept them funding channel in this case. */
|
||||
@@ -660,7 +661,7 @@ static void channel_config(struct lightningd *ld,
|
||||
ld->config.min_capacity_sat))
|
||||
fatal("amount_msat overflow for config.min_capacity_sat");
|
||||
/* Substract 2 * dust_limit, so fundchannel with min value is possible */
|
||||
if (!amount_sat_to_msat(&dust_limit, get_chainparams(ld)->dust_limit))
|
||||
if (!amount_sat_to_msat(&dust_limit, chainparams->dust_limit))
|
||||
fatal("amount_msat overflow for dustlimit");
|
||||
if (!amount_msat_sub(min_effective_htlc_capacity,
|
||||
*min_effective_htlc_capacity,
|
||||
@@ -678,7 +679,7 @@ static void channel_config(struct lightningd *ld,
|
||||
* - set `dust_limit_satoshis` to a sufficient value to allow
|
||||
* commitment transactions to propagate through the Bitcoin network.
|
||||
*/
|
||||
ours->dust_limit = get_chainparams(ld)->dust_limit;
|
||||
ours->dust_limit = chainparams->dust_limit;
|
||||
ours->max_htlc_value_in_flight = AMOUNT_MSAT(UINT64_MAX);
|
||||
|
||||
/* Don't care */
|
||||
@@ -1080,7 +1081,7 @@ static struct command_result *json_fund_channel_start(struct command *cmd,
|
||||
u8 *msg = NULL;
|
||||
struct amount_sat max_funding_satoshi, *amount;
|
||||
|
||||
max_funding_satoshi = get_chainparams(cmd->ld)->max_funding;
|
||||
max_funding_satoshi = chainparams->max_funding;
|
||||
fc->cmd = cmd;
|
||||
fc->cancels = tal_arr(fc, struct command *, 0);
|
||||
fc->uc = NULL;
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
#include <bitcoin/chainparams.h>
|
||||
#include <ccan/array_size/array_size.h>
|
||||
#include <ccan/err/err.h>
|
||||
#include <ccan/json_escape/json_escape.h>
|
||||
@@ -18,6 +17,7 @@
|
||||
#include <common/jsonrpc_errors.h>
|
||||
#include <common/memleak.h>
|
||||
#include <common/param.h>
|
||||
#include <common/utils.h>
|
||||
#include <common/version.h>
|
||||
#include <common/wireaddr.h>
|
||||
#include <errno.h>
|
||||
@@ -256,9 +256,7 @@ static char *opt_set_network(const char *arg, struct lightningd *ld)
|
||||
|
||||
/* Set the global chainparams instance */
|
||||
chainparams = chainparams_for_network(arg);
|
||||
|
||||
ld->topology->bitcoind->chainparams = chainparams;
|
||||
if (!ld->topology->bitcoind->chainparams)
|
||||
if (!chainparams)
|
||||
return tal_fmt(NULL, "Unknown network name '%s'", arg);
|
||||
return NULL;
|
||||
}
|
||||
@@ -281,7 +279,7 @@ static char *opt_set_mainnet(struct lightningd *ld)
|
||||
static void opt_show_network(char buf[OPT_SHOW_LEN],
|
||||
const struct lightningd *ld)
|
||||
{
|
||||
snprintf(buf, OPT_SHOW_LEN, "%s", get_chainparams(ld)->network_name);
|
||||
snprintf(buf, OPT_SHOW_LEN, "%s", chainparams->network_name);
|
||||
}
|
||||
|
||||
static char *opt_set_rgb(const char *arg, struct lightningd *ld)
|
||||
@@ -692,14 +690,14 @@ static void check_config(struct lightningd *ld)
|
||||
|
||||
static void setup_default_config(struct lightningd *ld)
|
||||
{
|
||||
if (get_chainparams(ld)->testnet)
|
||||
if (chainparams->testnet)
|
||||
ld->config = testnet_config;
|
||||
else
|
||||
ld->config = mainnet_config;
|
||||
|
||||
/* Set default PID file name to be per-network */
|
||||
tal_free(ld->pidfile);
|
||||
ld->pidfile = tal_fmt(ld, "lightningd-%s.pid", get_chainparams(ld)->network_name);
|
||||
ld->pidfile = tal_fmt(ld, "lightningd-%s.pid", chainparams->network_name);
|
||||
}
|
||||
|
||||
|
||||
@@ -830,8 +828,7 @@ static char *opt_lightningd_usage(struct lightningd *ld)
|
||||
* to display before it exits */
|
||||
setup_default_config(ld);
|
||||
char *extra = tal_fmt(NULL, "\nA bitcoin lightning daemon (default "
|
||||
"values shown for network: %s).",
|
||||
get_chainparams(ld)->network_name);
|
||||
"values shown for network: %s).", chainparams->network_name);
|
||||
opt_usage_and_exit(extra);
|
||||
tal_free(extra);
|
||||
return NULL;
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
#include <common/per_peer_state.h>
|
||||
#include <common/status.h>
|
||||
#include <common/timeout.h>
|
||||
#include <common/utils.h>
|
||||
#include <common/version.h>
|
||||
#include <common/wire_error.h>
|
||||
#include <connectd/gen_connect_wire.h>
|
||||
@@ -623,7 +624,7 @@ static void json_add_channel(struct lightningd *ld,
|
||||
|
||||
if (channel->shutdown_scriptpubkey[LOCAL]) {
|
||||
char *addr = encode_scriptpubkey_to_addr(tmpctx,
|
||||
get_chainparams(ld),
|
||||
chainparams,
|
||||
channel->shutdown_scriptpubkey[LOCAL]);
|
||||
if (addr)
|
||||
json_add_string(response, "close_to_addr", addr);
|
||||
@@ -729,8 +730,8 @@ static void json_add_channel(struct lightningd *ld,
|
||||
spendable = AMOUNT_MSAT(0);
|
||||
|
||||
/* We can't offer an HTLC over the max payment threshold either. */
|
||||
if (amount_msat_greater(spendable, get_chainparams(ld)->max_payment))
|
||||
spendable = get_chainparams(ld)->max_payment;
|
||||
if (amount_msat_greater(spendable, chainparams->max_payment))
|
||||
spendable = chainparams->max_payment;
|
||||
|
||||
json_add_amount_msat_compat(response, spendable,
|
||||
"spendable_msatoshi", "spendable_msat");
|
||||
@@ -1271,7 +1272,7 @@ static struct command_result *param_tok_dest_or_timeout(
|
||||
if (!json_to_number(buffer, tok, &timeout)) {
|
||||
enum address_parse_result res;
|
||||
res = json_to_address_scriptpubkey(cmd,
|
||||
get_chainparams(cmd->ld),
|
||||
chainparams,
|
||||
buffer, tok,
|
||||
&script);
|
||||
if (res == ADDRESS_PARSE_UNRECOGNIZED)
|
||||
@@ -1280,7 +1281,7 @@ static struct command_result *param_tok_dest_or_timeout(
|
||||
else if (res == ADDRESS_PARSE_WRONG_NETWORK)
|
||||
return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
|
||||
"Destination address is not on network %s",
|
||||
get_chainparams(cmd->ld)->network_name);
|
||||
chainparams->network_name);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
@@ -1355,7 +1356,7 @@ static struct command_result *json_close(struct command *cmd,
|
||||
if (secondtok) {
|
||||
enum address_parse_result res;
|
||||
res = json_to_address_scriptpubkey(cmd,
|
||||
get_chainparams(cmd->ld),
|
||||
chainparams,
|
||||
buffer, secondtok,
|
||||
&close_to_script);
|
||||
if (res == ADDRESS_PARSE_UNRECOGNIZED)
|
||||
@@ -1364,7 +1365,7 @@ static struct command_result *json_close(struct command *cmd,
|
||||
else if (res == ADDRESS_PARSE_WRONG_NETWORK)
|
||||
return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
|
||||
"Destination address is not on network %s",
|
||||
get_chainparams(cmd->ld)->network_name);
|
||||
chainparams->network_name);
|
||||
}
|
||||
}
|
||||
} else if (secondtok) {
|
||||
@@ -1378,7 +1379,7 @@ static struct command_result *json_close(struct command *cmd,
|
||||
enum address_parse_result res;
|
||||
|
||||
res = json_to_address_scriptpubkey(cmd,
|
||||
get_chainparams(cmd->ld),
|
||||
chainparams,
|
||||
buffer, secondtok,
|
||||
&close_to_script);
|
||||
if (res == ADDRESS_PARSE_UNRECOGNIZED)
|
||||
@@ -1387,7 +1388,7 @@ static struct command_result *json_close(struct command *cmd,
|
||||
else if (res == ADDRESS_PARSE_WRONG_NETWORK)
|
||||
return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
|
||||
"Destination address is not on network %s",
|
||||
get_chainparams(cmd->ld)->network_name);
|
||||
chainparams->network_name);
|
||||
}
|
||||
} else
|
||||
old_style = false;
|
||||
@@ -1722,7 +1723,7 @@ static struct command_result *json_getinfo(struct command *cmd,
|
||||
}
|
||||
json_add_string(response, "version", version());
|
||||
json_add_num(response, "blockheight", get_block_height(cmd->ld->topology));
|
||||
json_add_string(response, "network", get_chainparams(cmd->ld)->network_name);
|
||||
json_add_string(response, "network", chainparams->network_name);
|
||||
json_add_amount_msat_compat(response,
|
||||
wallet_total_forward_fees(cmd->ld->wallet),
|
||||
"msatoshi_fees_collected",
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include <common/param.h>
|
||||
#include <common/sphinx.h>
|
||||
#include <common/timeout.h>
|
||||
#include <common/utils.h>
|
||||
#include <gossipd/gen_gossip_wire.h>
|
||||
#include <lightningd/chaintopology.h>
|
||||
#include <lightningd/htlc_end.h>
|
||||
@@ -527,7 +528,7 @@ static void forward_htlc(struct htlc_in *hin,
|
||||
}
|
||||
|
||||
if (amount_msat_greater(amt_to_forward,
|
||||
get_chainparams(ld)->max_payment)) {
|
||||
chainparams->max_payment)) {
|
||||
/* ENOWUMBO! */
|
||||
failcode = WIRE_REQUIRED_CHANNEL_FEATURE_MISSING;
|
||||
goto fail;
|
||||
@@ -1549,7 +1550,7 @@ void peer_got_commitsig(struct channel *channel, const u8 *msg)
|
||||
tal_hex(channel, msg));
|
||||
return;
|
||||
}
|
||||
tx->chainparams = get_chainparams(ld);
|
||||
tx->chainparams = chainparams;
|
||||
|
||||
log_debug(channel->log,
|
||||
"got commitsig %"PRIu64
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include <ccan/opt/opt.h>
|
||||
#include <ccan/tal/str/str.h>
|
||||
#include <ccan/utf8/utf8.h>
|
||||
#include <common/utils.h>
|
||||
#include <common/version.h>
|
||||
#include <lightningd/json.h>
|
||||
#include <lightningd/notification.h>
|
||||
@@ -1050,9 +1051,7 @@ plugin_populate_init_request(struct plugin *plugin, struct jsonrpc_request *req)
|
||||
json_add_string(req->stream, "lightning-dir", ld->config_dir);
|
||||
json_add_string(req->stream, "rpc-file", ld->rpc_filename);
|
||||
json_add_bool(req->stream, "startup", plugin->plugins->startup);
|
||||
json_add_string(
|
||||
req->stream, "network",
|
||||
plugin->plugins->ld->topology->bitcoind->chainparams->network_name);
|
||||
json_add_string(req->stream, "network", chainparams->network_name);
|
||||
json_object_end(req->stream);
|
||||
}
|
||||
|
||||
|
||||
@@ -120,9 +120,6 @@ void fulfill_htlc(struct htlc_in *hin UNNEEDED, const struct preimage *preimage
|
||||
/* Generated stub for get_block_height */
|
||||
u32 get_block_height(const struct chain_topology *topo UNNEEDED)
|
||||
{ fprintf(stderr, "get_block_height called!\n"); abort(); }
|
||||
/* Generated stub for get_chainparams */
|
||||
const struct chainparams *get_chainparams(const struct lightningd *ld UNNEEDED)
|
||||
{ fprintf(stderr, "get_chainparams called!\n"); abort(); }
|
||||
/* Generated stub for get_log_level */
|
||||
enum log_level get_log_level(struct log_book *lr UNNEEDED)
|
||||
{ fprintf(stderr, "get_log_level called!\n"); abort(); }
|
||||
|
||||
@@ -30,9 +30,6 @@ const char *feerate_name(enum feerate feerate UNNEEDED)
|
||||
/* Generated stub for fmt_wireaddr_without_port */
|
||||
char *fmt_wireaddr_without_port(const tal_t *ctx UNNEEDED, const struct wireaddr *a UNNEEDED)
|
||||
{ fprintf(stderr, "fmt_wireaddr_without_port called!\n"); abort(); }
|
||||
/* Generated stub for get_chainparams */
|
||||
const struct chainparams *get_chainparams(const struct lightningd *ld UNNEEDED)
|
||||
{ fprintf(stderr, "get_chainparams called!\n"); abort(); }
|
||||
/* Generated stub for json_to_pubkey */
|
||||
bool json_to_pubkey(const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED,
|
||||
struct pubkey *pubkey UNNEEDED)
|
||||
|
||||
@@ -29,11 +29,6 @@ static void db_log_(struct log *log UNUSED, enum log_level level UNUSED, bool ca
|
||||
|
||||
bool deprecated_apis = true;
|
||||
|
||||
const struct chainparams *get_chainparams(const struct lightningd *ld)
|
||||
{
|
||||
return chainparams_for_network("bitcoin");
|
||||
}
|
||||
|
||||
/* AUTOGENERATED MOCKS START */
|
||||
/* Generated stub for bigsize_get */
|
||||
size_t bigsize_get(const u8 *p UNNEEDED, size_t max UNNEEDED, bigsize_t *val UNNEEDED)
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include <common/key_derive.h>
|
||||
#include <common/param.h>
|
||||
#include <common/status.h>
|
||||
#include <common/utils.h>
|
||||
#include <common/utxo.h>
|
||||
#include <common/wallet_tx.h>
|
||||
#include <common/withdraw_tx.h>
|
||||
@@ -320,7 +321,7 @@ static struct command_result *json_prepare_tx(struct command *cmd,
|
||||
"{destination: amount}");
|
||||
|
||||
res = json_to_address_scriptpubkey(cmd,
|
||||
get_chainparams(cmd->ld),
|
||||
chainparams,
|
||||
buffer, &t[1],
|
||||
&destination);
|
||||
if (res == ADDRESS_PARSE_UNRECOGNIZED)
|
||||
@@ -329,7 +330,7 @@ static struct command_result *json_prepare_tx(struct command *cmd,
|
||||
else if (res == ADDRESS_PARSE_WRONG_NETWORK)
|
||||
return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
|
||||
"Destination address is not on network %s",
|
||||
get_chainparams(cmd->ld)->network_name);
|
||||
chainparams->network_name);
|
||||
|
||||
amount = tal(tmpctx, struct amount_sat);
|
||||
if (!json_to_sat_or_all(buffer, &t[2], amount))
|
||||
@@ -392,7 +393,7 @@ create_tx:
|
||||
return command_fail(cmd, LIGHTNINGD, "Keys generation failure");
|
||||
} else
|
||||
changekey = NULL;
|
||||
(*utx)->tx = withdraw_tx(*utx, get_chainparams(cmd->ld),
|
||||
(*utx)->tx = withdraw_tx(*utx, chainparams,
|
||||
(*utx)->wtx->utxos, (*utx)->outputs,
|
||||
changekey, (*utx)->wtx->change,
|
||||
cmd->ld->wallet->bip32_base,
|
||||
@@ -586,10 +587,10 @@ encode_pubkey_to_addr(const tal_t *ctx,
|
||||
sha256(&h, redeemscript, tal_count(redeemscript));
|
||||
ripemd160(&h160, h.u.u8, sizeof(h));
|
||||
out = p2sh_to_base58(ctx,
|
||||
get_chainparams(ld),
|
||||
chainparams,
|
||||
&h160);
|
||||
} else {
|
||||
hrp = get_chainparams(ld)->bip173_name;
|
||||
hrp = chainparams->bip173_name;
|
||||
|
||||
/* out buffer is 73 + strlen(human readable part),
|
||||
* see common/bech32.h*/
|
||||
@@ -814,7 +815,7 @@ static struct command_result *json_listfunds(struct command *cmd,
|
||||
json_add_string(response, "address", out);
|
||||
} else if (utxos[i]->scriptPubkey != NULL) {
|
||||
out = encode_scriptpubkey_to_addr(
|
||||
cmd, get_chainparams(cmd->ld),
|
||||
cmd, chainparams,
|
||||
utxos[i]->scriptPubkey);
|
||||
if (out)
|
||||
json_add_string(response, "address", out);
|
||||
|
||||
Reference in New Issue
Block a user