Skip to content

Commit dd11eae

Browse files
Fix NWC list_transactions (#8)
The list of transactions in the result is an Array of Objects, not an Object. Example: { "result": { "transactions": [ { "type": "incoming", "invoice": "lnbc50n19cywtv", "description": "test", ... So it needs .as<JsonArray>(), not .as<JsonObject>(), otherwise no transactions will be parsed from the JSON.
1 parent 122e70c commit dd11eae

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

src/Nip47.cpp

+13-13
Original file line numberDiff line numberDiff line change
@@ -366,22 +366,22 @@ void Nip47::parseResponse(SignedNostrEvent *response, Nip47Response<ListTransact
366366
NostrString resultType = doc["result_type"].as<NostrString>();
367367
JsonObject data = doc["result"];
368368
if (NostrString_equals(resultType, "list_transactions")) {
369-
for (JsonPair kv : data["transactions"].as<JsonObject>()) {
369+
for (JsonObject kv : data["transactions"].as<JsonArray>()) {
370370
Transaction transaction;
371-
transaction.type = kv.value()["type"].as<NostrString>();
372-
transaction.invoice = kv.value()["invoice"].as<NostrString>();
373-
transaction.description = kv.value()["description"].as<NostrString>();
374-
transaction.descriptionHash = kv.value()["description_hash"].as<NostrString>();
375-
transaction.preimage = kv.value()["preimage"].as<NostrString>();
376-
transaction.paymentHash = kv.value()["payment_hash"].as<NostrString>();
377-
transaction.amount = kv.value()["amount"].as<unsigned long long>();
378-
transaction.feesPaid = kv.value()["fees_paid"].as<unsigned long long>();
379-
transaction.createdAt = kv.value()["created_at"].as<unsigned long long>();
380-
transaction.expiresAt = kv.value()["expires_at"].as<unsigned long long>();
381-
transaction.settledAt = kv.value()["settled_at"].as<unsigned long long>();
371+
transaction.type = kv["type"].as<NostrString>();
372+
transaction.invoice = kv["invoice"].as<NostrString>();
373+
transaction.description = kv["description"].as<NostrString>();
374+
transaction.descriptionHash = kv["description_hash"].as<NostrString>();
375+
transaction.preimage = kv["preimage"].as<NostrString>();
376+
transaction.paymentHash = kv["payment_hash"].as<NostrString>();
377+
transaction.amount = kv["amount"].as<unsigned long long>();
378+
transaction.feesPaid = kv["fees_paid"].as<unsigned long long>();
379+
transaction.createdAt = kv["created_at"].as<unsigned long long>();
380+
transaction.expiresAt = kv["expires_at"].as<unsigned long long>();
381+
transaction.settledAt = kv["settled_at"].as<unsigned long long>();
382382
JsonDocument metadataDoc;
383383
JsonObject metadataObject = metadataDoc.as<JsonObject>();
384-
for (JsonPair kv : kv.value()["metadata"].as<JsonObject>()) {
384+
for (JsonPair kv : kv["metadata"].as<JsonObject>()) {
385385
metadataObject[kv.key().c_str()] = kv.value().as<NostrString>();
386386
}
387387
transaction.metadata = metadataObject;

0 commit comments

Comments
 (0)