Valid strings: * [0-9]+ => millisatoshi. * [0-9]+msat => millisatoshi. * [0-9]+sat => *1000 -> millisatoshi. * [0-9]+.[0-9]{1,11}btc => millisatoshi. */
| 198 | * [0-9]+.[0-9]{1,11}btc => millisatoshi. |
| 199 | */ |
| 200 | bool 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. |
no test coverage detected