aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2020-08-12 16:02:58 +0530
committerFlorian Dold <florian.dold@gmail.com>2020-08-12 16:02:58 +0530
commit8d7b171d02e0ab4d5da7dc81eaea6c27106dbc57 (patch)
tree1ee7138d008cf8dcf2cd2a9f5a646701932d1ee5
parent56f5a1e3abe2679b4913ac87ff82860bb9675823 (diff)
rename for consistency
-rw-r--r--packages/taler-integrationtests/src/harness.ts8
-rw-r--r--packages/taler-integrationtests/src/merchantApiTypes.ts45
-rw-r--r--packages/taler-wallet-cli/src/index.ts4
-rw-r--r--packages/taler-wallet-core/src/operations/testing.ts4
-rw-r--r--packages/taler-wallet-core/src/operations/transactions.ts1
-rw-r--r--packages/taler-wallet-core/src/types/ReserveStatus.ts10
-rw-r--r--packages/taler-wallet-core/src/types/ReserveTransaction.ts60
-rw-r--r--packages/taler-wallet-core/src/types/talerTypes.ts337
-rw-r--r--packages/taler-wallet-core/src/types/transactions.ts10
-rw-r--r--packages/taler-wallet-core/src/types/walletTypes.ts58
-rw-r--r--packages/taler-wallet-core/src/util/amounts.ts12
-rw-r--r--packages/taler-wallet-core/src/util/codec-test.ts24
-rw-r--r--packages/taler-wallet-core/src/util/codec.ts76
-rw-r--r--packages/taler-wallet-core/src/walletCoreApiHandler.ts58
14 files changed, 356 insertions, 351 deletions
diff --git a/packages/taler-integrationtests/src/harness.ts b/packages/taler-integrationtests/src/harness.ts
index 84b5bc5c4..ecb0758da 100644
--- a/packages/taler-integrationtests/src/harness.ts
+++ b/packages/taler-integrationtests/src/harness.ts
@@ -35,7 +35,7 @@ import {
AmountJson,
Amounts,
Codec,
- makeCodecForObject,
+ buildCodecForObject,
codecForString,
Duration,
CoreApiResponse,
@@ -627,9 +627,9 @@ export interface WithdrawalOperationInfo {
}
const codecForWithdrawalOperationInfo = (): Codec<WithdrawalOperationInfo> =>
- makeCodecForObject<WithdrawalOperationInfo>()
- .property("withdrawal_id", codecForString)
- .property("taler_withdraw_uri", codecForString)
+ buildCodecForObject<WithdrawalOperationInfo>()
+ .property("withdrawal_id", codecForString())
+ .property("taler_withdraw_uri", codecForString())
.build("WithdrawalOperationInfo");
export const defaultCoinConfig = [
diff --git a/packages/taler-integrationtests/src/merchantApiTypes.ts b/packages/taler-integrationtests/src/merchantApiTypes.ts
index 3c0965813..d08c354a1 100644
--- a/packages/taler-integrationtests/src/merchantApiTypes.ts
+++ b/packages/taler-integrationtests/src/merchantApiTypes.ts
@@ -28,19 +28,20 @@ import {
ContractTerms,
Duration,
Codec,
- makeCodecForObject,
+ buildCodecForObject,
codecForString,
- makeCodecOptional,
- makeCodecForConstString,
+ codecOptional,
+ codecForConstString,
codecForBoolean,
codecForNumber,
codecForContractTerms,
codecForAny,
- makeCodecForUnion,
+ buildCodecForUnion,
AmountString,
Timestamp,
CoinPublicKeyString,
} from "taler-wallet-core";
+import { codecForAmountString } from "taler-wallet-core/lib/util/amounts";
export interface PostOrderRequest {
// The order must at least contain the minimal
@@ -72,43 +73,43 @@ export interface PostOrderResponse {
}
export const codecForPostOrderResponse = (): Codec<PostOrderResponse> =>
- makeCodecForObject<PostOrderResponse>()
- .property("order_id", codecForString)
- .property("token", makeCodecOptional(codecForString))
+ buildCodecForObject<PostOrderResponse>()
+ .property("order_id", codecForString())
+ .property("token", codecOptional(codecForString()))
.build("PostOrderResponse");
export const codecForCheckPaymentPaidResponse = (): Codec<
CheckPaymentPaidResponse
> =>
- makeCodecForObject<CheckPaymentPaidResponse>()
- .property("order_status", makeCodecForConstString("paid"))
+ buildCodecForObject<CheckPaymentPaidResponse>()
+ .property("order_status", codecForConstString("paid"))
.property("refunded", codecForBoolean)
.property("wired", codecForBoolean)
- .property("deposit_total", codecForString)
- .property("exchange_ec", codecForNumber)
- .property("exchange_hc", codecForNumber)
- .property("refund_amount", codecForString)
+ .property("deposit_total", codecForAmountString())
+ .property("exchange_ec", codecForNumber())
+ .property("exchange_hc", codecForNumber())
+ .property("refund_amount", codecForAmountString())
.property("contract_terms", codecForContractTerms())
// FIXME: specify
- .property("wire_details", codecForAny)
- .property("wire_reports", codecForAny)
- .property("refund_details", codecForAny)
+ .property("wire_details", codecForAny())
+ .property("wire_reports", codecForAny())
+ .property("refund_details", codecForAny())
.build("CheckPaymentPaidResponse");
export const codecForCheckPaymentUnpaidResponse = (): Codec<
CheckPaymentUnpaidResponse
> =>
- makeCodecForObject<CheckPaymentUnpaidResponse>()
- .property("order_status", makeCodecForConstString("unpaid"))
- .property("taler_pay_uri", codecForString)
- .property("order_status_url", codecForString)
- .property("already_paid_order_id", makeCodecOptional(codecForString))
+ buildCodecForObject<CheckPaymentUnpaidResponse>()
+ .property("order_status", codecForConstString("unpaid"))
+ .property("taler_pay_uri", codecForString())
+ .property("order_status_url", codecForString())
+ .property("already_paid_order_id", codecOptional(codecForString()))
.build("CheckPaymentPaidResponse");
export const codecForMerchantOrderPrivateStatusResponse = (): Codec<
MerchantOrderPrivateStatusResponse
> =>
- makeCodecForUnion<MerchantOrderPrivateStatusResponse>()
+ buildCodecForUnion<MerchantOrderPrivateStatusResponse>()
.discriminateOn("order_status")
.alternative("paid", codecForCheckPaymentPaidResponse())
.alternative("unpaid", codecForCheckPaymentUnpaidResponse())
diff --git a/packages/taler-wallet-cli/src/index.ts b/packages/taler-wallet-cli/src/index.ts
index 16897b7aa..a32ed2267 100644
--- a/packages/taler-wallet-cli/src/index.ts
+++ b/packages/taler-wallet-cli/src/index.ts
@@ -31,7 +31,7 @@ import {
TalerUriType,
decodeCrock,
addPaytoQueryParams,
- makeCodecForList,
+ codecForList,
codecForString,
printTestVectors,
} from "taler-wallet-core";
@@ -548,7 +548,7 @@ advancedCli
});
});
-const coinPubListCodec = makeCodecForList(codecForString);
+const coinPubListCodec = codecForList(codecForString());
advancedCli
.subcommand("suspendCoins", "suspend-coins", {
diff --git a/packages/taler-wallet-core/src/operations/testing.ts b/packages/taler-wallet-core/src/operations/testing.ts
index 71cee1f3a..3ccfafc93 100644
--- a/packages/taler-wallet-core/src/operations/testing.ts
+++ b/packages/taler-wallet-core/src/operations/testing.ts
@@ -112,7 +112,7 @@ async function createBankWithdrawalUri(
},
},
);
- const respJson = await readSuccessResponseJsonOrThrow(resp, codecForAny);
+ const respJson = await readSuccessResponseJsonOrThrow(resp, codecForAny());
return respJson;
}
@@ -135,7 +135,7 @@ async function confirmBankWithdrawalUri(
},
},
);
- await readSuccessResponseJsonOrThrow(resp, codecForAny);
+ await readSuccessResponseJsonOrThrow(resp, codecForAny());
return;
}
diff --git a/packages/taler-wallet-core/src/operations/transactions.ts b/packages/taler-wallet-core/src/operations/transactions.ts
index 8de204d49..5521dda90 100644
--- a/packages/taler-wallet-core/src/operations/transactions.ts
+++ b/packages/taler-wallet-core/src/operations/transactions.ts
@@ -37,7 +37,6 @@ import {
PaymentShortInfo,
} from "../types/transactions";
import { getFundingPaytoUris } from "./reserves";
-import { ResultLevel } from "idb-bridge";
/**
* Create an event ID from the type and the primary key for the event.
diff --git a/packages/taler-wallet-core/src/types/ReserveStatus.ts b/packages/taler-wallet-core/src/types/ReserveStatus.ts
index 18601b9a7..8a6092a7f 100644
--- a/packages/taler-wallet-core/src/types/ReserveStatus.ts
+++ b/packages/taler-wallet-core/src/types/ReserveStatus.ts
@@ -23,8 +23,8 @@
*/
import {
codecForString,
- makeCodecForObject,
- makeCodecForList,
+ buildCodecForObject,
+ codecForList,
Codec,
} from "../util/codec";
import { AmountString } from "./talerTypes";
@@ -51,7 +51,7 @@ export interface ReserveStatus {
}
export const codecForReserveStatus = (): Codec<ReserveStatus> =>
- makeCodecForObject<ReserveStatus>()
- .property("balance", codecForString)
- .property("history", makeCodecForList(codecForReserveTransaction()))
+ buildCodecForObject<ReserveStatus>()
+ .property("balance", codecForString())
+ .property("history", codecForList(codecForReserveTransaction()))
.build("ReserveStatus");
diff --git a/packages/taler-wallet-core/src/types/ReserveTransaction.ts b/packages/taler-wallet-core/src/types/ReserveTransaction.ts
index bdd9b0f93..0d946518f 100644
--- a/packages/taler-wallet-core/src/types/ReserveTransaction.ts
+++ b/packages/taler-wallet-core/src/types/ReserveTransaction.ts
@@ -23,9 +23,9 @@
*/
import {
codecForString,
- makeCodecForObject,
- makeCodecForConstString,
- makeCodecForUnion,
+ buildCodecForObject,
+ codecForConstString,
+ buildCodecForUnion,
Codec,
} from "../util/codec";
import {
@@ -182,54 +182,54 @@ export type ReserveTransaction =
export const codecForReserveWithdrawTransaction = (): Codec<
ReserveWithdrawTransaction
> =>
- makeCodecForObject<ReserveWithdrawTransaction>()
- .property("amount", codecForString)
- .property("h_coin_envelope", codecForString)
- .property("h_denom_pub", codecForString)
- .property("reserve_sig", codecForString)
- .property("type", makeCodecForConstString(ReserveTransactionType.Withdraw))
- .property("withdraw_fee", codecForString)
+ buildCodecForObject<ReserveWithdrawTransaction>()
+ .property("amount", codecForString())
+ .property("h_coin_envelope", codecForString())
+ .property("h_denom_pub", codecForString())
+ .property("reserve_sig", codecForString())
+ .property("type", codecForConstString(ReserveTransactionType.Withdraw))
+ .property("withdraw_fee", codecForString())
.build("ReserveWithdrawTransaction");
export const codecForReserveCreditTransaction = (): Codec<
ReserveCreditTransaction
> =>
- makeCodecForObject<ReserveCreditTransaction>()
- .property("amount", codecForString)
- .property("sender_account_url", codecForString)
+ buildCodecForObject<ReserveCreditTransaction>()
+ .property("amount", codecForString())
+ .property("sender_account_url", codecForString())
.property("timestamp", codecForTimestamp)
- .property("wire_reference", codecForString)
- .property("type", makeCodecForConstString(ReserveTransactionType.Credit))
+ .property("wire_reference", codecForString())
+ .property("type", codecForConstString(ReserveTransactionType.Credit))
.build("ReserveCreditTransaction");
export const codecForReserveClosingTransaction = (): Codec<
ReserveClosingTransaction
> =>
- makeCodecForObject<ReserveClosingTransaction>()
- .property("amount", codecForString)
- .property("closing_fee", codecForString)
- .property("exchange_pub", codecForString)
- .property("exchange_sig", codecForString)
- .property("h_wire", codecForString)
+ buildCodecForObject<ReserveClosingTransaction>()
+ .property("amount", codecForString())
+ .property("closing_fee", codecForString())
+ .property("exchange_pub", codecForString())
+ .property("exchange_sig", codecForString())
+ .property("h_wire", codecForString())
.property("timestamp", codecForTimestamp)
- .property("type", makeCodecForConstString(ReserveTransactionType.Closing))
- .property("wtid", codecForString)
+ .property("type", codecForConstString(ReserveTransactionType.Closing))
+ .property("wtid", codecForString())
.build("ReserveClosingTransaction");
export const codecForReserveRecoupTransaction = (): Codec<
ReserveRecoupTransaction
> =>
- makeCodecForObject<ReserveRecoupTransaction>()
- .property("amount", codecForString)
- .property("coin_pub", codecForString)
- .property("exchange_pub", codecForString)
- .property("exchange_sig", codecForString)
+ buildCodecForObject<ReserveRecoupTransaction>()
+ .property("amount", codecForString())
+ .property("coin_pub", codecForString())
+ .property("exchange_pub", codecForString())
+ .property("exchange_sig", codecForString())
.property("timestamp", codecForTimestamp)
- .property("type", makeCodecForConstString(ReserveTransactionType.Recoup))
+ .property("type", codecForConstString(ReserveTransactionType.Recoup))
.build("ReserveRecoupTransaction");
export const codecForReserveTransaction = (): Codec<ReserveTransaction> =>
- makeCodecForUnion<ReserveTransaction>()
+ buildCodecForUnion<ReserveTransaction>()
.discriminateOn("type")
.alternative(
ReserveTransactionType.Withdraw,
diff --git a/packages/taler-wallet-core/src/types/talerTypes.ts b/packages/taler-wallet-core/src/types/talerTypes.ts
index acebbda95..bb0118a78 100644
--- a/packages/taler-wallet-core/src/types/talerTypes.ts
+++ b/packages/taler-wallet-core/src/types/talerTypes.ts
@@ -28,18 +28,18 @@
*/
import {
- makeCodecForObject,
+ buildCodecForObject,
codecForString,
- makeCodecForList,
- makeCodecOptional,
+ codecForList,
+ codecOptional,
codecForAny,
codecForNumber,
codecForBoolean,
- makeCodecForMap,
+ codecForMap,
Codec,
- makeCodecForConstNumber,
- makeCodecForUnion,
- makeCodecForConstString,
+ codecForConstNumber,
+ buildCodecForUnion,
+ codecForConstString,
} from "../util/codec";
import {
Timestamp,
@@ -48,6 +48,7 @@ import {
codecForDuration,
} from "../util/time";
import { ExchangeListItem } from "./walletTypes";
+import { codecForAmountString } from "../util/amounts";
/**
* Denomination as found in the /keys response from the exchange.
@@ -951,7 +952,7 @@ export interface BankWithdrawalOperationPostResponse {
export const codecForBankWithdrawalOperationPostResponse = (): Codec<
BankWithdrawalOperationPostResponse
> =>
- makeCodecForObject<BankWithdrawalOperationPostResponse>()
+ buildCodecForObject<BankWithdrawalOperationPostResponse>()
.property("transfer_done", codecForBoolean)
.build("BankWithdrawalOperationPostResponse");
@@ -962,292 +963,292 @@ export type EddsaPublicKeyString = string;
export type CoinPublicKeyString = string;
export const codecForDenomination = (): Codec<Denomination> =>
- makeCodecForObject<Denomination>()
- .property("value", codecForString)
- .property("denom_pub", codecForString)
- .property("fee_withdraw", codecForString)
- .property("fee_deposit", codecForString)
- .property("fee_refresh", codecForString)
- .property("fee_refund", codecForString)
+ buildCodecForObject<Denomination>()
+ .property("value", codecForString())
+ .property("denom_pub", codecForString())
+ .property("fee_withdraw", codecForString())
+ .property("fee_deposit", codecForString())
+ .property("fee_refresh", codecForString())
+ .property("fee_refund", codecForString())
.property("stamp_start", codecForTimestamp)
.property("stamp_expire_withdraw", codecForTimestamp)
.property("stamp_expire_legal", codecForTimestamp)
.property("stamp_expire_deposit", codecForTimestamp)
- .property("master_sig", codecForString)
+ .property("master_sig", codecForString())
.build("Denomination");
export const codecForAuditorDenomSig = (): Codec<AuditorDenomSig> =>
- makeCodecForObject<AuditorDenomSig>()
- .property("denom_pub_h", codecForString)
- .property("auditor_sig", codecForString)
+ buildCodecForObject<AuditorDenomSig>()
+ .property("denom_pub_h", codecForString())
+ .property("auditor_sig", codecForString())
.build("AuditorDenomSig");
export const codecForAuditor = (): Codec<Auditor> =>
- makeCodecForObject<Auditor>()
- .property("auditor_pub", codecForString)
- .property("auditor_url", codecForString)
- .property("denomination_keys", makeCodecForList(codecForAuditorDenomSig()))
+ buildCodecForObject<Auditor>()
+ .property("auditor_pub", codecForString())
+ .property("auditor_url", codecForString())
+ .property("denomination_keys", codecForList(codecForAuditorDenomSig()))
.build("Auditor");
export const codecForExchangeHandle = (): Codec<ExchangeHandle> =>
- makeCodecForObject<ExchangeHandle>()
- .property("master_pub", codecForString)
- .property("url", codecForString)
+ buildCodecForObject<ExchangeHandle>()
+ .property("master_pub", codecForString())
+ .property("url", codecForString())
.build("ExchangeHandle");
export const codecForAuditorHandle = (): Codec<AuditorHandle> =>
- makeCodecForObject<AuditorHandle>()
- .property("name", codecForString)
- .property("master_pub", codecForString)
- .property("url", codecForString)
+ buildCodecForObject<AuditorHandle>()
+ .property("name", codecForString())
+ .property("master_pub", codecForString())
+ .property("url", codecForString())
.build("AuditorHandle");
export const codecForMerchantInfo = (): Codec<MerchantInfo> =>
- makeCodecForObject<MerchantInfo>()
- .property("name", codecForString)
- .property("address", makeCodecOptional(codecForString))
- .property("jurisdiction", makeCodecOptional(codecForString))
+ buildCodecForObject<MerchantInfo>()
+ .property("name", codecForString())
+ .property("address", codecOptional(codecForString()))
+ .property("jurisdiction", codecOptional(codecForString()))
.build("MerchantInfo");
export const codecForTax = (): Codec<Tax> =>
- makeCodecForObject<Tax>()
- .property("name", codecForString)
- .property("tax", codecForString)
+ buildCodecForObject<Tax>()
+ .property("name", codecForString())
+ .property("tax", codecForString())
.build("Tax");
export const codecForI18n = (): Codec<{ [lang_tag: string]: string }> =>
- makeCodecForMap(codecForString);
+ codecForMap(codecForString());
export const codecForProduct = (): Codec<Product> =>
- makeCodecForObject<Product>()
- .property("product_id", makeCodecOptional(codecForString))
- .property("description", codecForString)
- .property("description_i18n", makeCodecOptional(codecForI18n()))
- .property("quantity", makeCodecOptional(codecForNumber))
- .property("unit", makeCodecOptional(codecForString))
- .property("price", makeCodecOptional(codecForString))
- .property("delivery_date", makeCodecOptional(codecForTimestamp))
- .property("delivery_location", makeCodecOptional(codecForString))
+ buildCodecForObject<Product>()
+ .property("product_id", codecOptional(codecForString()))
+ .property("description", codecForString())
+ .property("description_i18n", codecOptional(codecForI18n()))
+ .property("quantity", codecOptional(codecForNumber()))
+ .property("unit", codecOptional(codecForString()))
+ .property("price", codecOptional(codecForString()))
+ .property("delivery_date", codecOptional(codecForTimestamp))
+ .property("delivery_location", codecOptional(codecForString()))
.build("Tax");
export const codecForContractTerms = (): Codec<ContractTerms> =>
- makeCodecForObject<ContractTerms>()
- .property("order_id", codecForString)
- .property("fulfillment_url", codecForString)
- .property("merchant_base_url", codecForString)
- .property("h_wire", codecForString)
- .property("auto_refund", makeCodecOptional(codecForDuration))
- .property("wire_method", codecForString)
- .property("summary", codecForString)
- .property("summary_i18n", makeCodecOptional(codecForI18n()))
- .property("nonce", codecForString)
- .property("amount", codecForString)
- .property("auditors", makeCodecForList(codecForAuditorHandle()))
+ buildCodecForObject<ContractTerms>()
+ .property("order_id", codecForString())
+ .property("fulfillment_url", codecForString())
+ .property("merchant_base_url", codecForString())
+ .property("h_wire", codecForString())
+ .property("auto_refund", codecOptional(codecForDuration))
+ .property("wire_method", codecForString())
+ .property("summary", codecForString())
+ .property("summary_i18n", codecOptional(codecForI18n()))
+ .property("nonce", codecForString())
+ .property("amount", codecForString())
+ .property("auditors", codecForList(codecForAuditorHandle()))
.property("pay_deadline", codecForTimestamp)
.property("refund_deadline", codecForTimestamp)
.property("wire_transfer_deadline", codecForTimestamp)
.property("timestamp", codecForTimestamp)
- .property("locations", codecForAny)
- .property("max_fee", codecForString)
- .property("max_wire_fee", makeCodecOptional(codecForString))
+ .property("locations", codecForAny())
+ .property("max_fee", codecForString())
+ .property("max_wire_fee", codecOptional(codecForString()))
.property("merchant", codecForMerchantInfo())
- .property("merchant_pub", codecForString)
- .property("exchanges", makeCodecForList(codecForExchangeHandle()))
+ .property("merchant_pub", codecForString())
+ .property("exchanges", codecForList(codecForExchangeHandle()))
.property(
"products",
- makeCodecOptional(makeCodecForList(codecForProduct())),
+ codecOptional(codecForList(codecForProduct())),
)
- .property("extra", codecForAny)
+ .property("extra", codecForAny())
.build("ContractTerms");
export const codecForMerchantRefundPermission = (): Codec<
MerchantAbortPayRefundDetails
> =>
- makeCodecForObject<MerchantAbortPayRefundDetails>()
- .property("refund_amount", codecForString)
- .property("refund_fee", codecForString)
- .property("coin_pub", codecForString)
- .property("rtransaction_id", codecForNumber)
- .property("exchange_http_status", codecForNumber)
- .property("exchange_code", makeCodecOptional(codecForNumber))
- .property("exchange_reply", makeCodecOptional(codecForAny))
- .property("exchange_sig", makeCodecOptional(codecForString))
- .property("exchange_pub", makeCodecOptional(codecForString))
+ buildCodecForObject<MerchantAbortPayRefundDetails>()
+ .property("refund_amount", codecForAmountString())
+ .property("refund_fee", codecForAmountString())
+ .property("coin_pub", codecForString())
+ .property("rtransaction_id", codecForNumber())
+ .property("exchange_http_status", codecForNumber())
+ .property("exchange_code", codecOptional(codecForNumber()))
+ .property("exchange_reply", codecOptional(codecForAny()))
+ .property("exchange_sig", codecOptional(codecForString()))
+ .property("exchange_pub", codecOptional(codecForString()))
.build("MerchantRefundPermission");
export const codecForMerchantRefundResponse = (): Codec<
MerchantRefundResponse
> =>
- makeCodecForObject<MerchantRefundResponse>()
- .property("merchant_pub", codecForString)
- .property("h_contract_terms", codecForString)
- .property("refunds", makeCodecForList(codecForMerchantRefundPermission()))
+ buildCodecForObject<MerchantRefundResponse>()
+ .property("merchant_pub", codecForString())
+ .property("h_contract_terms", codecForString())
+ .property("refunds", codecForList(codecForMerchantRefundPermission()))
.build("MerchantRefundResponse");
export const codecForReserveSigSingleton = (): Codec<ReserveSigSingleton> =>
- makeCodecForObject<ReserveSigSingleton>()
- .property("reserve_sig", codecForString)
+ buildCodecForObject<ReserveSigSingleton>()
+ .property("reserve_sig", codecForString())
.build("ReserveSigSingleton");
export const codecForTipResponse = (): Codec<TipResponse> =>
- makeCodecForObject<TipResponse>()
- .property("reserve_pub", codecForString)
- .property("reserve_sigs", makeCodecForList(codecForReserveSigSingleton()))
+ buildCodecForObject<TipResponse>()
+ .property("reserve_pub", codecForString())
+ .property("reserve_sigs", codecForList(codecForReserveSigSingleton()))
.build("TipResponse");
export const codecForRecoup = (): Codec<Recoup> =>
- makeCodecForObject<Recoup>()
- .property("h_denom_pub", codecForString)
+ buildCodecForObject<Recoup>()
+ .property("h_denom_pub", codecForString())
.build("Recoup");
export const codecForExchangeSigningKey = (): Codec<ExchangeSignKeyJson> =>
- makeCodecForObject<ExchangeSignKeyJson>()
- .property("key", codecForString)
- .property("master_sig", codecForString)
+ buildCodecForObject<ExchangeSignKeyJson>()
+ .property("key", codecForString())
+ .property("master_sig", codecForString())
.property("stamp_end", codecForTimestamp)
.property("stamp_start", codecForTimestamp)
.property("stamp_expire", codecForTimestamp)
.build("ExchangeSignKeyJson");
export const codecForExchangeKeysJson = (): Codec<ExchangeKeysJson> =>
- makeCodecForObject<ExchangeKeysJson>()
- .property("denoms", makeCodecForList(codecForDenomination()))
- .property("master_public_key", codecForString)
- .property("auditors", makeCodecForList(codecForAuditor()))
+ buildCodecForObject<ExchangeKeysJson>()
+ .property("denoms", codecForList(codecForDenomination()))
+ .property("master_public_key", codecForString())
+ .property("auditors", codecForList(codecForAuditor()))
.property("list_issue_date", codecForTimestamp)
- .property("recoup", makeCodecOptional(makeCodecForList(codecForRecoup())))
- .property("signkeys", makeCodecForList(codecForExchangeSigningKey()))
- .property("version", codecForString)
+ .property("recoup", codecOptional(codecForList(codecForRecoup())))
+ .property("signkeys", codecForList(codecForExchangeSigningKey()))
+ .property("version", codecForString())
.build("KeysJson");
export const codecForWireFeesJson = (): Codec<WireFeesJson> =>
- makeCodecForObject<WireFeesJson>()
- .property("wire_fee", codecForString)
- .property("closing_fee", codecForString)
- .property("sig", codecForString)
+ buildCodecForObject<WireFeesJson>()
+ .property("wire_fee", codecForString())
+ .property("closing_fee", codecForString())
+ .property("sig", codecForString())
.property("start_date", codecForTimestamp)
.property("end_date", codecForTimestamp)
.build("WireFeesJson");
export const codecForAccountInfo = (): Codec<AccountInfo> =>
- makeCodecForObject<AccountInfo>()
- .property("payto_uri", codecForString)
- .property("master_sig", codecForString)
+ buildCodecForObject<AccountInfo>()
+ .property("payto_uri", codecForString())
+ .property("master_sig", codecForString())
.build("AccountInfo");
export const codecForExchangeWireJson = (): Codec<ExchangeWireJson> =>
- makeCodecForObject<ExchangeWireJson>()
- .property("accounts", makeCodecForList(codecForAccountInfo()))
- .property("fees", makeCodecForMap(makeCodecForList(codecForWireFeesJson())))
+ buildCodecForObject<ExchangeWireJson>()
+ .property("accounts", codecForList(codecForAccountInfo()))
+ .property("fees", codecForMap(codecForList(codecForWireFeesJson())))
.build("ExchangeWireJson");
export const codecForProposal = (): Codec<Proposal> =>
- makeCodecForObject<Proposal>()
- .property("contract_terms", codecForAny)
- .property("sig", codecForString)
+ buildCodecForObject<Proposal>()
+ .property("contract_terms", codecForAny())
+ .property("sig", codecForString())
.build("Proposal");
export const codecForCheckPaymentResponse = (): Codec<CheckPaymentResponse> =>
- makeCodecForObject<CheckPaymentResponse>()
- .property("order_status", codecForString)
- .property("refunded", makeCodecOptional(codecForBoolean))
- .property("refunded_amount", makeCodecOptional(codecForString))
- .property("contract_terms", makeCodecOptional(codecForAny))
- .property("taler_pay_uri", makeCodecOptional(codecForString))
- .property("contract_url", makeCodecOptional(codecForString))
+ buildCodecForObject<CheckPaymentResponse>()
+ .property("order_status", codecForString())
+ .property("refunded", codecOptional(codecForBoolean))
+ .property("refunded_amount", codecOptional(codecForString()))
+ .property("contract_terms", codecOptional(codecForAny()))
+ .property("taler_pay_uri", codecOptional(codecForString()))
+ .property("contract_url", codecOptional(codecForString()))
.build("CheckPaymentResponse");
export const codecForWithdrawOperationStatusResponse = (): Codec<
WithdrawOperationStatusResponse
> =>
- makeCodecForObject<WithdrawOperationStatusResponse>()
+ buildCodecForObject<WithdrawOperationStatusResponse>()
.property("selection_done", codecForBoolean)
.property("transfer_done", codecForBoolean)
- .property("amount", codecForString)
- .property("sender_wire", makeCodecOptional(codecForString))
- .property("suggested_exchange", makeCodecOptional(codecForString))
- .property("confirm_transfer_url", makeCodecOptional(codecForString))
- .property("wire_types", makeCodecForList(codecForString))
+ .property("amount", codecForString())
+ .property("sender_wire", codecOptional(codecForString()))
+ .property("suggested_exchange", codecOptional(codecForString()))
+ .property("confirm_transfer_url", codecOptional(codecForString()))
+ .property("wire_types", codecForList(codecForString()))
.build("WithdrawOperationStatusResponse");
export const codecForTipPickupGetResponse = (): Codec<TipPickupGetResponse> =>
- makeCodecForObject<TipPickupGetResponse>()
- .property("extra", codecForAny)
- .property("amount", codecForString)
- .property("amount_left", codecForString)
- .property("exchange_url", codecForString)
+ buildCodecForObject<TipPickupGetResponse>()
+ .property("extra", codecForAny())
+ .property("amount", codecForString())
+ .property("amount_left", codecForString())
+ .property("exchange_url", codecForString())
.property("stamp_expire", codecForTimestamp)
.property("stamp_created", codecForTimestamp)
.build("TipPickupGetResponse");
export const codecForRecoupConfirmation = (): Codec<RecoupConfirmation> =>
- makeCodecForObject<RecoupConfirmation>()
- .property("reserve_pub", makeCodecOptional(codecForString))
- .property("old_coin_pub", makeCodecOptional(codecForString))
+ buildCodecForObject<RecoupConfirmation>()
+ .property("reserve_pub", codecOptional(codecForString()))
+ .property("old_coin_pub", codecOptional(codecForString()))
.build("RecoupConfirmation");
export const codecForWithdrawResponse = (): Codec<WithdrawResponse> =>
- makeCodecForObject<WithdrawResponse>()
- .property("ev_sig", codecForString)
+ buildCodecForObject<WithdrawResponse>()
+ .property("ev_sig", codecForString())
.build("WithdrawResponse");
export const codecForMerchantPayResponse = (): Codec<MerchantPayResponse> =>
- makeCodecForObject<MerchantPayResponse>()
- .property("sig", codecForString)
+ buildCodecForObject<MerchantPayResponse>()
+ .property("sig", codecForString())
.build("MerchantPayResponse");
export const codecForExchangeMeltResponse = (): Codec<ExchangeMeltResponse> =>
- makeCodecForObject<ExchangeMeltResponse>()
- .property("exchange_pub", codecForString)
- .property("exchange_sig", codecForString)
- .property("noreveal_index", codecForNumber)
- .property("refresh_base_url", makeCodecOptional(codecForString))
+ buildCodecForObject<ExchangeMeltResponse>()
+ .property("exchange_pub", codecForString())
+ .property("exchange_sig", codecForString())
+ .property("noreveal_index", codecForNumber())
+ .property("refresh_base_url", codecOptional(codecForString()))
.build("ExchangeMeltResponse");
export const codecForExchangeRevealItem = (): Codec<ExchangeRevealItem> =>
- makeCodecForObject<ExchangeRevealItem>()
- .property("ev_sig", codecForString)
+ buildCodecForObject<ExchangeRevealItem>()
+ .property("ev_sig", codecForString())
.build("ExchangeRevealItem");
export const codecForExchangeRevealResponse = (): Codec<
ExchangeRevealResponse
> =>
- makeCodecForObject<ExchangeRevealResponse>()
- .property("ev_sigs", makeCodecForList(codecForExchangeRevealItem()))
+ buildCodecForObject<ExchangeRevealResponse>()
+ .property("ev_sigs", codecForList(codecForExchangeRevealItem()))
.build("ExchangeRevealResponse");
export const codecForMerchantCoinRefundSuccessStatus = (): Codec<
MerchantCoinRefundSuccessStatus
> =>
- makeCodecForObject<MerchantCoinRefundSuccessStatus>()
- .property("type", makeCodecForConstString("success"))
- .property("coin_pub", codecForString)
- .property("exchange_status", makeCodecForConstNumber(200))
- .property("exchange_sig", codecForString)
- .property("rtransaction_id", codecForNumber)
- .property("refund_amount", codecForString)
- .property("exchange_pub", codecForString)
+ buildCodecForObject<MerchantCoinRefundSuccessStatus>()
+ .property("type", codecForConstString("success"))
+ .property("coin_pub", codecForString())
+ .property("exchange_status", codecForConstNumber(200))
+ .property("exchange_sig", codecForString())
+ .property("rtransaction_id", codecForNumber())
+ .property("refund_amount", codecForString())
+ .property("exchange_pub", codecForString())
.property("execution_time", codecForTimestamp)
.build("MerchantCoinRefundSuccessStatus");
export const codecForMerchantCoinRefundFailureStatus = (): Codec<
MerchantCoinRefundFailureStatus
> =>
- makeCodecForObject<MerchantCoinRefundFailureStatus>()
- .property("type", makeCodecForConstString("failure"))
- .property("coin_pub", codecForString)
- .property("exchange_status", makeCodecForConstNumber(200))
- .property("rtransaction_id", codecForNumber)
- .property("refund_amount", codecForString)
- .property("exchange_code", makeCodecOptional(codecForNumber))
- .property("exchange_reply", makeCodecOptional(codecForAny))
+ buildCodecForObject<MerchantCoinRefundFailureStatus>()
+ .property("type", codecForConstString("failure"))
+ .property("coin_pub", codecForString())
+ .property("exchange_status", codecForConstNumber(200))
+ .property("rtransaction_id", codecForNumber())
+ .property("refund_amount", codecForString())
+ .property("exchange_code", codecOptional(codecForNumber()))
+ .property("exchange_reply", codecOptional(codecForAny()))
.property("execution_time", codecForTimestamp)
.build("MerchantCoinRefundSuccessStatus");
export const codecForMerchantCoinRefundStatus = (): Codec<
MerchantCoinRefundStatus
> =>
- makeCodecForUnion<MerchantCoinRefundStatus>()
+ buildCodecForUnion<MerchantCoinRefundStatus>()
.discriminateOn("type")
.alternative("success", codecForMerchantCoinRefundSuccessStatus())
.alternative("failure", codecForMerchantCoinRefundFailureStatus())
@@ -1256,17 +1257,17 @@ export const codecForMerchantCoinRefundStatus = (): Codec<
export const codecForMerchantOrderStatusPaid = (): Codec<
MerchantOrderStatusPaid
> =>
- makeCodecForObject<MerchantOrderStatusPaid>()
- .property("merchant_pub", codecForString)
- .property("refund_amount", codecForString)
+ buildCodecForObject<MerchantOrderStatusPaid>()
+ .property("merchant_pub", codecForString())
+ .property("refund_amount", codecForString())
.property("refunded", codecForBoolean)
- .property("refunds", makeCodecForList(codecForMerchantCoinRefundStatus()))
+ .property("refunds", codecForList(codecForMerchantCoinRefundStatus()))
.build("MerchantOrderStatusPaid");
export const codecForMerchantOrderStatusUnpaid = (): Codec<
MerchantOrderStatusUnpaid
> =>
- makeCodecForObject<MerchantOrderStatusUnpaid>()
- .property("taler_pay_uri", codecForString)
- .property("already_paid_order_id", makeCodecOptional(codecForString))
+ buildCodecForObject<MerchantOrderStatusUnpaid>()
+ .property("taler_pay_uri", codecForString())
+ .property("already_paid_order_id", codecOptional(codecForString()))
.build("MerchantOrderStatusUnpaid");
diff --git a/packages/taler-wallet-core/src/types/transactions.ts b/packages/taler-wallet-core/src/types/transactions.ts
index 47e3e7d5b..f3192e5a4 100644
--- a/packages/taler-wallet-core/src/types/transactions.ts
+++ b/packages/taler-wallet-core/src/types/transactions.ts
@@ -28,8 +28,8 @@ import { Timestamp } from "../util/time";
import { AmountString, Product } from "./talerTypes";
import {
Codec,
- makeCodecForObject,
- makeCodecOptional,
+ buildCodecForObject,
+ codecOptional,
codecForString,
} from "../util/codec";
@@ -305,7 +305,7 @@ interface TransactionRefresh extends TransactionCommon {
}
export const codecForTransactionsRequest = (): Codec<TransactionsRequest> =>
- makeCodecForObject<TransactionsRequest>()
- .property("currency", makeCodecOptional(codecForString))
- .property("search", makeCodecOptional(codecForString))
+ buildCodecForObject<TransactionsRequest>()
+ .property("currency", codecOptional(codecForString()))
+ .property("search", codecOptional(codecForString()))
.build("TransactionsRequest");
diff --git a/packages/taler-wallet-core/src/types/walletTypes.ts b/packages/taler-wallet-core/src/types/walletTypes.ts
index d79ade971..7a648dd56 100644
--- a/packages/taler-wallet-core/src/types/walletTypes.ts
+++ b/packages/taler-wallet-core/src/types/walletTypes.ts
@@ -40,13 +40,13 @@ import {
} from "./dbTypes";
import { Timestamp } from "../util/time";
import {
- makeCodecForObject,
+ buildCodecForObject,
codecForString,
- makeCodecOptional,
+ codecOptional,
Codec,
- makeCodecForList,
+ codecForList,
codecForBoolean,
- makeCodecForConstString,
+ codecForConstString,
codecForAny,
} from "../util/codec";
import { AmountString, codecForContractTerms } from "./talerTypes";
@@ -174,17 +174,17 @@ export interface BalancesResponse {
}
export const codecForBalance = (): Codec<Balance> =>
- makeCodecForObject<Balance>()
- .property("available", codecForString)
+ buildCodecForObject<Balance>()
+ .property("available", codecForString())
.property("hasPendingTransactions", codecForBoolean)
- .property("pendingIncoming", codecForString)
- .property("pendingOutgoing", codecForString)
+ .property("pendingIncoming", codecForString())
+ .property("pendingOutgoing", codecForString())
.property("requiresUserInput", codecForBoolean)
.build("Balance");
export const codecForBalancesResponse = (): Codec<BalancesResponse> =>
- makeCodecForObject<BalancesResponse>()
- .property("balances", makeCodecForList(codecForBalance()))
+ buildCodecForObject<BalancesResponse>()
+ .property("balances", codecForList(codecForBalance()))
.build("BalancesResponse");
/**
@@ -270,12 +270,12 @@ export interface CreateReserveRequest {
}
export const codecForCreateReserveRequest = (): Codec<CreateReserveRequest> =>
- makeCodecForObject<CreateReserveRequest>()
+ buildCodecForObject<CreateReserveRequest>()
.property("amount", codecForAmountJson())
- .property("exchange", codecForString)
- .property("exchangePaytoUri", codecForString)
- .property("senderWire", makeCodecOptional(codecForString))
- .property("bankWithdrawStatusUrl", makeCodecOptional(codecForString))
+ .property("exchange", codecForString())
+ .property("exchangePaytoUri", codecForString())
+ .property("senderWire", codecOptional(codecForString()))
+ .property("bankWithdrawStatusUrl", codecOptional(codecForString()))
.build("CreateReserveRequest");
/**
@@ -290,8 +290,8 @@ export interface ConfirmReserveRequest {
}
export const codecForConfirmReserveRequest = (): Codec<ConfirmReserveRequest> =>
- makeCodecForObject<ConfirmReserveRequest>()
- .property("reservePub", codecForString)
+ buildCodecForObject<ConfirmReserveRequest>()
+ .property("reservePub", codecForString())
.build("ConfirmReserveRequest");
/**
@@ -360,43 +360,43 @@ export const enum PreparePayResultType {
export const codecForPreparePayResultPaymentPossible = (): Codec<
PreparePayResultPaymentPossible
> =>
- makeCodecForObject<PreparePayResultPaymentPossible>()
+ buildCodecForObject<PreparePayResultPaymentPossible>()
.property("amountEffective", codecForAmountString())
.property("amountRaw", codecForAmountString())
- .property("contractTerms", codecForAny)
- .property("proposalId", codecForString)
+ .property("contractTerms", codecForAny())
+ .property("proposalId", codecForString())
.property(
"status",
- makeCodecForConstString(PreparePayResultType.PaymentPossible),
+ codecForConstString(PreparePayResultType.PaymentPossible),
)
.build("PreparePayResultPaymentPossible");
export const codecForPreparePayResultInsufficientBalance = (): Codec<
PreparePayResultInsufficientBalance
> =>
- makeCodecForObject<PreparePayResultInsufficientBalance>()
+ buildCodecForObject<PreparePayResultInsufficientBalance>()
.property("amountRaw", codecForAmountString())
- .property("contractTerms", codecForAny)
- .property("proposalId", codecForString)
+ .property("contractTerms", codecForAny())
+ .property("proposalId", codecForString())
.property(
"status",
- makeCodecForConstString(PreparePayResultType.InsufficientBalance),
+ codecForConstString(PreparePayResultType.InsufficientBalance),
)
.build("PreparePayResultInsufficientBalance");
export const codecForPreparePayResultAlreadyConfirmed = (): Codec<
PreparePayResultAlreadyConfirmed
> =>
- makeCodecForObject<PreparePayResultAlreadyConfirmed>()
+ buildCodecForObject<PreparePayResultAlreadyConfirmed>()
.property(
"status",
- makeCodecForConstString(PreparePayResultType.AlreadyConfirmed),
+ codecForConstString(PreparePayResultType.AlreadyConfirmed),
)
.property("amountEffective", codecForAmountString())
.property("amountRaw", codecForAmountString())
- .property("nextUrl", codecForString)
+ .property("nextUrl", codecForString())
.property("paid", codecForBoolean)
- .property("contractTerms", codecForAny)
+ .property("contractTerms", codecForAny())
.build("PreparePayResultAlreadyConfirmed");
export type PreparePayResult =
diff --git a/packages/taler-wallet-core/src/util/amounts.ts b/packages/taler-wallet-core/src/util/amounts.ts
index 33faa868e..2a8c47905 100644
--- a/packages/taler-wallet-core/src/util/amounts.ts
+++ b/packages/taler-wallet-core/src/util/amounts.ts
@@ -22,7 +22,7 @@
* Imports.
*/
import {
- makeCodecForObject,
+ buildCodecForObject,
codecForString,
codecForNumber,
Codec,
@@ -68,13 +68,13 @@ export interface AmountJson {
}
export const codecForAmountJson = (): Codec<AmountJson> =>
- makeCodecForObject<AmountJson>()
- .property("currency", codecForString)
- .property("value", codecForNumber)
- .property("fraction", codecForNumber)
+ buildCodecForObject<AmountJson>()
+ .property("currency", codecForString())
+ .property("value", codecForNumber())
+ .property("fraction", codecForNumber())
.build("AmountJson");
-export const codecForAmountString = (): Codec<AmountString> => codecForString;
+export const codecForAmountString = (): Codec<AmountString> => codecForString();
/**
* Result of a possibly overflowing operation.
diff --git a/packages/taler-wallet-core/src/util/codec-test.ts b/packages/taler-wallet-core/src/util/codec-test.ts
index b429c318c..f8f4c797c 100644
--- a/packages/taler-wallet-core/src/util/codec-test.ts
+++ b/packages/taler-wallet-core/src/util/codec-test.ts
@@ -21,10 +21,10 @@
import test from "ava";
import {
Codec,
- makeCodecForObject,
- makeCodecForConstString,
+ buildCodecForObject,
+ codecForConstString,
codecForString,
- makeCodecForUnion,
+ buildCodecForUnion,
} from "./codec";
interface MyObj {
@@ -44,8 +44,8 @@ interface AltTwo {
type MyUnion = AltOne | AltTwo;
test("basic codec", (t) => {
- const myObjCodec = makeCodecForObject<MyObj>()
- .property("foo", codecForString)
+ const myObjCodec = buildCodecForObject<MyObj>()
+ .property("foo", codecForString())
.build("MyObj");
const res = myObjCodec.decode({ foo: "hello" });
t.assert(res.foo === "hello");
@@ -56,15 +56,15 @@ test("basic codec", (t) => {
});
test("union", (t) => {
- const altOneCodec: Codec<AltOne> = makeCodecForObject<AltOne>()
- .property("type", makeCodecForConstString("one"))
- .property("foo", codecForString)
+ const altOneCodec: Codec<AltOne> = buildCodecForObject<AltOne>()
+ .property("type", codecForConstString("one"))
+ .property("foo", codecForString())
.build("AltOne");
- const altTwoCodec: Codec<AltTwo> = makeCodecForObject<AltTwo>()
- .property("type", makeCodecForConstString("two"))
- .property("bar", codecForString)
+ const altTwoCodec: Codec<AltTwo> = buildCodecForObject<AltTwo>()
+ .property("type", codecForConstString("two"))
+ .property("bar", codecForString())
.build("AltTwo");
- const myUnionCodec: Codec<MyUnion> = makeCodecForUnion<MyUnion>()
+ const myUnionCodec: Codec<MyUnion> = buildCodecForUnion<MyUnion>()
.discriminateOn("type")
.alternative("one", altOneCodec)
.alternative("two", altTwoCodec)
diff --git a/packages/taler-wallet-core/src/util/codec.ts b/packages/taler-wallet-core/src/util/codec.ts
index 2ce3c2cba..111abc38c 100644
--- a/packages/taler-wallet-core/src/util/codec.ts
+++ b/packages/taler-wallet-core/src/util/codec.ts
@@ -221,18 +221,18 @@ export class UnionCodecPreBuilder<T> {
/**
* Return a builder for a codec that decodes an object with properties.
*/
-export function makeCodecForObject<T>(): ObjectCodecBuilder<T, {}> {
+export function buildCodecForObject<T>(): ObjectCodecBuilder<T, {}> {
return new ObjectCodecBuilder<T, {}>();
}
-export function makeCodecForUnion<T>(): UnionCodecPreBuilder<T> {
+export function buildCodecForUnion<T>(): UnionCodecPreBuilder<T> {
return new UnionCodecPreBuilder<T>();
}
/**
* Return a codec for a mapping from a string to values described by the inner codec.
*/
-export function makeCodecForMap<T>(
+export function codecForMap<T>(
innerCodec: Codec<T>,
): Codec<{ [x: string]: T }> {
if (!innerCodec) {
@@ -255,7 +255,7 @@ export function makeCodecForMap<T>(
/**
* Return a codec for a list, containing values described by the inner codec.
*/
-export function makeCodecForList<T>(innerCodec: Codec<T>): Codec<T[]> {
+export function codecForList<T>(innerCodec: Codec<T>): Codec<T[]> {
if (!innerCodec) {
throw Error("inner codec must be defined");
}
@@ -276,16 +276,18 @@ export function makeCodecForList<T>(innerCodec: Codec<T>): Codec<T[]> {
/**
* Return a codec for a value that must be a number.
*/
-export const codecForNumber: Codec<number> = {
- decode(x: any, c?: Context): number {
- if (typeof x === "number") {
- return x;
- }
- throw new DecodingError(
- `expected number at ${renderContext(c)} but got ${typeof x}`,
- );
- },
-};
+export function codecForNumber(): Codec<number> {
+ return {
+ decode(x: any, c?: Context): number {
+ if (typeof x === "number") {
+ return x;
+ }
+ throw new DecodingError(
+ `expected number at ${renderContext(c)} but got ${typeof x}`,
+ );
+ },
+ };
+}
/**
* Return a codec for a value that must be a number.
@@ -304,30 +306,34 @@ export const codecForBoolean: Codec<boolean> = {
/**
* Return a codec for a value that must be a string.
*/
-export const codecForString: Codec<string> = {
- decode(x: any, c?: Context): string {
- if (typeof x === "string") {
- return x;
- }
- throw new DecodingError(
- `expected string at ${renderContext(c)} but got ${typeof x}`,
- );
- },
-};
+export function codecForString(): Codec<string> {
+ return {
+ decode(x: any, c?: Context): string {
+ if (typeof x === "string") {
+ return x;
+ }
+ throw new DecodingError(
+ `expected string at ${renderContext(c)} but got ${typeof x}`,
+ );
+ },
+ };
+}
/**
* Codec that allows any value.
*/
-export const codecForAny: Codec<any> = {
- decode(x: any, c?: Context): any {
- return x;
- },
-};
+export function codecForAny(): Codec<any> {
+ return {
+ decode(x: any, c?: Context): any {
+ return x;
+ },
+ };
+}
/**
* Return a codec for a value that must be a string.
*/
-export function makeCodecForConstString<V extends string>(s: V): Codec<V> {
+export function codecForConstString<V extends string>(s: V): Codec<V> {
return {
decode(x: any, c?: Context): V {
if (x === s) {
@@ -345,7 +351,7 @@ export function makeCodecForConstString<V extends string>(s: V): Codec<V> {
/**
* Return a codec for a boolean true constant.
*/
-export function makeCodecForConstTrue(): Codec<true> {
+export function codecForConstTrue(): Codec<true> {
return {
decode(x: any, c?: Context): true {
if (x === true) {
@@ -361,7 +367,7 @@ export function makeCodecForConstTrue(): Codec<true> {
/**
* Return a codec for a boolean true constant.
*/
-export function makeCodecForConstFalse(): Codec<false> {
+export function codecForConstFalse(): Codec<false> {
return {
decode(x: any, c?: Context): false {
if (x === false) {
@@ -377,7 +383,7 @@ export function makeCodecForConstFalse(): Codec<false> {
/**
* Return a codec for a value that must be a constant number.
*/
-export function makeCodecForConstNumber<V extends number>(n: V): Codec<V> {
+export function codecForConstNumber<V extends number>(n: V): Codec<V> {
return {
decode(x: any, c?: Context): V {
if (x === n) {
@@ -392,9 +398,7 @@ export function makeCodecForConstNumber<V extends number>(n: V): Codec<V> {
};
}
-export function makeCodecOptional<V>(
- innerCodec: Codec<V>,
-): Codec<V | undefined> {
+export function codecOptional<V>(innerCodec: Codec<V>): Codec<V | undefined> {
return {
decode(x: any, c?: Context): V | undefined {
if (x === undefined || x === null) {
diff --git a/packages/taler-wallet-core/src/walletCoreApiHandler.ts b/packages/taler-wallet-core/src/walletCoreApiHandler.ts
index 604439186..5bc9005a8 100644
--- a/packages/taler-wallet-core/src/walletCoreApiHandler.ts
+++ b/packages/taler-wallet-core/src/walletCoreApiHandler.ts
@@ -23,10 +23,10 @@ import {
import { TalerErrorCode } from "./TalerErrorCode";
import { codecForTransactionsRequest } from "./types/transactions";
import {
- makeCodecForObject,
+ buildCodecForObject,
codecForString,
Codec,
- makeCodecOptional,
+ codecOptional,
} from "./util/codec";
import { Amounts } from "./util/amounts";
import { OperationErrorDetails } from "./types/walletTypes";
@@ -36,8 +36,8 @@ export interface AddExchangeRequest {
}
export const codecForAddExchangeRequest = (): Codec<AddExchangeRequest> =>
- makeCodecForObject<AddExchangeRequest>()
- .property("exchangeBaseUrl", codecForString)
+ buildCodecForObject<AddExchangeRequest>()
+ .property("exchangeBaseUrl", codecForString())
.build("AddExchangeRequest");
export interface GetExchangeTosRequest {
@@ -45,8 +45,8 @@ export interface GetExchangeTosRequest {
}
export const codecForGetExchangeTosRequest = (): Codec<GetExchangeTosRequest> =>
- makeCodecForObject<GetExchangeTosRequest>()
- .property("exchangeBaseUrl", codecForString)
+ buildCodecForObject<GetExchangeTosRequest>()
+ .property("exchangeBaseUrl", codecForString())
.build("GetExchangeTosRequest");
export interface AcceptManualWithdrawalRequest {
@@ -57,9 +57,9 @@ export interface AcceptManualWithdrawalRequest {
export const codecForAcceptManualWithdrawalRequet = (): Codec<
AcceptManualWithdrawalRequest
> =>
- makeCodecForObject<AcceptManualWithdrawalRequest>()
- .property("exchangeBaseUrl", codecForString)
- .property("amount", codecForString)
+ buildCodecForObject<AcceptManualWithdrawalRequest>()
+ .property("exchangeBaseUrl", codecForString())
+ .property("amount", codecForString())
.build("AcceptManualWithdrawalRequest");
export interface GetWithdrawalDetailsForAmountRequest {
@@ -75,17 +75,17 @@ export interface AcceptBankIntegratedWithdrawalRequest {
export const codecForAcceptBankIntegratedWithdrawalRequest = (): Codec<
AcceptBankIntegratedWithdrawalRequest
> =>
- makeCodecForObject<AcceptBankIntegratedWithdrawalRequest>()
- .property("exchangeBaseUrl", codecForString)
- .property("talerWithdrawUri", codecForString)
+ buildCodecForObject<AcceptBankIntegratedWithdrawalRequest>()
+ .property("exchangeBaseUrl", codecForString())
+ .property("talerWithdrawUri", codecForString())
.build("AcceptBankIntegratedWithdrawalRequest");
export const codecForGetWithdrawalDetailsForAmountRequest = (): Codec<
GetWithdrawalDetailsForAmountRequest
> =>
- makeCodecForObject<GetWithdrawalDetailsForAmountRequest>()
- .property("exchangeBaseUrl", codecForString)
- .property("amount", codecForString)
+ buildCodecForObject<GetWithdrawalDetailsForAmountRequest>()
+ .property("exchangeBaseUrl", codecForString())
+ .property("amount", codecForString())
.build("GetWithdrawalDetailsForAmountRequest");
export interface AcceptExchangeTosRequest {
@@ -94,9 +94,9 @@ export interface AcceptExchangeTosRequest {
}
export const codecForAcceptExchangeTosRequest = (): Codec<AcceptExchangeTosRequest> =>
- makeCodecForObject<AcceptExchangeTosRequest>()
- .property("exchangeBaseUrl", codecForString)
- .property("etag", codecForString)
+ buildCodecForObject<AcceptExchangeTosRequest>()
+ .property("exchangeBaseUrl", codecForString())
+ .property("etag", codecForString())
.build("AcceptExchangeTosRequest");
export interface ApplyRefundRequest {
@@ -104,8 +104,8 @@ export interface ApplyRefundRequest {
}
export const codecForApplyRefundRequest = (): Codec<ApplyRefundRequest> =>
- makeCodecForObject<ApplyRefundRequest>()
- .property("talerRefundUri", codecForString)
+ buildCodecForObject<ApplyRefundRequest>()
+ .property("talerRefundUri", codecForString())
.build("ApplyRefundRequest");
export interface GetWithdrawalDetailsForUriRequest {
@@ -115,8 +115,8 @@ export interface GetWithdrawalDetailsForUriRequest {
export const codecForGetWithdrawalDetailsForUri = (): Codec<
GetWithdrawalDetailsForUriRequest
> =>
- makeCodecForObject<GetWithdrawalDetailsForUriRequest>()
- .property("talerWithdrawUri", codecForString)
+ buildCodecForObject<GetWithdrawalDetailsForUriRequest>()
+ .property("talerWithdrawUri", codecForString())
.build("GetWithdrawalDetailsForUriRequest");
export interface AbortProposalRequest {
@@ -124,8 +124,8 @@ export interface AbortProposalRequest {
}
export const codecForAbortProposalRequest = (): Codec<AbortProposalRequest> =>
- makeCodecForObject<AbortProposalRequest>()
- .property("proposalId", codecForString)
+ buildCodecForObject<AbortProposalRequest>()
+ .property("proposalId", codecForString())
.build("AbortProposalRequest");
export interface PreparePayRequest {
@@ -133,8 +133,8 @@ export interface PreparePayRequest {
}
const codecForPreparePayRequest = (): Codec<PreparePayRequest> =>
- makeCodecForObject<PreparePayRequest>()
- .property("talerPayUri", codecForString)
+ buildCodecForObject<PreparePayRequest>()
+ .property("talerPayUri", codecForString())
.build("PreparePay");
export interface ConfirmPayRequest {
@@ -143,9 +143,9 @@ export interface ConfirmPayRequest {
}
export const codecForConfirmPayRequest = (): Codec<ConfirmPayRequest> =>
- makeCodecForObject<ConfirmPayRequest>()
- .property("proposalId", codecForString)
- .property("sessionId", makeCodecOptional(codecForString))
+ buildCodecForObject<ConfirmPayRequest>()
+ .property("proposalId", codecForString())
+ .property("sessionId", codecOptional(codecForString()))
.build("ConfirmPay");
/**