helpers and tests for reserve reconciliation
This commit is contained in:
parent
63cf437633
commit
62de27d2ac
@ -115,6 +115,7 @@ export async function createReserve(
|
|||||||
retryInfo: initRetryInfo(),
|
retryInfo: initRetryInfo(),
|
||||||
lastError: undefined,
|
lastError: undefined,
|
||||||
reserveTransactions: [],
|
reserveTransactions: [],
|
||||||
|
history: [],
|
||||||
};
|
};
|
||||||
|
|
||||||
const senderWire = req.senderWire;
|
const senderWire = req.senderWire;
|
||||||
|
@ -39,7 +39,7 @@ import { Timestamp, codecForTimestamp } from "../util/time";
|
|||||||
|
|
||||||
export const enum ReserveTransactionType {
|
export const enum ReserveTransactionType {
|
||||||
Withdraw = "WITHDRAW",
|
Withdraw = "WITHDRAW",
|
||||||
Deposit = "CREDIT",
|
Credit = "CREDIT",
|
||||||
Recoup = "RECOUP",
|
Recoup = "RECOUP",
|
||||||
Closing = "CLOSING",
|
Closing = "CLOSING",
|
||||||
}
|
}
|
||||||
@ -74,8 +74,8 @@ export interface ReserveWithdrawTransaction {
|
|||||||
withdraw_fee: AmountString;
|
withdraw_fee: AmountString;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ReserveDepositTransaction {
|
export interface ReserveCreditTransaction {
|
||||||
type: ReserveTransactionType.Deposit;
|
type: ReserveTransactionType.Credit;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Amount withdrawn.
|
* Amount withdrawn.
|
||||||
@ -175,7 +175,7 @@ export interface ReserveRecoupTransaction {
|
|||||||
*/
|
*/
|
||||||
export type ReserveTransaction =
|
export type ReserveTransaction =
|
||||||
| ReserveWithdrawTransaction
|
| ReserveWithdrawTransaction
|
||||||
| ReserveDepositTransaction
|
| ReserveCreditTransaction
|
||||||
| ReserveClosingTransaction
|
| ReserveClosingTransaction
|
||||||
| ReserveRecoupTransaction;
|
| ReserveRecoupTransaction;
|
||||||
|
|
||||||
@ -194,15 +194,15 @@ export const codecForReserveWithdrawTransaction = () =>
|
|||||||
.build("ReserveWithdrawTransaction"),
|
.build("ReserveWithdrawTransaction"),
|
||||||
);
|
);
|
||||||
|
|
||||||
export const codecForReserveDepositTransaction = () =>
|
export const codecForReserveCreditTransaction = () =>
|
||||||
typecheckedCodec<ReserveDepositTransaction>(
|
typecheckedCodec<ReserveCreditTransaction>(
|
||||||
makeCodecForObject<ReserveDepositTransaction>()
|
makeCodecForObject<ReserveCreditTransaction>()
|
||||||
.property("amount", codecForString)
|
.property("amount", codecForString)
|
||||||
.property("sender_account_url", codecForString)
|
.property("sender_account_url", codecForString)
|
||||||
.property("timestamp", codecForTimestamp)
|
.property("timestamp", codecForTimestamp)
|
||||||
.property("wire_reference", codecForString)
|
.property("wire_reference", codecForString)
|
||||||
.property("type", makeCodecForConstString(ReserveTransactionType.Deposit))
|
.property("type", makeCodecForConstString(ReserveTransactionType.Credit))
|
||||||
.build("ReserveDepositTransaction"),
|
.build("ReserveCreditTransaction"),
|
||||||
);
|
);
|
||||||
|
|
||||||
export const codecForReserveClosingTransaction = () =>
|
export const codecForReserveClosingTransaction = () =>
|
||||||
@ -248,8 +248,8 @@ export const codecForReserveTransaction = () =>
|
|||||||
codecForReserveRecoupTransaction(),
|
codecForReserveRecoupTransaction(),
|
||||||
)
|
)
|
||||||
.alternative(
|
.alternative(
|
||||||
ReserveTransactionType.Deposit,
|
ReserveTransactionType.Credit,
|
||||||
codecForReserveDepositTransaction(),
|
codecForReserveCreditTransaction(),
|
||||||
)
|
)
|
||||||
.build<ReserveTransaction>("ReserveTransaction"),
|
.build<ReserveTransaction>("ReserveTransaction"),
|
||||||
);
|
);
|
||||||
|
@ -35,8 +35,9 @@ import {
|
|||||||
|
|
||||||
import { Index, Store } from "../util/query";
|
import { Index, Store } from "../util/query";
|
||||||
import { OperationError, RefreshReason } from "./walletTypes";
|
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 { Timestamp, Duration, getTimestampNow } from "../util/time";
|
||||||
|
import { Wallet } from "../wallet";
|
||||||
|
|
||||||
export enum ReserveRecordStatus {
|
export enum ReserveRecordStatus {
|
||||||
/**
|
/**
|
||||||
@ -131,6 +132,71 @@ export function initRetryInfo(
|
|||||||
return info;
|
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.
|
* A reserve record as stored in the wallet's database.
|
||||||
*/
|
*/
|
||||||
@ -234,6 +300,13 @@ export interface ReserveRecord {
|
|||||||
lastError: OperationError | undefined;
|
lastError: OperationError | undefined;
|
||||||
|
|
||||||
reserveTransactions: ReserveTransaction[];
|
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[];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -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
|
* Map from a collection to a list or results and then
|
||||||
* concatenate the results.
|
* concatenate the results.
|
||||||
|
@ -86,6 +86,8 @@
|
|||||||
"src/util/payto.ts",
|
"src/util/payto.ts",
|
||||||
"src/util/promiseUtils.ts",
|
"src/util/promiseUtils.ts",
|
||||||
"src/util/query.ts",
|
"src/util/query.ts",
|
||||||
|
"src/util/reserveHistoryUtil-test.ts",
|
||||||
|
"src/util/reserveHistoryUtil.ts",
|
||||||
"src/util/talerconfig.ts",
|
"src/util/talerconfig.ts",
|
||||||
"src/util/taleruri-test.ts",
|
"src/util/taleruri-test.ts",
|
||||||
"src/util/taleruri.ts",
|
"src/util/taleruri.ts",
|
||||||
|
Loading…
Reference in New Issue
Block a user