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

Function parse_amount_sat

common/amount.c:234–266  ·  view source on GitHub ↗

Valid strings: * [0-9]+ => satoshi. * [0-9]+sat => satoshi. * [0-9]+000msat => satoshi. * 0msat => 0 satoshi * [0-9]+.[0-9]{1,8}btc => satoshi. */

Source from the content-addressed store, hash-verified

232 * [0-9]+.[0-9]{1,8}btc => satoshi.
233 */
234bool parse_amount_sat(struct amount_sat *sat, const char *s, size_t slen)
235{
236 size_t whole_number_len, post_decimal_len, suffix_len;
237 const char *post_decimal_ptr, *suffix_ptr;
238
239 if (!breakup(s, slen, &whole_number_len,
240 &post_decimal_ptr, &post_decimal_len,
241 &suffix_ptr, &suffix_len))
242 return false;
243
244 if (!post_decimal_ptr && !suffix_ptr)
245 return from_number(&sat->satoshis, s, whole_number_len, 0);
246 if (!post_decimal_ptr && memstarts_str(suffix_ptr, suffix_len, "sat"))
247 return from_number(&sat->satoshis, s, whole_number_len, 0);
248 if (!post_decimal_ptr && memstarts_str(suffix_ptr, suffix_len, "msat")) {
249 if (!memends(s, whole_number_len, "000", strlen("000"))) {
250 if (memstarts_str(s, whole_number_len, "0"))
251 return from_number(&sat->satoshis, s,
252 whole_number_len, 0);
253 return false;
254 }
255 return from_number(&sat->satoshis, s, whole_number_len - 3, 0);
256 }
257 if (memstarts_str(suffix_ptr, suffix_len, "btc")) {
258 if (post_decimal_len > 0)
259 return from_numbers(&sat->satoshis,
260 s, whole_number_len, 8,
261 post_decimal_ptr, post_decimal_len);
262 return from_number(&sat->satoshis, s, whole_number_len, 8);
263 }
264
265 return false;
266}
267
268WARN_UNUSED_RESULT bool amount_msat_add(struct amount_msat *val,
269 struct amount_msat a,

Callers 13

json_to_satFunction · 0.70
param_satFunction · 0.70
type_dataFunction · 0.70
mainFunction · 0.50
runFunction · 0.50
param_policy_modFunction · 0.50
amount_optionFunction · 0.50
amount_sat_or_u64_optionFunction · 0.50
parse_configFunction · 0.50
mainFunction · 0.50
mainFunction · 0.50
mainFunction · 0.50

Calls 5

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

Tested by 1

mainFunction · 0.40