mirror of
https://github.com/colanode/colanode.git
synced 2025-12-29 00:25:03 +01:00
Improve replace transactions service
This commit is contained in:
@@ -586,13 +586,18 @@ class NodeService {
|
||||
public async replaceTransactions(
|
||||
userId: string,
|
||||
nodeId: string,
|
||||
transactions: ServerTransaction[]
|
||||
transactions: ServerTransaction[],
|
||||
transactionCursor: bigint
|
||||
): Promise<boolean> {
|
||||
const workspaceDatabase =
|
||||
await databaseService.getWorkspaceDatabase(userId);
|
||||
|
||||
const firstTransaction = transactions[0];
|
||||
if (!firstTransaction) {
|
||||
if (!firstTransaction || firstTransaction.operation !== 'create') {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (transactionCursor < BigInt(firstTransaction.version)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -439,10 +439,12 @@ class SyncService {
|
||||
continue;
|
||||
}
|
||||
|
||||
const cursor = await this.fetchCursor(userId, 'transactions');
|
||||
const synced = await nodeService.replaceTransactions(
|
||||
userId,
|
||||
nodeId,
|
||||
data.transactions
|
||||
data.transactions,
|
||||
cursor
|
||||
);
|
||||
|
||||
if (!synced) {
|
||||
@@ -558,10 +560,12 @@ class SyncService {
|
||||
}
|
||||
);
|
||||
|
||||
const cursor = await this.fetchCursor(userId, 'transactions');
|
||||
await nodeService.replaceTransactions(
|
||||
userId,
|
||||
node.node_id,
|
||||
data.transactions
|
||||
data.transactions,
|
||||
cursor
|
||||
);
|
||||
} catch (error) {
|
||||
this.debug(
|
||||
@@ -626,10 +630,12 @@ class SyncService {
|
||||
}
|
||||
);
|
||||
|
||||
const cursor = await this.fetchCursor(event.userId, 'transactions');
|
||||
await nodeService.replaceTransactions(
|
||||
event.userId,
|
||||
event.nodeId,
|
||||
data.transactions
|
||||
data.transactions,
|
||||
cursor
|
||||
);
|
||||
} catch (error) {
|
||||
this.debug(
|
||||
|
||||
Reference in New Issue
Block a user