Skip to content

Commit

Permalink
fix: incorrect batch transfer parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
jaensen committed Jan 16, 2025
1 parent 06284f5 commit 4c4abd5
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 18 deletions.
44 changes: 28 additions & 16 deletions Circles.Index.CirclesV2/LogParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,13 @@ public IEnumerable<IIndexEvent> 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)
{
Expand Down Expand Up @@ -207,20 +207,31 @@ private TransferSingle Erc1155TransferSingle(Block block, TxReceipt receipt, Log
value);
}

private IEnumerable<TransferBatch> Erc1155TransferBatch(Block block, TxReceipt receipt, LogEntry log, int logIndex)
private IEnumerable<TransferBatch> 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,
Expand All @@ -231,8 +242,9 @@ private IEnumerable<TransferBatch> Erc1155TransferBatch(Block block, TxReceipt r
operatorAddress,
fromAddress,
toAddress,
batchId,
batchValue);
ids[i],
values[i]
);
}
}

Expand Down
4 changes: 2 additions & 2 deletions Circles.Index/Circles.Index.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
<Authors>Daniel Janz (Gnosis Service GmbH)</Authors>
<Copyright>Gnosis Service GmbH</Copyright>
<Product>Circles</Product>
<AssemblyVersion>1.11.8</AssemblyVersion>
<FileVersion>1.11.8</FileVersion>
<AssemblyVersion>1.11.10</AssemblyVersion>
<FileVersion>1.11.10</FileVersion>
</PropertyGroup>


Expand Down

0 comments on commit 4c4abd5

Please sign in to comment.