diff options
author | Florian Dold <florian.dold@gmail.com> | 2017-04-27 04:06:48 +0200 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2017-04-27 04:06:48 +0200 |
commit | ce97b1076b7e4a53b84d3fd34bf2047580ddeb22 (patch) | |
tree | be365d6cf69b9c6a9b7841869727e57c1a152ad3 /src/types.ts | |
parent | 82b5754e157a1a3b22afe48c8366c76525eb91e3 (diff) | |
download | wallet-core-ce97b1076b7e4a53b84d3fd34bf2047580ddeb22.tar.xz |
fix signature checks, add wire fee
Diffstat (limited to 'src/types.ts')
-rw-r--r-- | src/types.ts | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/src/types.ts b/src/types.ts index c6111bd09..5d53f8db0 100644 --- a/src/types.ts +++ b/src/types.ts @@ -526,10 +526,10 @@ export class Contract { fulfillment_url: string; @Checkable.Number - wire_fee_amortization: number; + wire_fee_amortization?: number; @Checkable.Value(AmountJson) - max_wire_fee: AmountJson; + max_wire_fee?: AmountJson; @Checkable.Any extra: any; @@ -661,6 +661,21 @@ export namespace Amounts { } } + export function divide(a: AmountJson, n: number): AmountJson { + if (n == 0) { + throw Error(`Division by 0`); + } + if (n == 1) { + return {value: a.value, fraction: a.fraction, currency: a.currency}; + } + let r = a.value % n; + return { + currency: a.currency, + value: Math.floor(a.value / n), + fraction: Math.floor(((r * fractionalBase) + a.fraction) / n), + } + } + export function isNonZero(a: AmountJson) { return a.value > 0 || a.fraction > 0; } |