<p>If you look at the source code you can find the data base schema of the SQLite3 database that is being used to store invoices at: <a href="https://github.com/ElementsProject/lightning/blob/426ff0abfff8b080b22095b9f0b670c7192f54ea/wallet/db.c#L185" rel="nofollow noreferrer">https://github.com/ElementsProject/lightning/blob/426ff0abfff8b080b22095b9f0b670c7192f54ea/wallet/db.c#L185</a></p>
<p>This indicates that the label field is of type TEXT. <a href="https://www.sqlite.org/datatype3.html" rel="nofollow noreferrer">According to the SQLite3 Documentation</a> this means:</p>
<blockquote>
<p>TEXT. The value is a text string, stored using the database encoding (UTF-8, UTF-16BE or UTF-16LE).</p>
</blockquote>
<p>Of course you need to check the if lightningd can also handle such long strings. the labels are stored in <code>invoice_details</code> which which is defined at:</p>
<p><a href="https://github.com/ElementsProject/lightning/blob/335ef3fb69f923f6f30213f68881d10ee6d977ed/wallet/wallet.h#L777" rel="nofollow noreferrer">https://github.com/ElementsProject/lightning/blob/335ef3fb69f923f6f30213f68881d10ee6d977ed/wallet/wallet.h#L777</a></p>
<p>from there you can see that it is of type <code>* json_escape</code> which comes from rusty's ccan libraries and is defined at:</p>
<p><a href="https://github.com/ElementsProject/lightning/blob/ade10e7fc4dacbb9d635b05152c7dc38c0896ce7/ccan/ccan/json_escape/json_escape.h" rel="nofollow noreferrer">https://github.com/ElementsProject/lightning/blob/ade10e7fc4dacbb9d635b05152c7dc38c0896ce7/ccan/ccan/json_escape/json_escape.h</a></p>
<p>There it says:</p>
<pre><code>/* Type differentiation for a correctly-escaped JSON string */
struct json_escape {
    /* NUL terminated string. */
    char s[1];
};

/**
 * json_escape - escape a valid UTF-8 string.
 * @ctx: tal context to allocate from.
 * @str: the string to escape.
 *
 * Allocates and returns a valid JSON string (without surrounding quotes).
 */
struct json_escape *json_escape(const tal_t *ctx, const char *str TAKES);
</code></pre>
<p>To my understanding this indicates indeed that as long as you have memory and disc you should be able to store UTF-8 strings of arbitrary length.</p>

CC BY-SA 4.0
2021-12-26T20:06:14.687Z
Thank for this great answer. It is stated in `json_escape.h`: `struct json_escape { char s[1]; };` . I'm a newbie to C, but doesn't it mean that the maximum size of the label is just one char? It wouldn't make sense but I think that the general syntax for declaring a string in C is: `char variable_name [array_size];`
John Smith
CC BY-SA 4.0
2021-12-26T20:13:04.960Z
No as mentioned in my answer `invoice_details` includes a pointer to that struct so effectively it is an array of those wrapped 1 element char arrays. I myself are a bit confused why it can be used to store utf8 but I guess they take the char as a byte and have the encoding in there. The reason for doing a one element array from the stack instead of a variable however is mysterious to me.
Rene Pickhardt
CC BY-SA 4.0
2021-12-26T14:32:34.470Z
2021-12-26T14:32:34.470Z
Rene Pickhardt
<p>I'm writing a script <a href="https://en.wikipedia.org/wiki/C_(programming_language)" rel="nofollow noreferrer">in C</a> that is mean to make the usage of my c-lightning wallet more convenient. And so I have to
specify a limit of characters (<code>l</code> is a variable that stands for label):</p>
<pre><code>puts(&quot;The label(a unique string or number)?&quot;);
        char l[15];
        fgets(l, 15, stdin);
        l[strcspn(l, &quot;\n&quot;)] = 0;
</code></pre>
<p>I arbitrarily decided on 15 not knowing whether <code>lightning-cli invoice</code> would accept such long string. Although <code>help invoice</code> gives some info about the label:</p>
<blockquote>
<p>The  label  must be a unique string or number (which is treated as a string, so &quot;01&quot; is different
from &quot;1&quot;); it is never revealed to other nodes on the lightning network, but it can  be  used  to
query the status of this invoice.</p>
</blockquote>
<p>it does not specify it's length nor its character set? Are <a href="https://en.wikipedia.org/wiki/UTF-8" rel="nofollow noreferrer">UTF-8 characters</a> accepted within the label or should I use only <a href="https://en.wikipedia.org/wiki/ASCII" rel="nofollow noreferrer">ASCII</a> character set? What is the maximum size / number of characters of the label?</p>

<core-lightning><invoices>
What is the maximum byte size or limit of characters in label in lightning-cli invoice? Are UTF-8 characters accepted?
John Smith
# What is the maximum byte size or limit of characters in label in lightning-cli invoice? Are UTF-8 characters accepted?

(Asked by: username_0 on 2021-12-26)

I'm writing a script [in C](https://en.wikipedia.org/wiki/C_(programming_language)) that is mean to make the usage of my c-lightning wallet more convenient. And so I have to
specify a limit of characters (`l` is a variable that stands for label):

```
puts("The label(a unique string or number)?");
        char l[15];
        fgets(l, 15, stdin);
        l[strcspn(l, "\n")] = 0;

```

I arbitrarily decided on 15 not knowing whether `lightning-cli invoice` would accept such long string. Although `help invoice` gives some info about the label:

> The label must be a unique string or number (which is treated as a string, so "01" is different
> from "1"); it is never revealed to other nodes on the lightning network, but it can be used to
> query the status of this invoice.

it does not specify it's length nor its character set? Are [UTF-8 characters](https://en.wikipedia.org/wiki/UTF-8) accepted within the label or should I use only [ASCII](https://en.wikipedia.org/wiki/ASCII) character set? What is the maximum size / number of characters of the label?

**Tags:** core-lightning, invoices


---

## 1 answers

### Answer by username_1 on 2021-12-26. Score: 1 | Accepted answer

If you look at the source code you can find the data base schema of the SQLite3 database that is being used to store invoices at: <https://github.com/ElementsProject/lightning/blob/426ff0abfff8b080b22095b9f0b670c7192f54ea/wallet/db.c#L185>

This indicates that the label field is of type TEXT. [According to the SQLite3 Documentation](https://www.sqlite.org/datatype3.html) this means:

> TEXT. The value is a text string, stored using the database encoding (UTF-8, UTF-16BE or UTF-16LE).

Of course you need to check the if lightningd can also handle such long strings. the labels are stored in `invoice_details` which which is defined at:

<https://github.com/ElementsProject/lightning/blob/335ef3fb69f923f6f30213f68881d10ee6d977ed/wallet/wallet.h#L777>

from there you can see that it is of type `* json_escape` which comes from rusty's ccan libraries and is defined at:

<https://github.com/ElementsProject/lightning/blob/ade10e7fc4dacbb9d635b05152c7dc38c0896ce7/ccan/ccan/json_escape/json_escape.h>

There it says:

```
/* Type differentiation for a correctly-escaped JSON string */
struct json_escape {
    /* NUL terminated string. */
    char s[1];
};

/**
 * json_escape - escape a valid UTF-8 string.
 * @ctx: tal context to allocate from.
 * @str: the string to escape.
 *
 * Allocates and returns a valid JSON string (without surrounding quotes).
 */
struct json_escape *json_escape(const tal_t *ctx, const char *str TAKES);

```

To my understanding this indicates indeed that as long as you have memory and disc you should be able to store UTF-8 strings of arbitrary length.

> **Comments:**
> **username_0**: Thank for this great answer. It is stated in `json_escape.h`: `struct json_escape { char s[1]; };` . I'm a newbie to C, but doesn't it mean that the maximum size of the label is just one char? It wouldn't make sense but I think that the general syntax for declaring a string in C is: `char variable_name [array_size];`  
> **username_1**: No as mentioned in my answer `invoice_details` includes a pointer to that struct so effectively it is an array of those wrapped 1 element char arrays. I myself are a bit confused why it can be used to store utf8 but I guess they take the char as a byte and have the encoding in there. The reason for doing a one element array from the stack instead of a variable however is mysterious to me.  

---

