From 0e2a088b206ce1e1db111a0a203fce61f18e27e2 Mon Sep 17 00:00:00 2001 From: ghost Date: Mon, 26 Feb 2024 12:34:29 +0200 Subject: [PATCH] skip processed transactions --- src/index.php | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/index.php b/src/index.php index cb68069..99678f1 100644 --- a/src/index.php +++ b/src/index.php @@ -191,6 +191,9 @@ for ($block = $state + 1; $block <= $blocks; $block++) ); } + // Reset memory pool of processed transactions for each new block + $transactions = []; + // Process each transaction in block foreach ((array) $data['tx'] as $transaction) { @@ -313,9 +316,13 @@ for ($block = $state + 1; $block <= $blocks; $block++) $namespace ) as $record) { - // Get current block transactions only - if ($record['height'] === $block) - { + if ( + // Get current block transactions only + $record['height'] === $block + && + // Skip processed transactions for this namespace + !in_array($raw['txid'], $transactions) + ) { // Register new transaction $index->add( $raw['time'], @@ -327,6 +334,9 @@ for ($block = $state + 1; $block <= $blocks; $block++) $record['key'], $record['value'] ); + + // Register processed transaction + $transactions[] = $raw['txid']; } }