Update publisher to account for only storing current account values

This commit is contained in:
Elizabeth Engelman 2018-12-19 15:23:28 -06:00
parent 96caa16268
commit 7604eb8f9a
3 changed files with 18 additions and 70 deletions

View File

@ -13,11 +13,8 @@ import (
var ( var (
Headers = []string{ Headers = []string{
"blockNumber", "blockHash", "accountAction", "blockNumber", "blockHash", "accountAction",
"code", "codeHash", "code", "codeHash", "nonceValue",
"oldNonceValue", "newNonceValue", "balanceValue", "contractRoot", "storageDiffPaths",
"oldBalanceValue", "newBalanceValue",
"oldContractRoot", "newContractRoot",
"storageDiffPaths",
} }
timeStampFormat = "20060102150405.00000" timeStampFormat = "20060102150405.00000"
@ -103,8 +100,7 @@ func accumulateCreatedAccountRows(sd builder.StateDiff) [][]string {
} }
func formatAccountDiffEventual(accountDiff builder.AccountDiffEventual, sd builder.StateDiff, accountAction string) []string { func formatAccountDiffEventual(accountDiff builder.AccountDiffEventual, sd builder.StateDiff, accountAction string) []string {
oldContractRoot := accountDiff.ContractRoot.OldValue newContractRoot := accountDiff.ContractRoot.Value
newContractRoot := accountDiff.ContractRoot.NewValue
var storageDiffPaths []string var storageDiffPaths []string
for k := range accountDiff.Storage { for k := range accountDiff.Storage {
storageDiffPaths = append(storageDiffPaths, k) storageDiffPaths = append(storageDiffPaths, k)
@ -115,11 +111,8 @@ func formatAccountDiffEventual(accountDiff builder.AccountDiffEventual, sd build
accountAction, accountAction,
string(accountDiff.Code), string(accountDiff.Code),
accountDiff.CodeHash, accountDiff.CodeHash,
strconv.FormatUint(*accountDiff.Nonce.OldValue, 10), strconv.FormatUint(*accountDiff.Nonce.Value, 10),
strconv.FormatUint(*accountDiff.Nonce.NewValue, 10), accountDiff.Balance.Value.String(),
accountDiff.Balance.OldValue.String(),
accountDiff.Balance.NewValue.String(),
*oldContractRoot,
*newContractRoot, *newContractRoot,
strings.Join(storageDiffPaths, ","), strings.Join(storageDiffPaths, ","),
} }
@ -127,8 +120,7 @@ func formatAccountDiffEventual(accountDiff builder.AccountDiffEventual, sd build
} }
func formatAccountDiffIncremental(accountDiff builder.AccountDiffIncremental, sd builder.StateDiff, accountAction string) []string { func formatAccountDiffIncremental(accountDiff builder.AccountDiffIncremental, sd builder.StateDiff, accountAction string) []string {
oldContractRoot := accountDiff.ContractRoot.OldValue newContractRoot := accountDiff.ContractRoot.Value
newContractRoot := accountDiff.ContractRoot.NewValue
var storageDiffPaths []string var storageDiffPaths []string
for k := range accountDiff.Storage { for k := range accountDiff.Storage {
storageDiffPaths = append(storageDiffPaths, k) storageDiffPaths = append(storageDiffPaths, k)
@ -139,11 +131,8 @@ func formatAccountDiffIncremental(accountDiff builder.AccountDiffIncremental, sd
accountAction, accountAction,
"", "",
accountDiff.CodeHash, accountDiff.CodeHash,
strconv.FormatUint(*accountDiff.Nonce.OldValue, 10), strconv.FormatUint(*accountDiff.Nonce.Value, 10),
strconv.FormatUint(*accountDiff.Nonce.NewValue, 10), accountDiff.Balance.Value.String(),
accountDiff.Balance.OldValue.String(),
accountDiff.Balance.NewValue.String(),
*oldContractRoot,
*newContractRoot, *newContractRoot,
strings.Join(storageDiffPaths, ","), strings.Join(storageDiffPaths, ","),
} }

View File

@ -30,12 +30,9 @@ var expectedCreatedAccountRow = []string{
"created", "created",
"created account code", "created account code",
testhelpers.CodeHash, testhelpers.CodeHash,
strconv.FormatUint(testhelpers.OldNonceValue, 10),
strconv.FormatUint(testhelpers.NewNonceValue, 10), strconv.FormatUint(testhelpers.NewNonceValue, 10),
strconv.FormatInt(testhelpers.OldBalanceValue, 10),
strconv.FormatInt(testhelpers.NewBalanceValue, 10), strconv.FormatInt(testhelpers.NewBalanceValue, 10),
testhelpers.ContractRoot, testhelpers.ContractRoot,
testhelpers.ContractRoot,
testhelpers.StoragePath, testhelpers.StoragePath,
} }
@ -45,12 +42,9 @@ var expectedUpdatedAccountRow = []string{
"updated", "updated",
"", "",
testhelpers.CodeHash, testhelpers.CodeHash,
strconv.FormatUint(testhelpers.OldNonceValue, 10),
strconv.FormatUint(testhelpers.NewNonceValue, 10), strconv.FormatUint(testhelpers.NewNonceValue, 10),
strconv.FormatInt(testhelpers.OldBalanceValue, 10),
strconv.FormatInt(testhelpers.NewBalanceValue, 10), strconv.FormatInt(testhelpers.NewBalanceValue, 10),
testhelpers.ContractRoot, testhelpers.ContractRoot,
testhelpers.ContractRoot,
testhelpers.StoragePath, testhelpers.StoragePath,
} }
@ -60,17 +54,12 @@ var expectedDeletedAccountRow = []string{
"deleted", "deleted",
"deleted account code", "deleted account code",
testhelpers.CodeHash, testhelpers.CodeHash,
strconv.FormatUint(testhelpers.OldNonceValue, 10),
strconv.FormatUint(testhelpers.NewNonceValue, 10), strconv.FormatUint(testhelpers.NewNonceValue, 10),
strconv.FormatInt(testhelpers.OldBalanceValue, 10),
strconv.FormatInt(testhelpers.NewBalanceValue, 10), strconv.FormatInt(testhelpers.NewBalanceValue, 10),
testhelpers.ContractRoot, testhelpers.ContractRoot,
testhelpers.ContractRoot,
testhelpers.StoragePath, testhelpers.StoragePath,
} }
func TestPublisher(t *testing.T) { func TestPublisher(t *testing.T) {
dir, err = ioutil.TempDir(tempDir, testFilePrefix) dir, err = ioutil.TempDir(tempDir, testFilePrefix)
if err != nil { if err != nil {

View File

@ -19,59 +19,29 @@ var (
StoragePath = "0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470" StoragePath = "0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470"
oldStorage = "0x0" oldStorage = "0x0"
newStorage = "0x03" newStorage = "0x03"
storage = map[string]builder.DiffString{StoragePath: { storage = map[string]builder.DiffString{StoragePath: { Value: &newStorage }}
NewValue: &newStorage,
OldValue: &oldStorage,
}}
address = common.HexToAddress("0xaE9BEa628c4Ce503DcFD7E305CaB4e29E7476592") address = common.HexToAddress("0xaE9BEa628c4Ce503DcFD7E305CaB4e29E7476592")
CreatedAccountDiffs = map[common.Address]builder.AccountDiffEventual{address: { CreatedAccountDiffs = map[common.Address]builder.AccountDiffEventual{address: {
Nonce: builder.DiffUint64{ Nonce: builder.DiffUint64{ Value: &NewNonceValue },
NewValue: &NewNonceValue, Balance: builder.DiffBigInt{ Value: big.NewInt(NewBalanceValue) },
OldValue: &OldNonceValue, ContractRoot: builder.DiffString{ Value: &ContractRoot },
},
Balance: builder.DiffBigInt{
NewValue: big.NewInt(NewBalanceValue),
OldValue: big.NewInt(OldBalanceValue),
},
ContractRoot: builder.DiffString{
NewValue: &ContractRoot,
OldValue: &ContractRoot,
},
Code: []byte("created account code"), Code: []byte("created account code"),
CodeHash: CodeHash, CodeHash: CodeHash,
Storage: storage, Storage: storage,
}} }}
UpdatedAccountDiffs = map[common.Address]builder.AccountDiffIncremental{address: { UpdatedAccountDiffs = map[common.Address]builder.AccountDiffIncremental{address: {
Nonce: builder.DiffUint64{ Nonce: builder.DiffUint64{ Value: &NewNonceValue },
NewValue: &NewNonceValue, Balance: builder.DiffBigInt{ Value: big.NewInt(NewBalanceValue) },
OldValue: &OldNonceValue,
},
Balance: builder.DiffBigInt{
NewValue: big.NewInt(NewBalanceValue),
OldValue: big.NewInt(OldBalanceValue),
},
CodeHash: CodeHash, CodeHash: CodeHash,
ContractRoot: builder.DiffString{ ContractRoot: builder.DiffString{ Value: &ContractRoot },
NewValue: &ContractRoot,
OldValue: &ContractRoot,
},
Storage: storage, Storage: storage,
}} }}
DeletedAccountDiffs = map[common.Address]builder.AccountDiffEventual{address: { DeletedAccountDiffs = map[common.Address]builder.AccountDiffEventual{address: {
Nonce: builder.DiffUint64{ Nonce: builder.DiffUint64{ Value: &NewNonceValue },
NewValue: &NewNonceValue, Balance: builder.DiffBigInt{ Value: big.NewInt(NewBalanceValue) },
OldValue: &OldNonceValue, ContractRoot: builder.DiffString{ Value: &ContractRoot },
},
Balance: builder.DiffBigInt{
NewValue: big.NewInt(NewBalanceValue),
OldValue: big.NewInt(OldBalanceValue),
},
ContractRoot: builder.DiffString{
NewValue: &ContractRoot,
OldValue: &ContractRoot,
},
Code: []byte("deleted account code"), Code: []byte("deleted account code"),
CodeHash: CodeHash, CodeHash: CodeHash,
Storage: storage, Storage: storage,