Apply go fmt changes and cleanup
This commit is contained in:
parent
d30b4ea4f2
commit
69ad521482
@ -47,11 +47,9 @@ func (transformer Transformer) Execute(row utils.StorageDiffRow) error {
|
|||||||
if lookupErr != nil {
|
if lookupErr != nil {
|
||||||
return lookupErr
|
return lookupErr
|
||||||
}
|
}
|
||||||
//packed storage slots return a slice of decoded values
|
|
||||||
value, decodeErr := utils.Decode(row, metadata)
|
value, decodeErr := utils.Decode(row, metadata)
|
||||||
if decodeErr != nil {
|
if decodeErr != nil {
|
||||||
return decodeErr
|
return decodeErr
|
||||||
}
|
}
|
||||||
|
|
||||||
return transformer.Repository.Create(row.BlockHeight, row.BlockHash.Hex(), metadata, value)
|
return transformer.Repository.Create(row.BlockHeight, row.BlockHash.Hex(), metadata, value)
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,6 @@ func (repository *MockStorageRepository) Create(blockNumber int, blockHash strin
|
|||||||
repository.PassedBlockNumber = blockNumber
|
repository.PassedBlockNumber = blockNumber
|
||||||
repository.PassedBlockHash = blockHash
|
repository.PassedBlockHash = blockHash
|
||||||
repository.PassedMetadata = metadata
|
repository.PassedMetadata = metadata
|
||||||
|
|
||||||
repository.PassedValue = value
|
repository.PassedValue = value
|
||||||
return repository.CreateErr
|
return repository.CreateErr
|
||||||
}
|
}
|
||||||
|
@ -18,8 +18,9 @@ package utils
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/ethereum/go-ethereum/common"
|
|
||||||
"math/big"
|
"math/big"
|
||||||
|
|
||||||
|
"github.com/ethereum/go-ethereum/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Decode(row StorageDiffRow, metadata StorageValueMetadata) (interface{}, error) {
|
func Decode(row StorageDiffRow, metadata StorageValueMetadata) (interface{}, error) {
|
||||||
@ -61,25 +62,29 @@ func decodeAddress(raw []byte) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func decodePackedSlot(raw []byte, packedTypes map[int]ValueType) map[int]string {
|
func decodePackedSlot(raw []byte, packedTypes map[int]ValueType) map[int]string {
|
||||||
storageSlot := raw
|
storageSlotData := raw
|
||||||
var results = map[int]string{}
|
decodedStorageSlotItems := map[int]string{}
|
||||||
|
|
||||||
//the reason we're using a map and not a slice is that golang doesn't guarantee the order of a slice
|
|
||||||
numberOfTypes := len(packedTypes)
|
numberOfTypes := len(packedTypes)
|
||||||
for position := 0; position < numberOfTypes; position++ {
|
|
||||||
valueType := packedTypes[position]
|
|
||||||
lengthOfStorageSlot := len(storageSlot)
|
|
||||||
lengthOfItem := getNumberOfBytes(valueType)
|
|
||||||
itemStartingIndex := lengthOfStorageSlot - lengthOfItem
|
|
||||||
value := storageSlot[itemStartingIndex:]
|
|
||||||
decodedValue := decodeIndividualItems(value, valueType)
|
|
||||||
results[position] = decodedValue
|
|
||||||
|
|
||||||
//pop last item off slot before moving on
|
for position := 0; position < numberOfTypes; position++ {
|
||||||
storageSlot = storageSlot[0:itemStartingIndex]
|
//get length of remaining storage date
|
||||||
|
lengthOfStorageData := len(storageSlotData)
|
||||||
|
|
||||||
|
//get item details (type, length, starting index, value bytes)
|
||||||
|
itemType := packedTypes[position]
|
||||||
|
lengthOfItem := getNumberOfBytes(itemType)
|
||||||
|
itemStartingIndex := lengthOfStorageData - lengthOfItem
|
||||||
|
itemValueBytes := storageSlotData[itemStartingIndex:]
|
||||||
|
|
||||||
|
//decode item's bytes and set in results map
|
||||||
|
decodedValue := decodeIndividualItems(itemValueBytes, itemType)
|
||||||
|
decodedStorageSlotItems[position] = decodedValue
|
||||||
|
|
||||||
|
//pop last item off raw slot data before moving on
|
||||||
|
storageSlotData = storageSlotData[0:itemStartingIndex]
|
||||||
}
|
}
|
||||||
|
|
||||||
return results
|
return decodedStorageSlotItems
|
||||||
}
|
}
|
||||||
|
|
||||||
func decodeIndividualItems(itemBytes []byte, valueType ValueType) string {
|
func decodeIndividualItems(itemBytes []byte, valueType ValueType) string {
|
||||||
|
@ -17,10 +17,11 @@
|
|||||||
package utils_test
|
package utils_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"math/big"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
. "github.com/onsi/ginkgo"
|
. "github.com/onsi/ginkgo"
|
||||||
. "github.com/onsi/gomega"
|
. "github.com/onsi/gomega"
|
||||||
"math/big"
|
|
||||||
|
|
||||||
"github.com/vulcanize/vulcanizedb/libraries/shared/storage/utils"
|
"github.com/vulcanize/vulcanizedb/libraries/shared/storage/utils"
|
||||||
)
|
)
|
||||||
|
@ -33,8 +33,8 @@ type StorageValueMetadata struct {
|
|||||||
Name string
|
Name string
|
||||||
Keys map[Key]string
|
Keys map[Key]string
|
||||||
Type ValueType
|
Type ValueType
|
||||||
PackedNames map[int]string //name of each item packed and their order
|
PackedNames map[int]string //position in map (zero indexed) => name of packed item
|
||||||
PackedTypes map[int]ValueType //type of each item packed and their order
|
PackedTypes map[int]ValueType //position in map (zero indexed)=> type of packed item
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetStorageValueMetadata(name string, keys map[Key]string, valueType ValueType) StorageValueMetadata {
|
func GetStorageValueMetadata(name string, keys map[Key]string, valueType ValueType) StorageValueMetadata {
|
||||||
|
Loading…
Reference in New Issue
Block a user