Skip to content

Commit

Permalink
ERROR: this is wrong
Browse files Browse the repository at this point in the history
  • Loading branch information
jtimon committed Oct 24, 2019
1 parent 866b56f commit 1692d4f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
10 changes: 10 additions & 0 deletions plugins/libplugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <common/daemon.h>
#include <common/utils.h>
#include <errno.h>
#include <lightningd/lightningd.h>
#include <poll.h>
#include <plugins/libplugin.h>
#include <stdarg.h>
Expand Down Expand Up @@ -53,6 +54,8 @@ static struct plugin_conn rpc_conn;
struct command {
u64 id;
const char *methodname;
/* The global state */
struct lightningd *ld;
bool usage_only;
};

Expand Down Expand Up @@ -87,6 +90,13 @@ struct command_result *command_param_failed(void)
return &complete;
}

/*~ Chainparams are the parameters for eg. testnet vs mainnet. This wrapper
* saves lots of struggles with our 80-column guideline! */
const struct chainparams *get_chainparams2(const struct command *cmd)
{
return cmd->ld->topology->bitcoind->chainparams;
}

struct json_out *json_out_obj(const tal_t *ctx,
const char *fieldname,
const char *str)
Expand Down
2 changes: 2 additions & 0 deletions plugins/libplugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ struct plugin_command {
const jsmntok_t *params);
};

const struct chainparams *get_chainparams2(const struct command *cmd);

/* Create an array of these, one for each --option you support. */
struct plugin_option {
const char *name;
Expand Down
5 changes: 5 additions & 0 deletions plugins/pay.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <bitcoin/chainparams.h>
#include <ccan/array_size/array_size.h>
#include <ccan/cast/cast.h>
#include <ccan/intmap/intmap.h>
Expand Down Expand Up @@ -1043,6 +1044,10 @@ static struct command_result *json_pay(struct command *cmd,
"Invalid bolt11: %s", fail);
}

if (b11->chain != get_chainparams2(cmd)) {
return command_fail(cmd, PAY_ROUTE_NOT_FOUND, "Invoice is for another network %s", b11->chain->network_name);
}

if (time_now().ts.tv_sec > b11->timestamp + b11->expiry) {
return command_fail(cmd, PAY_INVOICE_EXPIRED, "Invoice expired");
}
Expand Down

0 comments on commit 1692d4f

Please sign in to comment.