diff --git a/statediff/builder/builder.go b/statediff/builder/builder.go index 0745444ff..650833af0 100644 --- a/statediff/builder/builder.go +++ b/statediff/builder/builder.go @@ -248,8 +248,10 @@ func (sdb *builder) buildStorageDiffsIncremental(oldSR common.Hash, newSR common if it.Leaf() { log.Debug("Found leaf in storage", "path", pathToStr(it)) path := pathToStr(it) + storageKey:= hexutil.Encode(it.LeafKey()) storageValue := hexutil.Encode(it.LeafBlob()) storageDiffs[path] = DiffStorage{ + Key: &storageKey, Value: &storageValue, } } diff --git a/statediff/builder/builder_test.go b/statediff/builder/builder_test.go index e9cb8caf2..af05d1e37 100644 --- a/statediff/builder/builder_test.go +++ b/statediff/builder/builder_test.go @@ -73,6 +73,8 @@ func TestBuilder(t *testing.T) { nonce3 = uint64(3) originalContractRoot = "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421" newContractRoot = "0x9e676b23802aff85d29b4f0243939bc6ecfdca2a41532310091781854d6ffeb2" + storageLocation = common.HexToHash("2") + newStorageKey = crypto.Keccak256Hash(storageLocation[:]).String() newStorageValue = "0x03" ) @@ -222,6 +224,7 @@ func TestBuilder(t *testing.T) { ContractRoot: b.DiffString{Value: &newContractRoot}, Storage: map[string]b.DiffStorage{ "0x405787fa12a823e0f2b7631cc41b3ba8828b3321ca811111fa75cd3aa3bb5ace": { + Key: &newStorageKey, Value: &newStorageValue}, }, }, diff --git a/statediff/builder/struct.go b/statediff/builder/struct.go index 44f7f4f84..e3ad599f1 100644 --- a/statediff/builder/struct.go +++ b/statediff/builder/struct.go @@ -64,6 +64,7 @@ type AccountDiff struct { } type DiffStorage struct { + Key *string `json:"key" gencodec:"optional"` Value *string `json:"value" gencodec:"optional"` } type DiffString struct { diff --git a/statediff/publisher/csv.go b/statediff/publisher/csv.go index 4efa76cfe..4054b7b15 100644 --- a/statediff/publisher/csv.go +++ b/statediff/publisher/csv.go @@ -14,7 +14,7 @@ var ( Headers = []string{ "blockNumber", "blockHash", "accountAction", "codeHash", "nonceValue", "balanceValue", "contractRoot", "storageDiffPaths", - "accountAddress", "storageValue", + "accountAddress", "storageKey", "storageValue", } timeStampFormat = "20060102150405.00000" @@ -88,7 +88,8 @@ func formatAccountData(accountAddr common.Address, accountDiff builder.AccountDi newContractRoot := accountDiff.ContractRoot.Value address := accountAddr.String() var result [][]string - for storagePath, storageValue := range accountDiff.Storage { + + for storagePath, storage := range accountDiff.Storage { formattedAccountData := []string{ blockNumberString, blockHash, @@ -99,7 +100,8 @@ func formatAccountData(accountAddr common.Address, accountDiff builder.AccountDi *newContractRoot, storagePath, address, - *storageValue.Value, + *storage.Key, + *storage.Value, } result = append(result, formattedAccountData) diff --git a/statediff/publisher/publisher_test.go b/statediff/publisher/publisher_test.go index 215505db3..ad9e29318 100644 --- a/statediff/publisher/publisher_test.go +++ b/statediff/publisher/publisher_test.go @@ -35,6 +35,7 @@ var expectedCreatedAccountRow = []string{ testhelpers.ContractRoot, testhelpers.StoragePath, testhelpers.ContractAddress, + "0000000000000000000000000000000000000000000000000000000000000001", testhelpers.StorageValue, } @@ -48,6 +49,7 @@ var expectedUpdatedAccountRow = []string{ testhelpers.ContractRoot, testhelpers.StoragePath, testhelpers.ContractAddress, + "0000000000000000000000000000000000000000000000000000000000000001", testhelpers.StorageValue, } @@ -61,6 +63,7 @@ var expectedDeletedAccountRow = []string{ testhelpers.ContractRoot, testhelpers.StoragePath, testhelpers.ContractAddress, + "0000000000000000000000000000000000000000000000000000000000000001", testhelpers.StorageValue, } diff --git a/statediff/testhelpers/test_data.go b/statediff/testhelpers/test_data.go index 2dff3c323..cd03e1e67 100644 --- a/statediff/testhelpers/test_data.go +++ b/statediff/testhelpers/test_data.go @@ -15,8 +15,12 @@ var ( NewBalanceValue = rand.Int63() ContractRoot = "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421" StoragePath = "0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470" + StorageKey = "0000000000000000000000000000000000000000000000000000000000000001" StorageValue = "0x03" - storage = map[string]builder.DiffStorage{StoragePath: {Value: &StorageValue}} + storage = map[string]builder.DiffStorage{StoragePath: { + Key: &StorageKey, + Value: &StorageValue, + }} address = common.HexToAddress("0xaE9BEa628c4Ce503DcFD7E305CaB4e29E7476592") ContractAddress = address.String() CreatedAccountDiffs = map[common.Address]builder.AccountDiff{address: {