diff options
author | Christian Grothoff <christian@grothoff.org> | 2020-01-13 18:16:01 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2020-01-13 18:16:01 +0100 |
commit | 4d6ef1da29e5c1bf4c2216d9fe0c14dcab0f04cd (patch) | |
tree | 8141db7f726c59d21a81fe37846970237a75d892 /src/util | |
parent | 258ed8617bdcad9f1c278a5fdcff97bcf2e29e54 (diff) | |
download | exchange-4d6ef1da29e5c1bf4c2216d9fe0c14dcab0f04cd.tar.xz |
eliminate libtalerwire
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/amount.c | 21 | ||||
-rw-r--r-- | src/util/util.c | 32 |
2 files changed, 53 insertions, 0 deletions
diff --git a/src/util/amount.c b/src/util/amount.c index 21410c769..edb9dc060 100644 --- a/src/util/amount.c +++ b/src/util/amount.c @@ -672,4 +672,25 @@ TALER_amount_divide (struct TALER_Amount *result, } +/** + * Round the amount to something that can be + * transferred on the wire. + * + * @param[in,out] amount amount to round down + * @return #GNUNET_OK on success, #GNUNET_NO if rounding was unnecessary, + * #GNUNET_SYSERR if the amount or currency was invalid + */ +int +TALER_amount_round (struct TALER_Amount *amount) +{ + uint32_t delta; + + delta = amount->fraction % (TALER_AMOUNT_FRAC_BASE / 100); + if (0 == delta) + return GNUNET_NO; + amount->fraction -= delta; + return GNUNET_OK; +} + + /* end of amount.c */ diff --git a/src/util/util.c b/src/util/util.c index fa65fc238..e312e345b 100644 --- a/src/util/util.c +++ b/src/util/util.c @@ -744,4 +744,36 @@ TALER_buffer_write_vfstr (struct TALER_Buffer *buf, } +/** + * Prefix of PAYTO URLs. + */ +#define PAYTO "payto://" + + +/** + * Obtain the payment method from a @a payto_url + * + * @param payto_url the URL to parse + * @return NULL on error (malformed @a payto_url) + */ +char * +TALER_payto_get_method (const char *payto_url) +{ + const char *start; + const char *end; + + if (0 != strncmp (payto_url, + PAYTO, + strlen (PAYTO))) + return NULL; + start = &payto_url[strlen (PAYTO)]; + end = strchr (start, + (unsigned char) '/'); + if (NULL == end) + return NULL; + return GNUNET_strndup (start, + end - start); +} + + /* end of util.c */ |