From 4c4abd5b364693451f1c05c81ba52886d8bffd19 Mon Sep 17 00:00:00 2001 From: daniel <4954577+jaensen@users.noreply.github.com> Date: Thu, 16 Jan 2025 17:11:59 +0100 Subject: [PATCH] fix: incorrect batch transfer parsing --- Circles.Index.CirclesV2/LogParser.cs | 44 ++++++++++++++++++---------- Circles.Index/Circles.Index.csproj | 4 +-- 2 files changed, 30 insertions(+), 18 deletions(-) diff --git a/Circles.Index.CirclesV2/LogParser.cs b/Circles.Index.CirclesV2/LogParser.cs index 56529ae..e2ec65d 100644 --- a/Circles.Index.CirclesV2/LogParser.cs +++ b/Circles.Index.CirclesV2/LogParser.cs @@ -80,13 +80,13 @@ public IEnumerable ParseLog(Block block, Transaction transaction, T yield return CrcV2RegisterOrganization(block, receipt, log, logIndex); } - // if (topic == _transferBatchTopic) - // { - // foreach (var batchEvent in Erc1155TransferBatch(block, receipt, log, logIndex)) - // { - // yield return batchEvent; - // } - // } + if (topic == _transferBatchTopic) + { + foreach (var batchEvent in Erc1155TransferBatch(block, receipt, log, logIndex)) + { + yield return batchEvent; + } + } if (topic == _transferSingleTopic) { @@ -207,20 +207,31 @@ private TransferSingle Erc1155TransferSingle(Block block, TxReceipt receipt, Log value); } - private IEnumerable Erc1155TransferBatch(Block block, TxReceipt receipt, LogEntry log, int logIndex) + private IEnumerable Erc1155TransferBatch( + Block block, + TxReceipt receipt, + LogEntry log, + int logIndex) { + var data = log.Data; + int idsOffset = (int)new BigInteger(data.Slice(0, 32).ToArray(), true, true); + int valuesOffset = (int)new BigInteger(data.Slice(32, 32).ToArray(), true, true); + string operatorAddress = "0x" + log.Topics[1].ToString().Substring(Consts.AddressEmptyBytesPrefixLength); string fromAddress = "0x" + log.Topics[2].ToString().Substring(Consts.AddressEmptyBytesPrefixLength); string toAddress = "0x" + log.Topics[3].ToString().Substring(Consts.AddressEmptyBytesPrefixLength); - int offset = 32; - int batchSize = (int)new BigInteger(log.Data.Slice(0, 32).ToArray()); - for (int i = 0; i < batchSize; i++) + var ids = DecodeUInt256Array(data.Slice(idsOffset)); + var values = DecodeUInt256Array(data.Slice(valuesOffset)); + + if (ids.Count != values.Count) { - UInt256 batchId = new UInt256(log.Data.Slice(offset, 32), true); - UInt256 batchValue = new UInt256(log.Data.Slice(offset + 32, 32), true); - offset += 64; + throw new InvalidOperationException("The number of ids and values must match."); + } + // Yield each pair + for (int i = 0; i < ids.Count; i++) + { yield return new TransferBatch( block.Number, (long)block.Timestamp, @@ -231,8 +242,9 @@ private IEnumerable Erc1155TransferBatch(Block block, TxReceipt r operatorAddress, fromAddress, toAddress, - batchId, - batchValue); + ids[i], + values[i] + ); } } diff --git a/Circles.Index/Circles.Index.csproj b/Circles.Index/Circles.Index.csproj index bd19d49..b90df58 100644 --- a/Circles.Index/Circles.Index.csproj +++ b/Circles.Index/Circles.Index.csproj @@ -8,8 +8,8 @@ Daniel Janz (Gnosis Service GmbH) Gnosis Service GmbH Circles - 1.11.8 - 1.11.8 + 1.11.10 + 1.11.10