From 0c9358c1b2bd80e25940022e86bd8daef8184ad7 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Thu, 19 Dec 2019 20:42:49 +0100 Subject: new date format, replace checkable annotations with codecs --- src/util/amounts.ts | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) (limited to 'src/util/amounts.ts') diff --git a/src/util/amounts.ts b/src/util/amounts.ts index c8fb76793..c85c4839a 100644 --- a/src/util/amounts.ts +++ b/src/util/amounts.ts @@ -1,17 +1,17 @@ /* - This file is part of TALER - (C) 2018 GNUnet e.V. and INRIA + This file is part of GNU Taler + (C) 2019 Taler Systems S.A. - TALER is free software; you can redistribute it and/or modify it under the + GNU Taler is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3, or (at your option) any later version. - TALER is distributed in the hope that it will be useful, but WITHOUT ANY + GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with - TALER; see the file COPYING. If not, see + GNU Taler; see the file COPYING. If not, see */ /** @@ -21,7 +21,12 @@ /** * Imports. */ -import { Checkable } from "./checkable"; +import { + typecheckedCodec, + makeCodecForObject, + codecForString, + codecForNumber, +} from "./codec"; /** * Number of fractional units that one value unit represents. @@ -44,29 +49,32 @@ export const maxAmountValue = 2 ** 52; * Non-negative financial amount. Fractional values are expressed as multiples * of 1e-8. */ -@Checkable.Class() -export class AmountJson { +export interface AmountJson { /** * Value, must be an integer. */ - @Checkable.Number() readonly value: number; /** * Fraction, must be an integer. Represent 1/1e8 of a unit. */ - @Checkable.Number() readonly fraction: number; /** * Currency of the amount. */ - @Checkable.String() readonly currency: string; - - static checked: (obj: any) => AmountJson; } +export const codecForAmountJson = () => + typecheckedCodec( + makeCodecForObject() + .property("currency", codecForString) + .property("value", codecForNumber) + .property("fraction", codecForNumber) + .build("AmountJson"), + ); + /** * Result of a possibly overflowing operation. */ -- cgit v1.2.3