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