mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 23:24:27 +01:00
json: reverse parse a coin_mvt tag back into an enum
This commit is contained in:
@@ -14,6 +14,7 @@ enum mvt_type {
|
||||
CHANNEL_MVT = 1,
|
||||
};
|
||||
|
||||
#define NUM_MVT_TAGS (LEASED + 1)
|
||||
enum mvt_tag {
|
||||
DEPOSIT = 0,
|
||||
WITHDRAWAL = 1,
|
||||
|
||||
@@ -108,6 +108,22 @@ bool json_to_channel_id(const char *buffer, const jsmntok_t *tok,
|
||||
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,
|
||||
char split,
|
||||
jsmntok_t *a,
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#define LIGHTNING_COMMON_JSON_HELPERS_H
|
||||
#include "config.h"
|
||||
#include <bitcoin/tx.h>
|
||||
#include <common/coin_mvt.h>
|
||||
#include <common/json.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,
|
||||
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 */
|
||||
bool split_tok(const char *buffer, const jsmntok_t *tok,
|
||||
char split,
|
||||
|
||||
@@ -21,8 +21,8 @@ ALL_TEST_PROGRAMS += $(COMMON_TEST_PROGRAMS)
|
||||
# Sphinx test wants to decode TLVs.
|
||||
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-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_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_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/coin_mvt.o
|
||||
|
||||
common/test/run-param \
|
||||
common/test/run-json: \
|
||||
@@ -30,6 +30,7 @@ common/test/run-json: \
|
||||
common/base32.o \
|
||||
common/bigsize.o \
|
||||
common/channel_id.o \
|
||||
common/coin_mvt.o \
|
||||
common/json.o \
|
||||
common/json_stream.o \
|
||||
common/lease_rates.o \
|
||||
|
||||
@@ -14,6 +14,7 @@ ALL_PROGRAMS += $(DEVTOOLS)
|
||||
DEVTOOLS_COMMON_OBJS := \
|
||||
common/amount.o \
|
||||
common/autodata.o \
|
||||
common/coin_mvt.o \
|
||||
common/base32.o \
|
||||
common/bech32.o \
|
||||
common/bech32_util.o \
|
||||
|
||||
@@ -9,6 +9,7 @@ GOSSIPD_TEST_PROGRAMS := $(GOSSIPD_TEST_OBJS:.o=)
|
||||
GOSSIPD_TEST_COMMON_OBJS := \
|
||||
common/amount.o \
|
||||
common/autodata.o \
|
||||
common/coin_mvt.o \
|
||||
common/bigsize.o \
|
||||
common/blindedpath.o \
|
||||
common/channel_id.o \
|
||||
|
||||
@@ -108,6 +108,7 @@ PLUGIN_COMMON_OBJS := \
|
||||
bitcoin/varint.o \
|
||||
common/amount.o \
|
||||
common/autodata.o \
|
||||
common/coin_mvt.o \
|
||||
common/base32.o \
|
||||
common/bech32.o \
|
||||
common/bech32_util.o \
|
||||
|
||||
Reference in New Issue
Block a user