aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/operations/reserves.ts1
-rw-r--r--src/types/ReserveTransaction.ts22
-rw-r--r--src/types/dbTypes.ts75
-rw-r--r--src/util/helpers.ts5
-rw-r--r--tsconfig.json2
5 files changed, 93 insertions, 12 deletions
diff --git a/src/operations/reserves.ts b/src/operations/reserves.ts
index 5cf189d3b..2e1b487b9 100644
--- a/src/operations/reserves.ts
+++ b/src/operations/reserves.ts
@@ -115,6 +115,7 @@ export async function createReserve(
retryInfo: initRetryInfo(),
lastError: undefined,
reserveTransactions: [],
+ history: [],
};
const senderWire = req.senderWire;
diff --git a/src/types/ReserveTransaction.ts b/src/types/ReserveTransaction.ts
index 3b2553def..cebccd2dc 100644
--- a/src/types/ReserveTransaction.ts
+++ b/src/types/ReserveTransaction.ts
@@ -39,7 +39,7 @@ import { Timestamp, codecForTimestamp } from "../util/time";
export const enum ReserveTransactionType {
Withdraw = "WITHDRAW",
- Deposit = "CREDIT",
+ Credit = "CREDIT",
Recoup = "RECOUP",
Closing = "CLOSING",
}
@@ -74,8 +74,8 @@ export interface ReserveWithdrawTransaction {
withdraw_fee: AmountString;
}
-export interface ReserveDepositTransaction {
- type: ReserveTransactionType.Deposit;
+export interface ReserveCreditTransaction {
+ type: ReserveTransactionType.Credit;
/**
* Amount withdrawn.
@@ -175,7 +175,7 @@ export interface ReserveRecoupTransaction {
*/
export type ReserveTransaction =
| ReserveWithdrawTransaction
- | ReserveDepositTransaction
+ | ReserveCreditTransaction
| ReserveClosingTransaction
| ReserveRecoupTransaction;
@@ -194,15 +194,15 @@ export const codecForReserveWithdrawTransaction = () =>
.build("ReserveWithdrawTransaction"),
);
-export const codecForReserveDepositTransaction = () =>
- typecheckedCodec<ReserveDepositTransaction>(
- makeCodecForObject<ReserveDepositTransaction>()
+export const codecForReserveCreditTransaction = () =>
+ typecheckedCodec<ReserveCreditTransaction>(
+ makeCodecForObject<ReserveCreditTransaction>()
.property("amount", codecForString)
.property("sender_account_url", codecForString)
.property("timestamp", codecForTimestamp)
.property("wire_reference", codecForString)
- .property("type", makeCodecForConstString(ReserveTransactionType.Deposit))
- .build("ReserveDepositTransaction"),
+ .property("type", makeCodecForConstString(ReserveTransactionType.Credit))
+ .build("ReserveCreditTransaction"),
);
export const codecForReserveClosingTransaction = () =>
@@ -248,8 +248,8 @@ export const codecForReserveTransaction = () =>
codecForReserveRecoupTransaction(),
)
.alternative(
- ReserveTransactionType.Deposit,
- codecForReserveDepositTransaction(),
+ ReserveTransactionType.Credit,
+ codecForReserveCreditTransaction(),
)
.build<ReserveTransaction>("ReserveTransaction"),
);
diff --git a/src/types/dbTypes.ts b/src/types/dbTypes.ts
index db71db710..c88148e7e 100644
--- a/src/types/dbTypes.ts
+++ b/src/types/dbTypes.ts
@@ -35,8 +35,9 @@ import {
import { Index, Store } from "../util/query";
import { OperationError, RefreshReason } from "./walletTypes";
-import { ReserveTransaction } from "./ReserveTransaction";
+import { ReserveTransaction, ReserveCreditTransaction, ReserveWithdrawTransaction, ReserveClosingTransaction, ReserveRecoupTransaction } from "./ReserveTransaction";
import { Timestamp, Duration, getTimestampNow } from "../util/time";
+import { Wallet } from "../wallet";
export enum ReserveRecordStatus {
/**
@@ -131,6 +132,71 @@ export function initRetryInfo(
return info;
}
+export const enum WalletReserveHistoryItemType {
+ Credit = "credit",
+ Withdraw = "withdraw",
+ Closing = "closing",
+ Recoup = "recoup",
+}
+
+export interface WalletReserveHistoryCreditItem {
+ type: WalletReserveHistoryItemType.Credit;
+
+ /**
+ * Amount we expect to see credited.
+ */
+ expectedAmount?: string;
+
+ /**
+ * Item from the reserve transaction history that this
+ * wallet reserve history item matches up with.
+ */
+ matchedExchangeTransaction?: ReserveCreditTransaction;
+}
+
+export interface WalletReserveHistoryWithdrawItem {
+ expectedAmount?: string;
+
+ type: WalletReserveHistoryItemType.Withdraw;
+
+ /**
+ * Item from the reserve transaction history that this
+ * wallet reserve history item matches up with.
+ */
+ matchedExchangeTransaction?: ReserveWithdrawTransaction;
+}
+
+export interface WalletReserveHistoryClosingItem {
+ type: WalletReserveHistoryItemType.Closing;
+
+ /**
+ * Item from the reserve transaction history that this
+ * wallet reserve history item matches up with.
+ */
+ matchedExchangeTransaction?: ReserveClosingTransaction;
+}
+
+export interface WalletReserveHistoryRecoupItem {
+ type: WalletReserveHistoryItemType.Recoup;
+
+ /**
+ * Amount we expect to see recouped.
+ */
+ expectedAmount?: string;
+
+ /**
+ * Item from the reserve transaction history that this
+ * wallet reserve history item matches up with.
+ */
+ matchedExchangeTransaction?: ReserveRecoupTransaction;
+}
+
+export type WalletReserveHistoryItem =
+ | WalletReserveHistoryCreditItem
+ | WalletReserveHistoryWithdrawItem
+ | WalletReserveHistoryRecoupItem
+ | WalletReserveHistoryClosingItem;
+
/**
* A reserve record as stored in the wallet's database.
*/
@@ -234,6 +300,13 @@ export interface ReserveRecord {
lastError: OperationError | undefined;
reserveTransactions: ReserveTransaction[];
+
+ /**
+ * History of the reserve as modeled by the wallet.
+ * Reconciled with the history kept by the exchange
+ * when we request the reserve status.
+ */
+ history: WalletReserveHistoryItem[];
}
/**
diff --git a/src/util/helpers.ts b/src/util/helpers.ts
index 130dcdaef..0e19d7aba 100644
--- a/src/util/helpers.ts
+++ b/src/util/helpers.ts
@@ -102,6 +102,11 @@ export function deepEquals(x: any, y: any): boolean {
);
}
+export function deepCopy(x: any): any {
+ // FIXME: this has many issues ...
+ return JSON.parse(JSON.stringify(x));
+}
+
/**
* Map from a collection to a list or results and then
* concatenate the results.
diff --git a/tsconfig.json b/tsconfig.json
index 6808b3374..f87e16b11 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -86,6 +86,8 @@
"src/util/payto.ts",
"src/util/promiseUtils.ts",
"src/util/query.ts",
+ "src/util/reserveHistoryUtil-test.ts",
+ "src/util/reserveHistoryUtil.ts",
"src/util/talerconfig.ts",
"src/util/taleruri-test.ts",
"src/util/taleruri.ts",