[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-wallet-core] branch master updated: extends parseId to include tm
From: |
gnunet |
Subject: |
[taler-wallet-core] branch master updated: extends parseId to include tmb |
Date: |
Mon, 17 Oct 2022 18:50:26 +0200 |
This is an automated email from the git hooks/post-receive script.
sebasjm pushed a commit to branch master
in repository wallet-core.
The following commit(s) were added to refs/heads/master by this push:
new 57892db20 extends parseId to include tmb
57892db20 is described below
commit 57892db20af42afa702ed41347c6da4b0cd5cb93
Author: Sebastian <sebasjm@gmail.com>
AuthorDate: Mon Oct 17 13:50:17 2022 -0300
extends parseId to include tmb
---
packages/taler-wallet-core/src/operations/common.ts | 15 +++++++++------
.../taler-wallet-core/src/operations/transactions.ts | 17 +++++------------
2 files changed, 14 insertions(+), 18 deletions(-)
diff --git a/packages/taler-wallet-core/src/operations/common.ts
b/packages/taler-wallet-core/src/operations/common.ts
index 2bed195a1..59d2b8ec3 100644
--- a/packages/taler-wallet-core/src/operations/common.ts
+++ b/packages/taler-wallet-core/src/operations/common.ts
@@ -306,23 +306,26 @@ export function makeTransactionId(
return `txn:${type}:${args.map((x) => encodeURIComponent(x)).join(":")}`;
}
-export function parseTransactionId(txId: string): {
+export function parseId(
+ idType: "txn" | "tmb" | "any",
+ txId: string,
+): {
type: TransactionType;
args: string[];
} {
const txnParts = txId.split(":");
if (txnParts.length < 3) {
- throw Error("transactionId should have al least 3 parts separated by ':'");
+ throw Error("id should have al least 3 parts separated by ':'");
}
- const [txn, typeStr, ...args] = txnParts;
+ const [prefix, typeStr, ...args] = txnParts;
const type = typeStr as TransactionType;
- if (txn !== "txn") {
- throw Error("transactionId should start with txn");
+ if (idType != "any" && prefix !== idType) {
+ throw Error(`id should start with ${idType}`);
}
if (args.length === 0) {
- throw Error("transactionId should have one or more arguments");
+ throw Error("id should have one or more arguments");
}
return { type, args };
diff --git a/packages/taler-wallet-core/src/operations/transactions.ts
b/packages/taler-wallet-core/src/operations/transactions.ts
index 5c903a649..6e8ebc4f4 100644
--- a/packages/taler-wallet-core/src/operations/transactions.ts
+++ b/packages/taler-wallet-core/src/operations/transactions.ts
@@ -56,7 +56,7 @@ import { RetryTags } from "../util/retries.js";
import {
makeTombstoneId,
makeTransactionId,
- parseTransactionId,
+ parseId,
TombstoneTag,
} from "./common.js";
import { processDepositGroup } from "./deposits.js";
@@ -122,7 +122,7 @@ export async function getTransactionById(
ws: InternalWalletState,
req: TransactionByIdRequest,
): Promise<Transaction> {
- const { type, args: rest } = parseTransactionId(req.transactionId);
+ const { type, args: rest } = parseId("txn", req.transactionId);
if (
type === TransactionType.Withdrawal ||
type === TransactionType.PeerPullCredit ||
@@ -959,11 +959,7 @@ export async function retryTransaction(
): Promise<void> {
logger.info(`retrying transaction ${transactionId}`);
- const [tmbPrefix, type, ...rest] = transactionId.split(":");
-
- if (tmbPrefix !== "tmb") {
- throw Error("invalid tombstone, expected 'tmb' prefix");
- }
+ const { type, args: rest } = parseId("any", transactionId);
switch (type) {
case TransactionType.Deposit: {
@@ -1005,11 +1001,8 @@ export async function deleteTransaction(
ws: InternalWalletState,
transactionId: string,
): Promise<void> {
- const [txnPrefix, typeStr, ...rest] = transactionId.split(":");
- if (txnPrefix !== "txn") {
- throw Error("invalid transaction ID, expected 'txn' prefix");
- }
- const type = typeStr as TransactionType;
+ const { type, args: rest } = parseId("txn", transactionId);
+
if (
type === TransactionType.Withdrawal ||
type === TransactionType.PeerPullCredit ||
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [taler-wallet-core] branch master updated: extends parseId to include tmb,
gnunet <=