From e76f8633297b3edd4e67e3211f6aedd84a15f2dd Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Wed, 7 Mar 2018 10:36:01 +1030 Subject: [PATCH] txfilter: clean up prototypes. Use const, add TAKES to declaration. Signed-off-by: Rusty Russell --- lightningd/test/run-find_my_path.c | 3 ++- wallet/test/run-wallet.c | 29 +++++++++++++++-------------- wallet/txfilter.c | 9 +++++---- wallet/txfilter.h | 5 +++-- 4 files changed, 25 insertions(+), 21 deletions(-) diff --git a/lightningd/test/run-find_my_path.c b/lightningd/test/run-find_my_path.c index a5b30752d..288db2eb0 100644 --- a/lightningd/test/run-find_my_path.c +++ b/lightningd/test/run-find_my_path.c @@ -84,7 +84,8 @@ void subd_shutdown(struct subd *subd UNNEEDED, unsigned int seconds UNNEEDED) void timer_expired(tal_t *ctx UNNEEDED, struct timer *timer UNNEEDED) { fprintf(stderr, "timer_expired called!\n"); abort(); } /* Generated stub for txfilter_add_derkey */ -void txfilter_add_derkey(struct txfilter *filter UNNEEDED, u8 derkey[PUBKEY_DER_LEN]) +void txfilter_add_derkey(struct txfilter *filter UNNEEDED, + const u8 derkey[PUBKEY_DER_LEN]) { fprintf(stderr, "txfilter_add_derkey called!\n"); abort(); } /* Generated stub for txfilter_new */ struct txfilter *txfilter_new(const tal_t *ctx UNNEEDED) diff --git a/wallet/test/run-wallet.c b/wallet/test/run-wallet.c index ff3e39ed5..3eeef5295 100644 --- a/wallet/test/run-wallet.c +++ b/wallet/test/run-wallet.c @@ -73,8 +73,14 @@ bool derive_basepoints(const struct privkey *seed UNNEEDED, /* Generated stub for extract_channel_id */ bool extract_channel_id(const u8 *in_pkt UNNEEDED, struct channel_id *channel_id UNNEEDED) { fprintf(stderr, "extract_channel_id called!\n"); abort(); } +/* Generated stub for fromwire_gossipctl_peer_disconnect_reply */ +bool fromwire_gossipctl_peer_disconnect_reply(const void *p UNNEEDED) +{ fprintf(stderr, "fromwire_gossipctl_peer_disconnect_reply called!\n"); abort(); } +/* Generated stub for fromwire_gossipctl_peer_disconnect_replyfail */ +bool fromwire_gossipctl_peer_disconnect_replyfail(const void *p UNNEEDED, bool *isconnected UNNEEDED) +{ fprintf(stderr, "fromwire_gossipctl_peer_disconnect_replyfail called!\n"); abort(); } /* Generated stub for fromwire_gossip_getpeers_reply */ -bool fromwire_gossip_getpeers_reply(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, struct pubkey **id UNNEEDED, struct wireaddr **addr UNNEEDED, struct gossip_getnodes_entry ***nodes UNNEEDED) +bool fromwire_gossip_getpeers_reply(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, struct pubkey **id UNNEEDED, struct wireaddr **addr UNNEEDED, struct gossip_getnodes_entry ***nodes UNNEEDED) { fprintf(stderr, "fromwire_gossip_getpeers_reply called!\n"); abort(); } /* Generated stub for fromwire_gossip_peer_connected */ bool fromwire_gossip_peer_connected(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, struct pubkey *id UNNEEDED, struct wireaddr *addr UNNEEDED, struct crypto_state *crypto_state UNNEEDED, u64 *gossip_index UNNEEDED, u8 **gfeatures UNNEEDED, u8 **lfeatures UNNEEDED) @@ -191,6 +197,10 @@ void json_add_short_channel_id(struct json_result *response UNNEEDED, /* Generated stub for json_add_string */ void json_add_string(struct json_result *result UNNEEDED, const char *fieldname UNNEEDED, const char *value UNNEEDED) { fprintf(stderr, "json_add_string called!\n"); abort(); } +/* Generated stub for json_add_string_escape */ +void json_add_string_escape(struct json_result *result UNNEEDED, const char *fieldname UNNEEDED, + const char *value UNNEEDED) +{ fprintf(stderr, "json_add_string_escape called!\n"); abort(); } /* Generated stub for json_add_txid */ void json_add_txid(struct json_result *result UNNEEDED, const char *fieldname UNNEEDED, const struct bitcoin_txid *txid UNNEEDED) @@ -338,6 +348,9 @@ u8 *towire_gossipctl_hand_back_peer(const tal_t *ctx UNNEEDED, const struct pubk /* Generated stub for towire_gossipctl_peer_addrhint */ u8 *towire_gossipctl_peer_addrhint(const tal_t *ctx UNNEEDED, const struct pubkey *id UNNEEDED, const struct wireaddr *addr UNNEEDED) { fprintf(stderr, "towire_gossipctl_peer_addrhint called!\n"); abort(); } +/* Generated stub for towire_gossipctl_peer_disconnect */ +u8 *towire_gossipctl_peer_disconnect(const tal_t *ctx UNNEEDED, const struct pubkey *id UNNEEDED) +{ fprintf(stderr, "towire_gossipctl_peer_disconnect called!\n"); abort(); } /* Generated stub for towire_gossipctl_reach_peer */ u8 *towire_gossipctl_reach_peer(const tal_t *ctx UNNEEDED, const struct pubkey *id UNNEEDED) { fprintf(stderr, "towire_gossipctl_reach_peer called!\n"); abort(); } @@ -348,7 +361,7 @@ u8 *towire_gossip_disable_channel(const tal_t *ctx UNNEEDED, const struct short_ u8 *towire_gossip_getpeers_request(const tal_t *ctx UNNEEDED, const struct pubkey *id UNNEEDED) { fprintf(stderr, "towire_gossip_getpeers_request called!\n"); abort(); } /* Generated stub for txfilter_add_scriptpubkey */ -void txfilter_add_scriptpubkey(struct txfilter *filter UNNEEDED, u8 *script UNNEEDED) +void txfilter_add_scriptpubkey(struct txfilter *filter UNNEEDED, const u8 *script TAKES UNNEEDED) { fprintf(stderr, "txfilter_add_scriptpubkey called!\n"); abort(); } /* Generated stub for unsupported_features */ bool unsupported_features(const u8 *gfeatures UNNEEDED, const u8 *lfeatures UNNEEDED) @@ -373,18 +386,6 @@ struct txowatch *watch_txo(const tal_t *ctx UNNEEDED, size_t input_num UNNEEDED, const struct block *block)) { fprintf(stderr, "watch_txo called!\n"); abort(); } -/* Generated stub for json_add_string_escape */ -void json_add_string_escape(struct json_result *result UNNEEDED, const char *fieldname UNNEEDED, const char *value UNNEEDED) -{ fprintf(stderr, "json_add_string_escape called!\n"); abort(); } -/* Generated stub for towire_gossipctl_peer_disconnect */ -u8 *towire_gossipctl_peer_disconnect(const tal_t *ctx UNNEEDED, const struct pubkey *id UNNEEDED) -{ fprintf(stderr, "towire_gossipctl_peer_disconnect called!\n"); abort(); } -/* Generated stub for fromwire_gossipctl_peer_disconnect_reply */ -bool fromwire_gossipctl_peer_disconnect_reply(const void *p UNNEEDED) -{ fprintf(stderr, "fromwire_gossipctl_peer_disconnect_reply called!\n"); abort(); } -/* Generated stub for fromwire_gossipctl_peer_disconnect_replyfail*/ -bool fromwire_gossipctl_peer_disconnect_replyfail(const void *p UNNEEDED, bool *isconnected UNNEEDED) -{ fprintf(stderr, "fromwire_gossipctl_peer_disconnect_replyfail called!\n"); abort(); } /* AUTOGENERATED MOCKS END */ #if DEVELOPER diff --git a/wallet/txfilter.c b/wallet/txfilter.c index d74bef0bd..990d159c1 100644 --- a/wallet/txfilter.c +++ b/wallet/txfilter.c @@ -11,7 +11,7 @@ #include struct txfilter { - u8 **scriptpubkeys; + const u8 **scriptpubkeys; }; struct outpointfilter_entry { @@ -49,18 +49,19 @@ struct outpointfilter { struct txfilter *txfilter_new(const tal_t *ctx) { struct txfilter *filter = tal(ctx, struct txfilter); - filter->scriptpubkeys = tal_arr(filter, u8*, 0); + filter->scriptpubkeys = tal_arr(filter, const u8 *, 0); return filter; } -void txfilter_add_scriptpubkey(struct txfilter *filter, u8 *script) +void txfilter_add_scriptpubkey(struct txfilter *filter, const u8 *script TAKES) { size_t count = tal_count(filter->scriptpubkeys); tal_resize(&filter->scriptpubkeys, count + 1); filter->scriptpubkeys[count] = tal_dup_arr(filter, u8, script, tal_len(script), 0); } -void txfilter_add_derkey(struct txfilter *filter, u8 derkey[PUBKEY_DER_LEN]) +void txfilter_add_derkey(struct txfilter *filter, + const u8 derkey[PUBKEY_DER_LEN]) { tal_t *tmpctx = tal_tmpctx(filter); u8 *skp, *p2sh; diff --git a/wallet/txfilter.h b/wallet/txfilter.h index fb8db02f8..397631300 100644 --- a/wallet/txfilter.h +++ b/wallet/txfilter.h @@ -26,7 +26,8 @@ struct txfilter *txfilter_new(const tal_t *ctx); * scriptpubkey then the transaction is marked as a match. Adds * scriptpubkey for both raw p2wpkh and p2wpkh wrapped in p2sh. */ -void txfilter_add_derkey(struct txfilter *filter, u8 derkey[PUBKEY_DER_LEN]); +void txfilter_add_derkey(struct txfilter *filter, + const u8 derkey[PUBKEY_DER_LEN]); /** * txfilter_match -- Check whether the tx matches the filter @@ -36,7 +37,7 @@ bool txfilter_match(const struct txfilter *filter, const struct bitcoin_tx *tx); /** * txfilter_add_scriptpubkey -- Add a serialized scriptpubkey to the filter */ -void txfilter_add_scriptpubkey(struct txfilter *filter, u8 *script); +void txfilter_add_scriptpubkey(struct txfilter *filter, const u8 *script TAKES); /** * outpointfilter_new -- Create a new outpointfilter