Browse Source

wallet: minor style fixes, and remove null JSON fields.

Our policy is generally to omit fields which aren't sensible.
Also, @niftynei points out the spacing in for loops.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
travis-debug
Rusty Russell 6 years ago
committed by neil saitug
parent
commit
93865bb0f3
  1. 12
      tests/test_wallet.py
  2. 12
      wallet/walletrpc.c

12
tests/test_wallet.py

@ -472,8 +472,16 @@ def test_transaction_annotations(node_factory, bitcoind):
assert(output['type'] == 'deposit' and output['satoshis'] == '1000000000msat') assert(output['type'] == 'deposit' and output['satoshis'] == '1000000000msat')
# ... and all other output should be change, and have no annotations # ... and all other output should be change, and have no annotations
types = set([o['type'] for i, o in enumerate(tx['outputs']) if i != idx]) types = []
assert(set([None]) == types) for i, o in enumerate(tx['outputs']):
if i == idx:
continue
if 'type' in o:
types.append(o['type'])
else:
types.append(None)
assert(set([None]) == set(types))
########################################################################## ##########################################################################
# Let's now open a channel. The opener should get the funding transaction # Let's now open a channel. The opener should get the funding transaction

12
wallet/walletrpc.c

@ -936,13 +936,9 @@ static void json_transaction_details(struct json_stream *response,
#if EXPERIMENTAL_FEATURES #if EXPERIMENTAL_FEATURES
if (tx->annotation.type != 0) if (tx->annotation.type != 0)
json_add_txtypes(response, "type", tx->annotation.type); json_add_txtypes(response, "type", tx->annotation.type);
else
json_add_null(response, "type");
if (tx->annotation.channel.u64 != 0) if (tx->annotation.channel.u64 != 0)
json_add_short_channel_id(response, "channel", &tx->annotation.channel); json_add_short_channel_id(response, "channel", &tx->annotation.channel);
else
json_add_null(response, "channel");
#endif #endif
json_add_u32(response, "locktime", wtx->locktime); json_add_u32(response, "locktime", wtx->locktime);
json_add_u32(response, "version", wtx->version); json_add_u32(response, "version", wtx->version);
@ -959,12 +955,8 @@ static void json_transaction_details(struct json_stream *response,
const char *txtype = txtype_to_string(ann->type); const char *txtype = txtype_to_string(ann->type);
if (txtype != NULL) if (txtype != NULL)
json_add_string(response, "type", txtype); json_add_string(response, "type", txtype);
else
json_add_null(response, "type");
if (ann->channel.u64 != 0) if (ann->channel.u64 != 0)
json_add_short_channel_id(response, "channel", &ann->channel); json_add_short_channel_id(response, "channel", &ann->channel);
else
json_add_null(response, "channel");
#endif #endif
json_object_end(response); json_object_end(response);
@ -993,13 +985,9 @@ static void json_transaction_details(struct json_stream *response,
const char *txtype = txtype_to_string(ann->type); const char *txtype = txtype_to_string(ann->type);
if (txtype != NULL) if (txtype != NULL)
json_add_string(response, "type", txtype); json_add_string(response, "type", txtype);
else
json_add_null(response, "type");
if (ann->channel.u64 != 0) if (ann->channel.u64 != 0)
json_add_short_channel_id(response, "channel", &ann->channel); json_add_short_channel_id(response, "channel", &ann->channel);
else
json_add_null(response, "channel");
#endif #endif
json_add_hex(response, "scriptPubKey", out->script, out->script_len); json_add_hex(response, "scriptPubKey", out->script, out->script_len);

Loading…
Cancel
Save