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

Function parse_amount_sat

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

219 * [0-9]+.[0-9]{1,8}btc => satoshi.
220 */
221bool parse_amount_sat(struct amount_sat *sat, const char *s, size_t slen)
222{
223 size_t whole_number_len, post_decimal_len, suffix_len;
224 const char *post_decimal_ptr, *suffix_ptr;
225
226 if (!breakup(s, slen, &whole_number_len,
227 &post_decimal_ptr, &post_decimal_len,
228 &suffix_ptr, &suffix_len))
229 return false;
230
231 if (!post_decimal_ptr && !suffix_ptr)
232 return from_number(&sat->satoshis, s, whole_number_len, 0);
233 if (!post_decimal_ptr && memstarts_str(suffix_ptr, suffix_len, "sat"))
234 return from_number(&sat->satoshis, s, whole_number_len, 0);
235 if (!post_decimal_ptr && memstarts_str(suffix_ptr, suffix_len, "msat")) {
236 if (!memends(s, whole_number_len, "000", strlen("000"))) {
237 if (memstarts_str(s, whole_number_len, "0"))
238 return from_number(&sat->satoshis, s,
239 whole_number_len, 0);
240 return false;
241 }
242 return from_number(&sat->satoshis, s, whole_number_len - 3, 0);
243 }
244 if (memstarts_str(suffix_ptr, suffix_len, "btc")) {
245 if (post_decimal_len > 0)
246 return from_numbers(&sat->satoshis,
247 s, whole_number_len, 8,
248 post_decimal_ptr, post_decimal_len);
249 return from_number(&sat->satoshis, s, whole_number_len, 8);
250 }
251
252 return false;
253}
254
255WARN_UNUSED_RESULT bool amount_msat_add(struct amount_msat *val,
256 struct amount_msat a,

Callers 12

json_to_satFunction · 0.70
param_satFunction · 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
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