summaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2020-07-23 17:35:17 +0530
committerFlorian Dold <florian.dold@gmail.com>2020-07-23 17:35:17 +0530
commitd88829cfa8dc7bf2967fb494af0290e068466828 (patch)
tree682faf6027e572e2c28b548d65b0045692b2da29 /src/util
parente60563fb540c04d9ba751fea69c1fc0f1de598b5 (diff)
downloadwallet-core-d88829cfa8dc7bf2967fb494af0290e068466828.tar.gz
wallet-core-d88829cfa8dc7bf2967fb494af0290e068466828.tar.bz2
wallet-core-d88829cfa8dc7bf2967fb494af0290e068466828.zip
towards refunds with updated protocol
Diffstat (limited to 'src/util')
-rw-r--r--src/util/codec.ts56
-rw-r--r--src/util/taleruri.ts2
2 files changed, 57 insertions, 1 deletions
diff --git a/src/util/codec.ts b/src/util/codec.ts
index 136c5b053..c468704b2 100644
--- a/src/util/codec.ts
+++ b/src/util/codec.ts
@@ -18,6 +18,8 @@
* Type-safe codecs for converting from/to JSON.
*/
+ /* eslint-disable @typescript-eslint/ban-types */
+
/**
* Error thrown when decoding fails.
*/
@@ -335,6 +337,60 @@ export function makeCodecForConstString<V extends string>(s: V): Codec<V> {
};
}
+/**
+ * Return a codec for a boolean true constant.
+ */
+export function makeCodecForConstTrue(): Codec<true> {
+ return {
+ decode(x: any, c?: Context): true {
+ if (x === true) {
+ return x;
+ }
+ throw new DecodingError(
+ `expected boolean true at ${renderContext(
+ c,
+ )} but got ${typeof x}`,
+ );
+ },
+ };
+}
+
+/**
+ * Return a codec for a boolean true constant.
+ */
+export function makeCodecForConstFalse(): Codec<false> {
+ return {
+ decode(x: any, c?: Context): false {
+ if (x === false) {
+ return x;
+ }
+ throw new DecodingError(
+ `expected boolean false at ${renderContext(
+ c,
+ )} but got ${typeof x}`,
+ );
+ },
+ };
+}
+
+/**
+ * Return a codec for a value that must be a constant number.
+ */
+export function makeCodecForConstNumber<V extends number>(n: V): Codec<V> {
+ return {
+ decode(x: any, c?: Context): V {
+ if (x === n) {
+ return x;
+ }
+ throw new DecodingError(
+ `expected number constant "${n}" at ${renderContext(
+ c,
+ )} but got ${typeof x}`,
+ );
+ },
+ };
+}
+
export function makeCodecOptional<V>(
innerCodec: Codec<V>,
): Codec<V | undefined> {
diff --git a/src/util/taleruri.ts b/src/util/taleruri.ts
index 30209d48a..73280b6c8 100644
--- a/src/util/taleruri.ts
+++ b/src/util/taleruri.ts
@@ -220,7 +220,7 @@ export function parseRefundUri(s: string): RefundUriResult | undefined {
}
if (maybePath === "-") {
- maybePath = "public/";
+ maybePath = "";
} else {
maybePath = decodeURIComponent(maybePath) + "/";
}