Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Offers Part 2: db and invoice infrastructure. #4256

Merged
merged 12 commits into from
Dec 15, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions common/iso4217.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <ccan/array_size/array_size.h>
#include <ccan/mem/mem.h>
#include <common/iso4217.h>
#include <string.h>

/* Wikipedia leads me to: https://www.currency-iso.org/en/home/tables/table-a1.html

Expand Down Expand Up @@ -191,10 +191,12 @@ static const struct iso4217_name_and_divisor iso4217[] = {
{ "ZWL", 2 },
};

const struct iso4217_name_and_divisor *find_iso4217(const char *prefix)
const struct iso4217_name_and_divisor *find_iso4217(const utf8 *prefix,
size_t len)
{
for (size_t i = 0; i < ARRAY_SIZE(iso4217); i++) {
if (memcmp(iso4217[i].name, prefix, ISO4217_NAMELEN) == 0)
if (memeq(iso4217[i].name, strlen(iso4217[i].name),
prefix, len))
return &iso4217[i];
}
return NULL;
Expand Down
4 changes: 3 additions & 1 deletion common/iso4217.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef LIGHTNING_COMMON_ISO4217_H
#define LIGHTNING_COMMON_ISO4217_H
#include "config.h"
#include <wire/wire.h>

/* BOLT-offers #12:
*
Expand All @@ -15,5 +16,6 @@ struct iso4217_name_and_divisor {

#define ISO4217_NAMELEN 3

const struct iso4217_name_and_divisor *find_iso4217(const char *prefix);
const struct iso4217_name_and_divisor *find_iso4217(const utf8 *prefix,
size_t len);
#endif /* LIGHTNING_COMMON_ISO4217_H */
12 changes: 6 additions & 6 deletions devtools/bolt12-cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,14 @@ static bool print_amount(const struct bitcoin_blkid *chains,
minor_unit = 11;
} else {
const struct iso4217_name_and_divisor *iso;
currency = tal_strndup(tmpctx, iso4217, tal_bytelen(iso4217));
iso = find_iso4217(currency);
if (iso)
iso = find_iso4217(iso4217, tal_bytelen(iso4217));
if (iso) {
minor_unit = iso->minor_unit;
else {
currency = iso->name;
} else {
minor_unit = 0;
currency = tal_fmt(tmpctx, "%s (UNKNOWN CURRENCY)",
currency);
currency = tal_fmt(tmpctx, "%.*s (UNKNOWN CURRENCY)",
(int)tal_bytelen(iso4217), iso4217);
ok = false;
}
}
Expand Down
7 changes: 7 additions & 0 deletions wallet/db.c
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,13 @@ static struct migration dbmigrations[] = {
" cause INTEGER,"
" message TEXT"
");"), NULL},
{SQL("CREATE TABLE offers ("
" offer_id BLOB"
", bolt12 TEXT"
", label TEXT"
", status INTEGER"
", PRIMARY KEY (offer_id)"
");"), NULL},
};

/* Leak tracking. */
Expand Down
52 changes: 50 additions & 2 deletions wallet/db_postgres_sqlgen.c

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 50 additions & 2 deletions wallet/db_sqlite3_sqlgen.c

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

66 changes: 49 additions & 17 deletions wallet/statements_gettextgen.po

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading