From d88829cfa8dc7bf2967fb494af0290e068466828 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Thu, 23 Jul 2020 17:35:17 +0530 Subject: towards refunds with updated protocol --- src/util/codec.ts | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++ src/util/taleruri.ts | 2 +- 2 files changed, 57 insertions(+), 1 deletion(-) (limited to 'src/util') 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(s: V): Codec { }; } +/** + * Return a codec for a boolean true constant. + */ +export function makeCodecForConstTrue(): Codec { + 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 { + 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(n: V): Codec { + 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( innerCodec: Codec, ): Codec { 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) + "/"; } -- cgit v1.2.3