|
1 | 1 | /* Simple tool to route gossip from a peer. */ |
| 2 | +#include <bitcoin/block.h> |
| 3 | +#include <bitcoin/chainparams.h> |
2 | 4 | #include <ccan/array_size/array_size.h> |
3 | 5 | #include <ccan/err/err.h> |
4 | 6 | #include <ccan/io/io.h> |
@@ -81,6 +83,22 @@ enum dev_disconnect dev_disconnect(int pkt_type) |
81 | 83 | } |
82 | 84 | #endif |
83 | 85 |
|
| 86 | +static char *opt_set_network(const char *arg, void *unused) |
| 87 | +{ |
| 88 | + assert(arg != NULL); |
| 89 | + |
| 90 | + /* Set the global chainparams instance */ |
| 91 | + chainparams = chainparams_for_network(arg); |
| 92 | + if (!chainparams) |
| 93 | + return tal_fmt(NULL, "Unknown network name '%s'", arg); |
| 94 | + return NULL; |
| 95 | +} |
| 96 | + |
| 97 | +static void opt_show_network(char buf[OPT_SHOW_LEN], const void *unused) |
| 98 | +{ |
| 99 | + snprintf(buf, OPT_SHOW_LEN, "%s", chainparams->network_name); |
| 100 | +} |
| 101 | + |
84 | 102 | void peer_failed_connection_lost(void) |
85 | 103 | { |
86 | 104 | exit(0); |
@@ -137,11 +155,19 @@ static struct io_plan *handshake_success(struct io_conn *conn, |
137 | 155 | OPTIONAL_FEATURE(OPT_INITIAL_ROUTING_SYNC)); |
138 | 156 |
|
139 | 157 | if (!no_init) { |
140 | | - msg = towire_init(NULL, NULL, features, NULL); |
| 158 | + struct tlv_init_tlvs *tlvs = NULL; |
| 159 | + if (chainparams) { |
| 160 | + tlvs = tlv_init_tlvs_new(NULL); |
| 161 | + tlvs->networks = tal(tlvs, struct tlv_init_tlvs_networks); |
| 162 | + tlvs->networks->chains = tal_arr(tlvs->networks, struct bitcoin_blkid, 1); |
| 163 | + tlvs->networks->chains[0] = chainparams->genesis_blockhash; |
| 164 | + } |
| 165 | + msg = towire_init(NULL, NULL, features, tlvs); |
141 | 166 |
|
142 | 167 | sync_crypto_write(pps, take(msg)); |
143 | 168 | /* Ignore their init message. */ |
144 | 169 | tal_free(sync_crypto_read(NULL, pps)); |
| 170 | + tal_free(tlvs); |
145 | 171 | } |
146 | 172 |
|
147 | 173 | if (stream_stdin) |
@@ -254,6 +280,10 @@ int main(int argc, char *argv[]) |
254 | 280 | "Print out messages in hex"); |
255 | 281 | opt_register_arg("--features=<hex>", opt_set_features, NULL, |
256 | 282 | &features, "Send these features in init"); |
| 283 | + opt_register_arg("--network", opt_set_network, opt_show_network, |
| 284 | + NULL, |
| 285 | + "Select the network parameters (bitcoin, testnet, regtest" |
| 286 | + " liquid, liquid-regtest, litecoin or litecoin-testnet)"); |
257 | 287 | opt_register_noarg("--help|-h", opt_usage_and_exit, |
258 | 288 | "id@addr[:port] [hex-msg-tosend...]\n" |
259 | 289 | "Connect to a lightning peer and relay gossip messages from it", |
|
0 commit comments