-wallet-core: merge DenominationInfo and DenomInfo
This commit is contained in:
parent
16e7814445
commit
183c836614
@ -682,21 +682,6 @@ const codecForWireInfo = (): Codec<WireInfo> =>
|
|||||||
.property("accounts", codecForList(codecForExchangeAccount()))
|
.property("accounts", codecForList(codecForExchangeAccount()))
|
||||||
.build("codecForWireInfo");
|
.build("codecForWireInfo");
|
||||||
|
|
||||||
const codecForDenominationInfo = (): Codec<DenominationInfo> =>
|
|
||||||
buildCodecForObject<DenominationInfo>()
|
|
||||||
.property("denomPubHash", codecForString())
|
|
||||||
.property("value", codecForAmountJson())
|
|
||||||
.property("feeWithdraw", codecForAmountJson())
|
|
||||||
.property("feeDeposit", codecForAmountJson())
|
|
||||||
.property("feeRefresh", codecForAmountJson())
|
|
||||||
.property("feeRefund", codecForAmountJson())
|
|
||||||
.property("stampStart", codecForTimestamp)
|
|
||||||
.property("stampExpireWithdraw", codecForTimestamp)
|
|
||||||
.property("stampExpireLegal", codecForTimestamp)
|
|
||||||
.property("stampExpireDeposit", codecForTimestamp)
|
|
||||||
.property("exchangeBaseUrl", codecForString())
|
|
||||||
.build("codecForDenominationInfo");
|
|
||||||
|
|
||||||
export interface DenominationInfo {
|
export interface DenominationInfo {
|
||||||
/**
|
/**
|
||||||
* Value of one coin of the denomination.
|
* Value of one coin of the denomination.
|
||||||
@ -709,6 +694,8 @@ export interface DenominationInfo {
|
|||||||
*/
|
*/
|
||||||
denomPubHash: string;
|
denomPubHash: string;
|
||||||
|
|
||||||
|
denomPub: DenominationPubKey;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fee for withdrawing.
|
* Fee for withdrawing.
|
||||||
*/
|
*/
|
||||||
|
@ -44,10 +44,10 @@ import {
|
|||||||
PeerContractTerms,
|
PeerContractTerms,
|
||||||
Location,
|
Location,
|
||||||
WireInfo,
|
WireInfo,
|
||||||
|
DenominationInfo,
|
||||||
} from "@gnu-taler/taler-util";
|
} from "@gnu-taler/taler-util";
|
||||||
import { RetryInfo, RetryTags } from "./util/retries.js";
|
import { RetryInfo, RetryTags } from "./util/retries.js";
|
||||||
import { Event, IDBDatabase } from "@gnu-taler/idb-bridge";
|
import { Event, IDBDatabase } from "@gnu-taler/idb-bridge";
|
||||||
import { DenomInfo } from "./internal-wallet-state.js";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Name of the Taler database. This is effectively the major
|
* Name of the Taler database. This is effectively the major
|
||||||
@ -330,7 +330,7 @@ export namespace DenominationRecord {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function toDenomInfo(d: DenominationRecord): DenomInfo {
|
export function toDenomInfo(d: DenominationRecord): DenominationInfo {
|
||||||
return {
|
return {
|
||||||
denomPub: d.denomPub,
|
denomPub: d.denomPub,
|
||||||
denomPubHash: d.denomPubHash,
|
denomPubHash: d.denomPubHash,
|
||||||
|
@ -125,14 +125,6 @@ export interface RecoupOperations {
|
|||||||
): Promise<void>;
|
): Promise<void>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type DenomInfo = DenominationInfo & {
|
|
||||||
/**
|
|
||||||
* The denomination public key.
|
|
||||||
*/
|
|
||||||
denomPub: DenominationPubKey;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
export type NotificationListener = (n: WalletNotification) => void;
|
export type NotificationListener = (n: WalletNotification) => void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -184,7 +176,7 @@ export interface InternalWalletState {
|
|||||||
}>,
|
}>,
|
||||||
exchangeBaseUrl: string,
|
exchangeBaseUrl: string,
|
||||||
denomPubHash: string,
|
denomPubHash: string,
|
||||||
): Promise<DenomInfo | undefined>;
|
): Promise<DenominationInfo | undefined>;
|
||||||
|
|
||||||
db: DbAccess<typeof WalletStoresV1>;
|
db: DbAccess<typeof WalletStoresV1>;
|
||||||
http: HttpRequestLibrary;
|
http: HttpRequestLibrary;
|
||||||
|
@ -53,8 +53,6 @@ import {
|
|||||||
DenominationVerificationStatus,
|
DenominationVerificationStatus,
|
||||||
ExchangeDetailsRecord,
|
ExchangeDetailsRecord,
|
||||||
ExchangeRecord,
|
ExchangeRecord,
|
||||||
OperationAttemptResult,
|
|
||||||
OperationAttemptResultType,
|
|
||||||
WalletStoresV1,
|
WalletStoresV1,
|
||||||
} from "../db.js";
|
} from "../db.js";
|
||||||
import { TalerError } from "../errors.js";
|
import { TalerError } from "../errors.js";
|
||||||
@ -66,7 +64,7 @@ import {
|
|||||||
readSuccessResponseTextOrThrow,
|
readSuccessResponseTextOrThrow,
|
||||||
} from "../util/http.js";
|
} from "../util/http.js";
|
||||||
import { DbAccess, GetReadOnlyAccess } from "../util/query.js";
|
import { DbAccess, GetReadOnlyAccess } from "../util/query.js";
|
||||||
import { RetryInfo, runOperationHandlerForResult } from "../util/retries.js";
|
import { OperationAttemptResult, OperationAttemptResultType, RetryInfo, runOperationHandlerForResult } from "../util/retries.js";
|
||||||
import { WALLET_EXCHANGE_PROTOCOL_VERSION } from "../versions.js";
|
import { WALLET_EXCHANGE_PROTOCOL_VERSION } from "../versions.js";
|
||||||
import { guardOperationException } from "./common.js";
|
import { guardOperationException } from "./common.js";
|
||||||
|
|
||||||
|
@ -25,6 +25,7 @@ import {
|
|||||||
codecForExchangeRevealResponse,
|
codecForExchangeRevealResponse,
|
||||||
CoinPublicKey,
|
CoinPublicKey,
|
||||||
CoinPublicKeyString,
|
CoinPublicKeyString,
|
||||||
|
DenominationInfo,
|
||||||
DenomKeyType,
|
DenomKeyType,
|
||||||
Duration,
|
Duration,
|
||||||
durationFromSpec,
|
durationFromSpec,
|
||||||
@ -42,7 +43,6 @@ import {
|
|||||||
NotificationType,
|
NotificationType,
|
||||||
RefreshGroupId,
|
RefreshGroupId,
|
||||||
RefreshReason,
|
RefreshReason,
|
||||||
TalerErrorDetail,
|
|
||||||
TalerProtocolTimestamp,
|
TalerProtocolTimestamp,
|
||||||
URL,
|
URL,
|
||||||
} from "@gnu-taler/taler-util";
|
} from "@gnu-taler/taler-util";
|
||||||
@ -64,7 +64,6 @@ import {
|
|||||||
} from "../db.js";
|
} from "../db.js";
|
||||||
import { TalerError } from "../errors.js";
|
import { TalerError } from "../errors.js";
|
||||||
import {
|
import {
|
||||||
DenomInfo,
|
|
||||||
EXCHANGE_COINS_LOCK,
|
EXCHANGE_COINS_LOCK,
|
||||||
InternalWalletState,
|
InternalWalletState,
|
||||||
} from "../internal-wallet-state.js";
|
} from "../internal-wallet-state.js";
|
||||||
@ -74,9 +73,11 @@ import {
|
|||||||
} from "../util/http.js";
|
} from "../util/http.js";
|
||||||
import { checkDbInvariant } from "../util/invariants.js";
|
import { checkDbInvariant } from "../util/invariants.js";
|
||||||
import { GetReadWriteAccess } from "../util/query.js";
|
import { GetReadWriteAccess } from "../util/query.js";
|
||||||
import { OperationAttemptResult, OperationAttemptResultType, RetryInfo, runOperationHandlerForResult } from "../util/retries.js";
|
import {
|
||||||
import { makeCoinAvailable, Wallet } from "../wallet.js";
|
OperationAttemptResult,
|
||||||
import { guardOperationException } from "./common.js";
|
OperationAttemptResultType,
|
||||||
|
} from "../util/retries.js";
|
||||||
|
import { makeCoinAvailable } from "../wallet.js";
|
||||||
import { updateExchangeFromUrl } from "./exchanges.js";
|
import { updateExchangeFromUrl } from "./exchanges.js";
|
||||||
import {
|
import {
|
||||||
isWithdrawableDenom,
|
isWithdrawableDenom,
|
||||||
@ -98,7 +99,7 @@ const logger = new Logger("refresh.ts");
|
|||||||
*/
|
*/
|
||||||
export function getTotalRefreshCost(
|
export function getTotalRefreshCost(
|
||||||
denoms: DenominationRecord[],
|
denoms: DenominationRecord[],
|
||||||
refreshedDenom: DenomInfo,
|
refreshedDenom: DenominationInfo,
|
||||||
amountLeft: AmountJson,
|
amountLeft: AmountJson,
|
||||||
): AmountJson {
|
): AmountJson {
|
||||||
const withdrawAmount = Amounts.sub(
|
const withdrawAmount = Amounts.sub(
|
||||||
|
@ -92,6 +92,7 @@ import {
|
|||||||
FeeDescription,
|
FeeDescription,
|
||||||
TalerErrorDetail,
|
TalerErrorDetail,
|
||||||
codecForTransactionByIdRequest,
|
codecForTransactionByIdRequest,
|
||||||
|
DenominationInfo,
|
||||||
} from "@gnu-taler/taler-util";
|
} from "@gnu-taler/taler-util";
|
||||||
import { TalerCryptoInterface } from "./crypto/cryptoImplementation.js";
|
import { TalerCryptoInterface } from "./crypto/cryptoImplementation.js";
|
||||||
import {
|
import {
|
||||||
@ -115,7 +116,6 @@ import {
|
|||||||
} from "./errors.js";
|
} from "./errors.js";
|
||||||
import { createDenominationTimeline } from "./index.browser.js";
|
import { createDenominationTimeline } from "./index.browser.js";
|
||||||
import {
|
import {
|
||||||
DenomInfo,
|
|
||||||
ExchangeOperations,
|
ExchangeOperations,
|
||||||
InternalWalletState,
|
InternalWalletState,
|
||||||
MerchantInfo,
|
MerchantInfo,
|
||||||
@ -746,7 +746,7 @@ async function getExchangeDetailedInfo(
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const denominations: DenomInfo[] = denominationRecords.map((x) =>
|
const denominations: DenominationInfo[] = denominationRecords.map((x) =>
|
||||||
DenominationRecord.toDenomInfo(x),
|
DenominationRecord.toDenomInfo(x),
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -1572,7 +1572,7 @@ class InternalWalletStateImpl implements InternalWalletState {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// FIXME: Use an LRU cache here.
|
// FIXME: Use an LRU cache here.
|
||||||
private denomCache: Record<string, DenomInfo> = {};
|
private denomCache: Record<string, DenominationInfo> = {};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Promises that are waiting for a particular resource.
|
* Promises that are waiting for a particular resource.
|
||||||
@ -1606,7 +1606,7 @@ class InternalWalletStateImpl implements InternalWalletState {
|
|||||||
}>,
|
}>,
|
||||||
exchangeBaseUrl: string,
|
exchangeBaseUrl: string,
|
||||||
denomPubHash: string,
|
denomPubHash: string,
|
||||||
): Promise<DenomInfo | undefined> {
|
): Promise<DenominationInfo | undefined> {
|
||||||
const key = `${exchangeBaseUrl}:${denomPubHash}`;
|
const key = `${exchangeBaseUrl}:${denomPubHash}`;
|
||||||
const cached = this.denomCache[key];
|
const cached = this.denomCache[key];
|
||||||
if (cached) {
|
if (cached) {
|
||||||
|
Loading…
Reference in New Issue
Block a user