Add storage key to csv

This commit is contained in:
Elizabeth Engelman 2019-01-14 10:48:46 -06:00
parent 0f2880a019
commit 29f5c3ce86
6 changed files with 19 additions and 4 deletions

View File

@ -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,
}
}

View File

@ -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},
},
},

View File

@ -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 {

View File

@ -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)

View File

@ -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,
}

View File

@ -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: {