aboutsummaryrefslogtreecommitdiff
path: root/src/types.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/types.ts')
-rw-r--r--src/types.ts19
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;
}