MCPcopy Create free account
hub / github.com/ElementsProject/lightning / convert_currency

Function convert_currency

plugins/offers_invreq_hook.c:784–824  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

782}
783
784static struct command_result *convert_currency(struct command *cmd,
785 struct invreq *ir)
786{
787 struct out_req *req;
788 u64 raw_amount;
789 double double_amount;
790 struct command_result *err;
791 const struct iso4217_name_and_divisor *iso4217;
792
793 assert(ir->invreq->offer_currency);
794
795 /* Multiply by quantity *first*, for best precision */
796 err = invreq_amount_by_quantity(cmd, ir, &raw_amount);
797 if (err)
798 return err;
799
800 /* BOLT #12:
801 * - MUST calculate the *expected amount* using the `offer_amount`:
802 * - if `offer_currency` is not the `invreq_chain` currency, convert to the
803 * `invreq_chain` currency.
804 */
805 iso4217 = find_iso4217(ir->invreq->offer_currency,
806 tal_bytelen(ir->invreq->offer_currency));
807 /* We should not create offer with unknown currency! */
808 if (!iso4217)
809 return fail_internalerr(cmd, ir,
810 "Unknown offer currency %.*s",
811 (int)tal_bytelen(ir->invreq->offer_currency),
812 ir->invreq->offer_currency);
813 double_amount = (double)raw_amount;
814 for (size_t i = 0; i < iso4217->minor_unit; i++)
815 double_amount /= 10;
816
817 req = jsonrpc_request_start(cmd, "currencyconvert",
818 currency_done, error, ir);
819 json_add_stringn(req->js, "currency",
820 (const char *)ir->invreq->offer_currency,
821 tal_bytelen(ir->invreq->offer_currency));
822 json_add_primitive_fmt(req->js, "amount", "%f", double_amount);
823 return send_outreq(req);
824}
825
826static struct command_result *listoffers_done(struct command *cmd,
827 const char *method,

Callers 1

listoffers_doneFunction · 0.85

Calls 7

find_iso4217Function · 0.85
tal_bytelenFunction · 0.85
json_add_stringnFunction · 0.85
json_add_primitive_fmtFunction · 0.85
fail_internalerrFunction · 0.70
send_outreqFunction · 0.70

Tested by

no test coverage detected