sync parseTx with the new makeTx
This commit is contained in:
parent
d1f43ca5f2
commit
995b6b4e96
@ -306,6 +306,28 @@ export function makeTransactionId(
|
|||||||
return `txn:${type}:${args.map((x) => encodeURIComponent(x)).join(":")}`;
|
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.
|
* Create an event ID from the type and the primary key for the event.
|
||||||
*/
|
*/
|
||||||
|
@ -53,7 +53,12 @@ import {
|
|||||||
import { InternalWalletState } from "../internal-wallet-state.js";
|
import { InternalWalletState } from "../internal-wallet-state.js";
|
||||||
import { checkDbInvariant } from "../util/invariants.js";
|
import { checkDbInvariant } from "../util/invariants.js";
|
||||||
import { RetryTags } from "../util/retries.js";
|
import { RetryTags } from "../util/retries.js";
|
||||||
import { makeTombstoneId, makeTransactionId, TombstoneTag } from "./common.js";
|
import {
|
||||||
|
makeTombstoneId,
|
||||||
|
makeTransactionId,
|
||||||
|
parseTransactionId,
|
||||||
|
TombstoneTag,
|
||||||
|
} from "./common.js";
|
||||||
import { processDepositGroup } from "./deposits.js";
|
import { processDepositGroup } from "./deposits.js";
|
||||||
import { getExchangeDetails } from "./exchanges.js";
|
import { getExchangeDetails } from "./exchanges.js";
|
||||||
import {
|
import {
|
||||||
@ -117,9 +122,7 @@ export async function getTransactionById(
|
|||||||
ws: InternalWalletState,
|
ws: InternalWalletState,
|
||||||
req: TransactionByIdRequest,
|
req: TransactionByIdRequest,
|
||||||
): Promise<Transaction> {
|
): Promise<Transaction> {
|
||||||
const [typeStr, ...rest] = req.transactionId.split(":");
|
const { type, args: rest } = parseTransactionId(req.transactionId);
|
||||||
const type = typeStr as TransactionType;
|
|
||||||
|
|
||||||
if (
|
if (
|
||||||
type === TransactionType.Withdrawal ||
|
type === TransactionType.Withdrawal ||
|
||||||
type === TransactionType.PeerPullCredit ||
|
type === TransactionType.PeerPullCredit ||
|
||||||
|
Loading…
Reference in New Issue
Block a user