summaryrefslogtreecommitdiff
path: root/packages/taler-wallet-core/src/operations/common.ts
diff options
context:
space:
mode:
authorSebastian <sebasjm@gmail.com>2022-10-17 13:36:39 -0300
committerSebastian <sebasjm@gmail.com>2022-10-17 13:36:39 -0300
commit995b6b4e96e2bd750d2d42f7ff806f4e2efb2d19 (patch)
tree5635b198da6782049862c28e7130e8fcf4f7a7f1 /packages/taler-wallet-core/src/operations/common.ts
parentd1f43ca5f21592a1b1db5cf7e98bb90c02db6eea (diff)
downloadwallet-core-995b6b4e96e2bd750d2d42f7ff806f4e2efb2d19.tar.gz
wallet-core-995b6b4e96e2bd750d2d42f7ff806f4e2efb2d19.tar.bz2
wallet-core-995b6b4e96e2bd750d2d42f7ff806f4e2efb2d19.zip
sync parseTx with the new makeTx
Diffstat (limited to 'packages/taler-wallet-core/src/operations/common.ts')
-rw-r--r--packages/taler-wallet-core/src/operations/common.ts22
1 files changed, 22 insertions, 0 deletions
diff --git a/packages/taler-wallet-core/src/operations/common.ts b/packages/taler-wallet-core/src/operations/common.ts
index 95441be2b..2bed195a1 100644
--- a/packages/taler-wallet-core/src/operations/common.ts
+++ b/packages/taler-wallet-core/src/operations/common.ts
@@ -306,6 +306,28 @@ export function makeTransactionId(
return `txn:${type}:${args.map((x) => encodeURIComponent(x)).join(":")}`;
}
+export function parseTransactionId(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 ':'");
+ }
+ const [txn, typeStr, ...args] = txnParts;
+ const type = typeStr as TransactionType;
+
+ if (txn !== "txn") {
+ throw Error("transactionId should start with txn");
+ }
+
+ if (args.length === 0) {
+ throw Error("transactionId should have one or more arguments");
+ }
+
+ return { type, args };
+}
+
/**
* Create an event ID from the type and the primary key for the event.
*/