implement currencies subcommand

This commit is contained in:
Florian Dold 2021-05-12 16:18:32 +02:00
parent 4da4380480
commit f4ec5b1a32
No known key found for this signature in database
GPG Key ID: D2E4F00F29D02A4B
5 changed files with 54 additions and 14 deletions

View File

@ -22,7 +22,7 @@
/**
* Imports.
*/
import { TalerErrorDetails } from "./walletTypes";
import { TalerErrorDetails } from "./walletTypes.js";
export enum NotificationType {
CoinWithdrawn = "coin-withdrawn",

View File

@ -604,6 +604,19 @@ advancedCli
});
});
const currenciesCli = walletCli.subcommand("currencies", "currencies", {
help: "Manage currencies.",
});
currenciesCli
.subcommand("show", "show", { help: "Show currencies."})
.action(async (args) => {
await withWallet(args, async (wallet) => {
const currencies = await wallet.getCurrencies();
console.log(JSON.stringify(currencies, undefined, 2));
});
})
const reservesCli = advancedCli.subcommand("reserves", "reserves", {
help: "Manage reserves.",
});

View File

@ -357,20 +357,41 @@ export interface AuditorRecord {
expirationStamp: number;
}
/**
* Exchange for currencies as stored in the wallet's currency
* information database.
*/
export interface ExchangeForCurrencyRecord {
export interface AuditorTrustInfo {
/**
* FIXME: unused?
* Base URL of the auditor.
*/
auditorBaseUrl: string;
/**
* Public key of the auditor.
*/
auditorPub: string;
/**
* UIDs for the operation of adding this auditor
* as a trusted auditor.
*/
uids: string[];
}
export interface ExchangeTrustInfo {
/**
* Canonicalized exchange base URL.
*/
exchangeBaseUrl: string;
/**
* Master public key of the exchange.
*/
exchangeMasterPub: string;
/**
* Base URL of the exchange.
* UIDs for the operation of adding this exchange
* as trusted.
*/
exchangeBaseUrl: string;
uids: string[];
}
/**
@ -390,12 +411,12 @@ export interface CurrencyRecord {
/**
* Auditors that the wallet trusts for this currency.
*/
auditors: AuditorRecord[];
auditors: AuditorTrustInfo[];
/**
* Exchanges that the wallet trusts for this currency.
*/
exchanges: ExchangeForCurrencyRecord[];
exchanges: ExchangeTrustInfo[];
}
/**

View File

@ -175,6 +175,7 @@ export async function createReserve(
currencyRecord.exchanges.push({
exchangeBaseUrl: req.exchange,
exchangeMasterPub: exchangeDetails.masterPublicKey,
uids: [encodeCrock(getRandomBytes(32))],
});
}

View File

@ -22,7 +22,11 @@
/**
* Imports.
*/
import { BackupRecovery, codecForAny, TalerErrorCode } from "@gnu-taler/taler-util";
import {
BackupRecovery,
codecForAny,
TalerErrorCode,
} from "@gnu-taler/taler-util";
import { CryptoWorkerFactory } from "./crypto/workers/cryptoApi";
import {
addBackupProvider,
@ -181,8 +185,8 @@ const builtinCurrencies: CurrencyRecord[] = [
auditors: [
{
auditorPub: "BW9DC48PHQY4NH011SHHX36DZZ3Q22Y6X7FZ1VD1CMZ2PTFZ6PN0",
baseUrl: "https://auditor.demo.taler.net/",
expirationStamp: new Date(2027, 1).getTime(),
auditorBaseUrl: "https://auditor.demo.taler.net/",
uids: ["5P25XF8TVQP9AW6VYGY2KV47WT5Y3ZXFSJAA570GJPX5SVJXKBVG"],
},
],
exchanges: [],
@ -672,6 +676,7 @@ export class Wallet {
return await this.db.iter(Stores.exchanges).toArray();
}
async getExchanges(): Promise<ExchangesListRespose> {
const exchanges: (ExchangeListItem | undefined)[] = await this.db
.iter(Stores.exchanges)