wallet effective config

This commit is contained in:
Sebastian 2023-04-24 12:53:20 -03:00
parent 3004ece1f8
commit 205d7364ed
No known key found for this signature in database
GPG Key ID: 173909D1A5F66069
5 changed files with 64 additions and 38 deletions

View File

@ -257,6 +257,8 @@ export interface BankAccessApiClientArgs {
baseUrl: string; baseUrl: string;
username: string; username: string;
password: string; password: string;
enableThrottling?: boolean;
allowHttp?: boolean;
} }
export interface BankAccessApiCreateTransactionRequest { export interface BankAccessApiCreateTransactionRequest {
@ -268,22 +270,30 @@ export class WireGatewayApiClientArgs {
accountName: string; accountName: string;
accountPassword: string; accountPassword: string;
wireGatewayApiBaseUrl: string; wireGatewayApiBaseUrl: string;
enableThrottling?: boolean;
allowHttp?: boolean;
} }
/**
* This API look like it belongs to harness
* but it will be nice to have in utils to be used by others
*/
export class WireGatewayApiClient { export class WireGatewayApiClient {
httpLib = createPlatformHttpLib(); httpLib;
constructor(private args: WireGatewayApiClientArgs) {} constructor(private args: WireGatewayApiClientArgs) {
this.httpLib = createPlatformHttpLib({
enableThrottling: !!args.enableThrottling,
allowHttp: !!args.allowHttp,
});
}
async adminAddIncoming(params: { async adminAddIncoming(params: {
amount: string; amount: string;
reservePub: string; reservePub: string;
debitAccountPayto: string; debitAccountPayto: string;
}): Promise<void> { }): Promise<void> {
let url = new URL( let url = new URL(`admin/add-incoming`, this.args.wireGatewayApiBaseUrl);
`admin/add-incoming`,
this.args.wireGatewayApiBaseUrl,
);
const resp = await this.httpLib.fetch(url.href, { const resp = await this.httpLib.fetch(url.href, {
method: "POST", method: "POST",
body: { body: {
@ -303,10 +313,19 @@ export class WireGatewayApiClient {
} }
} }
/**
* This API look like it belongs to harness
* but it will be nice to have in utils to be used by others
*/
export class BankAccessApiClient { export class BankAccessApiClient {
httpLib = createPlatformHttpLib(); httpLib;
constructor(private args: BankAccessApiClientArgs) {} constructor(private args: BankAccessApiClientArgs) {
this.httpLib = createPlatformHttpLib({
enableThrottling: !!args.enableThrottling,
allowHttp: !!args.allowHttp,
});
}
async getTransactions(): Promise<void> { async getTransactions(): Promise<void> {
const reqUrl = new URL( const reqUrl = new URL(

View File

@ -104,6 +104,7 @@ export async function createNativeWalletHost2(
} else { } else {
myHttpLib = createPlatformHttpLib({ myHttpLib = createPlatformHttpLib({
enableThrottling: true, enableThrottling: true,
allowHttp: args.config?.features?.allowHttp,
}); });
} }

View File

@ -89,7 +89,10 @@ export async function createNativeWalletHost2(
if (args.httpLib) { if (args.httpLib) {
myHttpLib = args.httpLib; myHttpLib = args.httpLib;
} else { } else {
myHttpLib = createPlatformHttpLib(); myHttpLib = createPlatformHttpLib({
enableThrottling: true,
allowHttp: args.config?.features?.allowHttp,
});
} }
const myVersionChange = (): Promise<void> => { const myVersionChange = (): Promise<void> => {

View File

@ -247,6 +247,7 @@ export interface WalletConfig {
denomselAllowLate: boolean; denomselAllowLate: boolean;
devModeActive: boolean; devModeActive: boolean;
insecureTrustExchange: boolean; insecureTrustExchange: boolean;
preventThrottling: boolean;
}; };
/** /**

View File

@ -1564,7 +1564,7 @@ export class Wallet {
http, http,
timer, timer,
cryptoWorkerFactory, cryptoWorkerFactory,
config ?? {}, Wallet.getEffectiveConfig(config),
); );
} }
@ -1587,8 +1587,33 @@ export class Wallet {
return w; return w;
} }
static getDefaultConfig(): Readonly<WalletConfig> { public static defaultConfig: Readonly<WalletConfig> = {
return InternalWalletStateImpl.defaultConfig; builtin: {
exchanges: ["https://exchange.demo.taler.net/"],
auditors: [
{
currency: "KUDOS",
auditorPub: "BW9DC48PHQY4NH011SHHX36DZZ3Q22Y6X7FZ1VD1CMZ2PTFZ6PN0",
auditorBaseUrl: "https://auditor.demo.taler.net/",
uids: ["5P25XF8TVQP9AW6VYGY2KV47WT5Y3ZXFSJAA570GJPX5SVJXKBVG"],
},
],
},
features: {
batchWithdrawal: false,
allowHttp: false,
},
testing: {
devModeActive: false,
insecureTrustExchange: false,
denomselAllowLate: false,
},
};
static getEffectiveConfig(
param?: WalletConfigParameter,
): Readonly<WalletConfig> {
return deepMerge(Wallet.defaultConfig, param ?? {});
} }
addNotificationListener(f: (n: WalletNotification) => void): void { addNotificationListener(f: (n: WalletNotification) => void): void {
@ -1674,29 +1699,6 @@ class InternalWalletStateImpl implements InternalWalletState {
config: Readonly<WalletConfig>; config: Readonly<WalletConfig>;
public static defaultConfig: Readonly<WalletConfig> = {
builtin: {
exchanges: ["https://exchange.demo.taler.net/"],
auditors: [
{
currency: "KUDOS",
auditorPub: "BW9DC48PHQY4NH011SHHX36DZZ3Q22Y6X7FZ1VD1CMZ2PTFZ6PN0",
auditorBaseUrl: "https://auditor.demo.taler.net/",
uids: ["5P25XF8TVQP9AW6VYGY2KV47WT5Y3ZXFSJAA570GJPX5SVJXKBVG"],
},
],
},
features: {
batchWithdrawal: false,
allowHttp: false,
},
testing: {
devModeActive: false,
insecureTrustExchange: false,
denomselAllowLate: false,
},
};
constructor( constructor(
// FIXME: Make this a getter and make // FIXME: Make this a getter and make
// the actual value nullable. // the actual value nullable.
@ -1706,12 +1708,12 @@ class InternalWalletStateImpl implements InternalWalletState {
public http: HttpRequestLibrary, public http: HttpRequestLibrary,
public timer: TimerAPI, public timer: TimerAPI,
cryptoWorkerFactory: CryptoWorkerFactory, cryptoWorkerFactory: CryptoWorkerFactory,
config: WalletConfigParameter, configParam: WalletConfig,
) { ) {
this.cryptoDispatcher = new CryptoDispatcher(cryptoWorkerFactory); this.cryptoDispatcher = new CryptoDispatcher(cryptoWorkerFactory);
this.cryptoApi = this.cryptoDispatcher.cryptoApi; this.cryptoApi = this.cryptoDispatcher.cryptoApi;
this.timerGroup = new TimerGroup(timer); this.timerGroup = new TimerGroup(timer);
this.config = deepMerge(InternalWalletStateImpl.defaultConfig, config); this.config = configParam;
if (this.config.testing.devModeActive) { if (this.config.testing.devModeActive) {
this.http = new DevExperimentHttpLib(this.http); this.http = new DevExperimentHttpLib(this.http);
} }
@ -1823,7 +1825,7 @@ class InternalWalletStateImpl implements InternalWalletState {
* @param override * @param override
* @returns * @returns
*/ */
function deepMerge<T extends object>(full: T, override: any): T { function deepMerge<T extends object>(full: T, override: object): T {
const keys = Object.keys(full); const keys = Object.keys(full);
const result = { ...full }; const result = { ...full };
for (const k of keys) { for (const k of keys) {