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

Function parse_amount_msat

common/amount.c:200–225  ·  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

198 * [0-9]+.[0-9]{1,11}btc => millisatoshi.
199 */
200bool parse_amount_msat(struct amount_msat *msat, const char *s, size_t slen)
201{
202 size_t whole_number_len, post_decimal_len, suffix_len;
203 const char *post_decimal_ptr, *suffix_ptr;
204
205 if (!breakup(s, slen, &whole_number_len,
206 &post_decimal_ptr, &post_decimal_len,
207 &suffix_ptr, &suffix_len))
208 return false;
209
210 if (!post_decimal_ptr && !suffix_ptr)
211 return from_number(&msat->millisatoshis, s, whole_number_len, 0);
212 if (!post_decimal_ptr && memstarts_str(suffix_ptr, suffix_len, "msat"))
213 return from_number(&msat->millisatoshis, s, whole_number_len, 0);
214 if (!post_decimal_ptr && memstarts_str(suffix_ptr, suffix_len, "sat"))
215 return from_number(&msat->millisatoshis, s, whole_number_len, 3);
216 if (memstarts_str(suffix_ptr, suffix_len, "btc")) {
217 if (post_decimal_len > 0)
218 return from_numbers(&msat->millisatoshis,
219 s, whole_number_len, 11,
220 post_decimal_ptr, post_decimal_len);
221 return from_number(&msat->millisatoshis, s, whole_number_len, 11);
222 }
223
224 return false;
225}
226
227/* Valid strings:
228 * [0-9]+ => satoshi.

Callers 15

json_to_msatFunction · 0.70
param_msatFunction · 0.70
opt_set_msatFunction · 0.50
opt_set_satFunction · 0.50
param_msat_as_satFunction · 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
calc_maxfeeFunction · 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