Add contract address and storage value to csv

This commit is contained in:
Elizabeth Engelman 2019-01-10 15:08:06 -06:00
parent 569a5a6dd8
commit dceddbfbaa
3 changed files with 29 additions and 12 deletions

View File

@ -8,12 +8,14 @@ import (
"strconv" "strconv"
"strings" "strings"
"time" "time"
"github.com/ethereum/go-ethereum/common"
) )
var ( var (
Headers = []string{ Headers = []string{
"blockNumber", "blockHash", "accountAction", "codeHash", "blockNumber", "blockHash", "accountAction", "codeHash",
"nonceValue", "balanceValue", "contractRoot", "storageDiffPaths", "nonceValue", "balanceValue", "contractRoot", "storageDiffPaths",
"accountAddress", "storageValue",
} }
timeStampFormat = "20060102150405.00000" timeStampFormat = "20060102150405.00000"
@ -67,8 +69,8 @@ func (p *publisher) publishStateDiffToCSV(sd builder.StateDiff) (string, error)
func accumulateUpdatedAccountRows(sd builder.StateDiff) [][]string { func accumulateUpdatedAccountRows(sd builder.StateDiff) [][]string {
var updatedAccountRows [][]string var updatedAccountRows [][]string
for _, accountDiff := range sd.UpdatedAccounts { for accountAddr, accountDiff := range sd.UpdatedAccounts {
formattedAccountData := formatAccountDiffIncremental(accountDiff, sd, updatedAccountAction) formattedAccountData := formatAccountDiffIncremental(accountAddr, accountDiff, sd, updatedAccountAction)
updatedAccountRows = append(updatedAccountRows, formattedAccountData) updatedAccountRows = append(updatedAccountRows, formattedAccountData)
} }
@ -78,8 +80,8 @@ func accumulateUpdatedAccountRows(sd builder.StateDiff) [][]string {
func accumulateDeletedAccountRows(sd builder.StateDiff) [][]string { func accumulateDeletedAccountRows(sd builder.StateDiff) [][]string {
var deletedAccountRows [][]string var deletedAccountRows [][]string
for _, accountDiff := range sd.DeletedAccounts { for accountAddr, accountDiff := range sd.DeletedAccounts {
formattedAccountData := formatAccountDiffEventual(accountDiff, sd, deletedAccountAction) formattedAccountData := formatAccountDiffEventual(accountAddr, accountDiff, sd, deletedAccountAction)
deletedAccountRows = append(deletedAccountRows, formattedAccountData) deletedAccountRows = append(deletedAccountRows, formattedAccountData)
} }
@ -89,8 +91,8 @@ func accumulateDeletedAccountRows(sd builder.StateDiff) [][]string {
func accumulateCreatedAccountRows(sd builder.StateDiff) [][]string { func accumulateCreatedAccountRows(sd builder.StateDiff) [][]string {
var createdAccountRows [][]string var createdAccountRows [][]string
for _, accountDiff := range sd.CreatedAccounts { for accountAddr, accountDiff := range sd.CreatedAccounts {
formattedAccountData := formatAccountDiffEventual(accountDiff, sd, createdAccountAction) formattedAccountData := formatAccountDiffEventual(accountAddr, accountDiff, sd, createdAccountAction)
createdAccountRows = append(createdAccountRows, formattedAccountData) createdAccountRows = append(createdAccountRows, formattedAccountData)
} }
@ -98,10 +100,12 @@ func accumulateCreatedAccountRows(sd builder.StateDiff) [][]string {
return createdAccountRows return createdAccountRows
} }
func formatAccountDiffEventual(accountDiff builder.AccountDiff, sd builder.StateDiff, accountAction string) []string { func formatAccountDiffEventual(accountAddr common.Address, accountDiff builder.AccountDiff, sd builder.StateDiff, accountAction string) []string {
newContractRoot := accountDiff.ContractRoot.Value newContractRoot := accountDiff.ContractRoot.Value
var storageDiffPaths []string var storageDiffPaths []string
for k := range accountDiff.Storage { var storageValue builder.DiffString
for k, v := range accountDiff.Storage {
storageValue = v
storageDiffPaths = append(storageDiffPaths, k) storageDiffPaths = append(storageDiffPaths, k)
} }
formattedAccountData := []string{ formattedAccountData := []string{
@ -113,15 +117,19 @@ func formatAccountDiffEventual(accountDiff builder.AccountDiff, sd builder.State
accountDiff.Balance.Value.String(), accountDiff.Balance.Value.String(),
*newContractRoot, *newContractRoot,
strings.Join(storageDiffPaths, ","), strings.Join(storageDiffPaths, ","),
accountAddr.String(),
*storageValue.Value,
} }
return formattedAccountData return formattedAccountData
} }
func formatAccountDiffIncremental(accountDiff builder.AccountDiff, sd builder.StateDiff, accountAction string) []string { func formatAccountDiffIncremental(accountAddr common.Address, accountDiff builder.AccountDiff, sd builder.StateDiff, accountAction string) []string {
newContractRoot := accountDiff.ContractRoot.Value newContractRoot := accountDiff.ContractRoot.Value
var storageDiffPaths []string var storageDiffPaths []string
for k := range accountDiff.Storage { var storageValue builder.DiffString
for k, v := range accountDiff.Storage {
storageDiffPaths = append(storageDiffPaths, k) storageDiffPaths = append(storageDiffPaths, k)
storageValue = v
} }
formattedAccountData := []string{ formattedAccountData := []string{
strconv.FormatInt(sd.BlockNumber, 10), strconv.FormatInt(sd.BlockNumber, 10),
@ -132,6 +140,8 @@ func formatAccountDiffIncremental(accountDiff builder.AccountDiff, sd builder.St
accountDiff.Balance.Value.String(), accountDiff.Balance.Value.String(),
*newContractRoot, *newContractRoot,
strings.Join(storageDiffPaths, ","), strings.Join(storageDiffPaths, ","),
accountAddr.String(),
*storageValue.Value,
} }
return formattedAccountData return formattedAccountData
} }

View File

@ -34,6 +34,8 @@ var expectedCreatedAccountRow = []string{
strconv.FormatInt(testhelpers.NewBalanceValue, 10), strconv.FormatInt(testhelpers.NewBalanceValue, 10),
testhelpers.ContractRoot, testhelpers.ContractRoot,
testhelpers.StoragePath, testhelpers.StoragePath,
testhelpers.ContractAddress,
testhelpers.StorageValue,
} }
var expectedUpdatedAccountRow = []string{ var expectedUpdatedAccountRow = []string{
@ -45,6 +47,8 @@ var expectedUpdatedAccountRow = []string{
strconv.FormatInt(testhelpers.NewBalanceValue, 10), strconv.FormatInt(testhelpers.NewBalanceValue, 10),
testhelpers.ContractRoot, testhelpers.ContractRoot,
testhelpers.StoragePath, testhelpers.StoragePath,
testhelpers.ContractAddress,
testhelpers.StorageValue,
} }
var expectedDeletedAccountRow = []string{ var expectedDeletedAccountRow = []string{
@ -56,6 +60,8 @@ var expectedDeletedAccountRow = []string{
strconv.FormatInt(testhelpers.NewBalanceValue, 10), strconv.FormatInt(testhelpers.NewBalanceValue, 10),
testhelpers.ContractRoot, testhelpers.ContractRoot,
testhelpers.StoragePath, testhelpers.StoragePath,
testhelpers.ContractAddress,
testhelpers.StorageValue,
} }
func TestPublisher(t *testing.T) { func TestPublisher(t *testing.T) {

View File

@ -15,9 +15,10 @@ var (
NewBalanceValue = rand.Int63() NewBalanceValue = rand.Int63()
ContractRoot = "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421" ContractRoot = "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421"
StoragePath = "0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470" StoragePath = "0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470"
newStorage = "0x03" StorageValue = "0x03"
storage = map[string]builder.DiffString{StoragePath: {Value: &newStorage}} storage = map[string]builder.DiffString{StoragePath: {Value: &StorageValue}}
address = common.HexToAddress("0xaE9BEa628c4Ce503DcFD7E305CaB4e29E7476592") address = common.HexToAddress("0xaE9BEa628c4Ce503DcFD7E305CaB4e29E7476592")
ContractAddress = address.String()
CreatedAccountDiffs = map[common.Address]builder.AccountDiff{address: { CreatedAccountDiffs = map[common.Address]builder.AccountDiff{address: {
Nonce: builder.DiffUint64{Value: &NewNonceValue}, Nonce: builder.DiffUint64{Value: &NewNonceValue},
Balance: builder.DiffBigInt{Value: big.NewInt(NewBalanceValue)}, Balance: builder.DiffBigInt{Value: big.NewInt(NewBalanceValue)},