NwcRequest.fromMap constructor
NwcRequest.fromMap(
- Map<String, dynamic> map
)
Implementation
factory NwcRequest.fromMap(Map<String, dynamic> map) {
final method = NwcMethod.fromPlaintext(map['method'] as String);
// Handling for standard methods
switch (method) {
case NwcMethod.GET_INFO:
return GetInfoRequest();
case NwcMethod.GET_BALANCE:
return GetBalanceRequest();
case NwcMethod.MAKE_INVOICE:
return MakeInvoiceRequest(
amountMsat: map['amount'] as int,
description: map['description'] as String?,
descriptionHash: map['description_hash'] as String?,
expiry: map['expiry'] as int?,
);
case NwcMethod.PAY_INVOICE:
return PayInvoiceRequest(
invoice: map['invoice'] as String,
);
case NwcMethod.MULTI_PAY_INVOICE:
final invoices = (map['invoices'] as List)
.map((e) => MultiPayInvoiceRequestInvoicesElement(
invoice: e['invoice'] as String,
amountMsat: e['amount'] as int,
))
.toList();
return MultiPayInvoiceRequest(
invoices: invoices,
);
case NwcMethod.PAY_KEYSEND:
return PayKeysendRequest(
amountMsat: map['amount'] as int,
pubkey: map['pubkey'] as String,
preimage: map['preimage'] as String?,
tlvRecords: (map['tlv_records'] as List)
.map((e) => TlvRecord.fromMap(e as Map<String, dynamic>))
.toList(),
);
case NwcMethod.MULTI_PAY_KEYSEND:
final keysends = (map['keysends'] as List)
.map((e) => MultiPayKeysendRequestInvoicesElement(
pubkey: e['pubkey'] as String,
amountMsat: e['amount'] as int,
preimage: e['preimage'] as String?,
tlvRecords: (e['tlv_records'] as List)
.map((e) => TlvRecord.fromMap(e as Map<String, dynamic>))
.toList(),
))
.toList();
return MultiPayKeysendRequest(
keysends: keysends,
);
case NwcMethod.LOOKUP_INVOICE:
return LookupInvoiceRequest(
paymentHash: map['payment_hash'] as String?,
invoice: map['invoice'] as String?,
);
case NwcMethod.LIST_TRANSACTIONS:
return ListTransactionsRequest(
from: map['from'] as int?,
until: map['until'] as int?,
limit: map['limit'] as int?,
offset: map['offset'] as int?,
unpaid: map['unpaid'] as bool,
type: map['type'] == null
? null
: TransactionType.fromValue(
map['type'] as String,
),
);
default:
throw Exception("unknown method");
}
}