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

Function parse_amount_msat

common/amount.c:187–212  ·  view source on GitHub ↗

Valid strings: * [0-9]+ => millisatoshi. * [0-9]+msat => millisatoshi. * [0-9]+sat => *1000 -> millisatoshi. * [0-9]+.[0-9]{1,11}btc => millisatoshi. */

Source from the content-addressed store, hash-verified

185 * [0-9]+.[0-9]{1,11}btc => millisatoshi.
186 */
187bool parse_amount_msat(struct amount_msat *msat, const char *s, size_t slen)
188{
189 size_t whole_number_len, post_decimal_len, suffix_len;
190 const char *post_decimal_ptr, *suffix_ptr;
191
192 if (!breakup(s, slen, &whole_number_len,
193 &post_decimal_ptr, &post_decimal_len,
194 &suffix_ptr, &suffix_len))
195 return false;
196
197 if (!post_decimal_ptr && !suffix_ptr)
198 return from_number(&msat->millisatoshis, s, whole_number_len, 0);
199 if (!post_decimal_ptr && memstarts_str(suffix_ptr, suffix_len, "msat"))
200 return from_number(&msat->millisatoshis, s, whole_number_len, 0);
201 if (!post_decimal_ptr && memstarts_str(suffix_ptr, suffix_len, "sat"))
202 return from_number(&msat->millisatoshis, s, whole_number_len, 3);
203 if (memstarts_str(suffix_ptr, suffix_len, "btc")) {
204 if (post_decimal_len > 0)
205 return from_numbers(&msat->millisatoshis,
206 s, whole_number_len, 11,
207 post_decimal_ptr, post_decimal_len);
208 return from_number(&msat->millisatoshis, s, whole_number_len, 11);
209 }
210
211 return false;
212}
213
214/* Valid strings:
215 * [0-9]+ => satoshi.

Callers 13

json_to_msatFunction · 0.70
param_msatFunction · 0.70
opt_set_msatFunction · 0.50
runFunction · 0.50
msat_or_anyFunction · 0.50
param_msat_as_satFunction · 0.50
option_channel_baseFunction · 0.50
after_fundpsbtFunction · 0.50
parse_htlcFunction · 0.50
mainFunction · 0.50
parse_optionsFunction · 0.50

Calls 4

breakupFunction · 0.85
from_numberFunction · 0.85
memstarts_strFunction · 0.85
from_numbersFunction · 0.85

Tested by

no test coverage detected