json: reverse parse a coin_mvt tag back into an enum

This commit is contained in:
niftynei
2022-02-16 15:36:47 -06:00
committed by Rusty Russell
parent 590f12145b
commit 7add7ca199
7 changed files with 28 additions and 2 deletions

View File

@@ -14,6 +14,7 @@ enum mvt_type {
CHANNEL_MVT = 1, CHANNEL_MVT = 1,
}; };
#define NUM_MVT_TAGS (LEASED + 1)
enum mvt_tag { enum mvt_tag {
DEPOSIT = 0, DEPOSIT = 0,
WITHDRAWAL = 1, WITHDRAWAL = 1,

View File

@@ -108,6 +108,22 @@ bool json_to_channel_id(const char *buffer, const jsmntok_t *tok,
cid, sizeof(*cid)); cid, sizeof(*cid));
} }
bool json_to_coin_mvt_tag(const char *buffer, const jsmntok_t *tok,
enum mvt_tag *tag)
{
enum mvt_tag i_tag;
for (size_t i = 0; i < NUM_MVT_TAGS; i++) {
i_tag = (enum mvt_tag) i;
if (json_tok_streq(buffer, tok, mvt_tag_str(i_tag))) {
*tag = i_tag;
return true;
}
}
return false;
}
bool split_tok(const char *buffer, const jsmntok_t *tok, bool split_tok(const char *buffer, const jsmntok_t *tok,
char split, char split,
jsmntok_t *a, jsmntok_t *a,

View File

@@ -3,6 +3,7 @@
#define LIGHTNING_COMMON_JSON_HELPERS_H #define LIGHTNING_COMMON_JSON_HELPERS_H
#include "config.h" #include "config.h"
#include <bitcoin/tx.h> #include <bitcoin/tx.h>
#include <common/coin_mvt.h>
#include <common/json.h> #include <common/json.h>
#include <wire/wire.h> #include <wire/wire.h>
@@ -73,6 +74,10 @@ bool json_to_outpoint(const char *buffer, const jsmntok_t *tok,
bool json_to_channel_id(const char *buffer, const jsmntok_t *tok, bool json_to_channel_id(const char *buffer, const jsmntok_t *tok,
struct channel_id *cid); struct channel_id *cid);
/* Extract a coin movement 'tag' from this */
bool json_to_coin_mvt_tag(const char *buffer, const jsmntok_t *tok,
enum mvt_tag *tag);
/* Split a json token into 2 tokens given a splitting character */ /* Split a json token into 2 tokens given a splitting character */
bool split_tok(const char *buffer, const jsmntok_t *tok, bool split_tok(const char *buffer, const jsmntok_t *tok,
char split, char split,

View File

@@ -21,8 +21,8 @@ ALL_TEST_PROGRAMS += $(COMMON_TEST_PROGRAMS)
# Sphinx test wants to decode TLVs. # Sphinx test wants to decode TLVs.
common/test/run-sphinx: wire/onion$(EXP)_wiregen.o wire/towire.o wire/fromwire.o common/test/run-sphinx: wire/onion$(EXP)_wiregen.o wire/towire.o wire/fromwire.o
common/test/run-blindedpath_enctlv common/test/run-blindedpath_onion: common/base32.o common/wireaddr.o wire/onion$(EXP)_wiregen.o wire/peer$(EXP)_wiregen.o wire/towire.o wire/fromwire.o wire/tlvstream.o common/test/run-blindedpath_enctlv common/test/run-blindedpath_onion: common/base32.o common/wireaddr.o wire/onion$(EXP)_wiregen.o wire/peer$(EXP)_wiregen.o wire/towire.o wire/fromwire.o wire/tlvstream.o
common/test/run-route_blinding_test: wire/onion$(EXP)_wiregen.o wire/peer$(EXP)_wiregen.o wire/towire.o wire/fromwire.o wire/tlvstream.o common/json.o common/json_helpers.o common/test/run-route_blinding_test: wire/onion$(EXP)_wiregen.o wire/peer$(EXP)_wiregen.o wire/towire.o wire/fromwire.o wire/tlvstream.o common/json.o common/json_helpers.o common/coin_mvt.o
common/test/run-route_blinding_override_test: common/base32.o common/wireaddr.o wire/onion$(EXP)_wiregen.o wire/peer$(EXP)_wiregen.o wire/towire.o wire/fromwire.o wire/tlvstream.o common/json.o common/json_helpers.o common/test/run-route_blinding_override_test: common/base32.o common/wireaddr.o wire/onion$(EXP)_wiregen.o wire/peer$(EXP)_wiregen.o wire/towire.o wire/fromwire.o wire/tlvstream.o common/json.o common/json_helpers.o common/coin_mvt.o
common/test/run-param \ common/test/run-param \
common/test/run-json: \ common/test/run-json: \
@@ -30,6 +30,7 @@ common/test/run-json: \
common/base32.o \ common/base32.o \
common/bigsize.o \ common/bigsize.o \
common/channel_id.o \ common/channel_id.o \
common/coin_mvt.o \
common/json.o \ common/json.o \
common/json_stream.o \ common/json_stream.o \
common/lease_rates.o \ common/lease_rates.o \

View File

@@ -14,6 +14,7 @@ ALL_PROGRAMS += $(DEVTOOLS)
DEVTOOLS_COMMON_OBJS := \ DEVTOOLS_COMMON_OBJS := \
common/amount.o \ common/amount.o \
common/autodata.o \ common/autodata.o \
common/coin_mvt.o \
common/base32.o \ common/base32.o \
common/bech32.o \ common/bech32.o \
common/bech32_util.o \ common/bech32_util.o \

View File

@@ -9,6 +9,7 @@ GOSSIPD_TEST_PROGRAMS := $(GOSSIPD_TEST_OBJS:.o=)
GOSSIPD_TEST_COMMON_OBJS := \ GOSSIPD_TEST_COMMON_OBJS := \
common/amount.o \ common/amount.o \
common/autodata.o \ common/autodata.o \
common/coin_mvt.o \
common/bigsize.o \ common/bigsize.o \
common/blindedpath.o \ common/blindedpath.o \
common/channel_id.o \ common/channel_id.o \

View File

@@ -108,6 +108,7 @@ PLUGIN_COMMON_OBJS := \
bitcoin/varint.o \ bitcoin/varint.o \
common/amount.o \ common/amount.o \
common/autodata.o \ common/autodata.o \
common/coin_mvt.o \
common/base32.o \ common/base32.o \
common/bech32.o \ common/bech32.o \
common/bech32_util.o \ common/bech32_util.o \