From dba4e48a3ec26df2349db3db90ff890a4a84bfa8 Mon Sep 17 00:00:00 2001 From: Rob Mulholand Date: Tue, 5 Feb 2019 16:22:26 -0600 Subject: [PATCH] Use map for key in storage value metadata - Enables inserting multiple keys for one storage row (e.g. ilk and urn) --- pkg/transformers/storage_diffs/maker/pit/mappings.go | 12 ++++++------ .../storage_diffs/maker/pit/mappings_test.go | 4 ++-- .../storage_diffs/maker/pit/repository.go | 4 ++-- .../storage_diffs/maker/pit/repository_test.go | 4 ++-- pkg/transformers/storage_diffs/shared/value.go | 8 +++++++- 5 files changed, 19 insertions(+), 13 deletions(-) diff --git a/pkg/transformers/storage_diffs/maker/pit/mappings.go b/pkg/transformers/storage_diffs/maker/pit/mappings.go index 4b9d299a..2533077f 100644 --- a/pkg/transformers/storage_diffs/maker/pit/mappings.go +++ b/pkg/transformers/storage_diffs/maker/pit/mappings.go @@ -40,7 +40,7 @@ var ( DripKey = common.HexToHash(storage_diffs.IndexFive) DripMetadata = shared.StorageValueMetadata{ Name: PitDrip, - Key: "", + Keys: nil, Type: shared.Address, } @@ -50,7 +50,7 @@ var ( LineKey = common.HexToHash(storage_diffs.IndexThree) LineMetadata = shared.StorageValueMetadata{ Name: PitLine, - Key: "", + Keys: nil, Type: shared.Uint256, } @@ -58,7 +58,7 @@ var ( LiveKey = common.HexToHash(storage_diffs.IndexTwo) LiveMetadata = shared.StorageValueMetadata{ Name: PitLive, - Key: "", + Keys: nil, Type: shared.Uint256, } @@ -66,7 +66,7 @@ var ( VatKey = common.HexToHash(storage_diffs.IndexFour) VatMetadata = shared.StorageValueMetadata{ Name: PitVat, - Key: "", + Keys: nil, Type: shared.Address, } ) @@ -126,7 +126,7 @@ func getSpotKey(ilk string) common.Hash { func getSpotMetadata(ilk string) shared.StorageValueMetadata { return shared.StorageValueMetadata{ Name: IlkSpot, - Key: ilk, + Keys: map[shared.Key]string{shared.Ilk: ilk}, Type: shared.Uint256, } } @@ -140,7 +140,7 @@ func getLineKey(ilk string) common.Hash { func getLineMetadata(ilk string) shared.StorageValueMetadata { return shared.StorageValueMetadata{ Name: IlkLine, - Key: ilk, + Keys: map[shared.Key]string{shared.Ilk: ilk}, Type: shared.Uint256, } } diff --git a/pkg/transformers/storage_diffs/maker/pit/mappings_test.go b/pkg/transformers/storage_diffs/maker/pit/mappings_test.go index 2bbb22aa..72331b58 100644 --- a/pkg/transformers/storage_diffs/maker/pit/mappings_test.go +++ b/pkg/transformers/storage_diffs/maker/pit/mappings_test.go @@ -52,7 +52,7 @@ var _ = Describe("Pit storage mappings", func() { ilkSpotKey := common.BytesToHash(crypto.Keccak256(common.FromHex("0x" + fakeIlk + pit.IlkSpotIndex))) expectedMetadata := shared.StorageValueMetadata{ Name: pit.IlkSpot, - Key: fakeIlk, + Keys: map[shared.Key]string{shared.Ilk: fakeIlk}, Type: shared.Uint256, } @@ -70,7 +70,7 @@ var _ = Describe("Pit storage mappings", func() { ilkLineKey := common.BytesToHash(incrementedIlkSpot.Bytes()) expectedMetadata := shared.StorageValueMetadata{ Name: pit.IlkLine, - Key: fakeIlk, + Keys: map[shared.Key]string{shared.Ilk: fakeIlk}, Type: shared.Uint256, } diff --git a/pkg/transformers/storage_diffs/maker/pit/repository.go b/pkg/transformers/storage_diffs/maker/pit/repository.go index a1c5c9df..cedb5663 100644 --- a/pkg/transformers/storage_diffs/maker/pit/repository.go +++ b/pkg/transformers/storage_diffs/maker/pit/repository.go @@ -32,9 +32,9 @@ func (repository *PitStorageRepository) SetDB(db *postgres.DB) { func (repository PitStorageRepository) Create(blockNumber int, blockHash string, metadata shared.StorageValueMetadata, value interface{}) error { switch metadata.Name { case IlkLine: - return repository.insertIlkLine(blockNumber, blockHash, metadata.Key, value.(string)) + return repository.insertIlkLine(blockNumber, blockHash, metadata.Keys[shared.Ilk], value.(string)) case IlkSpot: - return repository.insertIlkSpot(blockNumber, blockHash, metadata.Key, value.(string)) + return repository.insertIlkSpot(blockNumber, blockHash, metadata.Keys[shared.Ilk], value.(string)) case PitDrip: return repository.insertPitDrip(blockNumber, blockHash, value.(string)) case PitLine: diff --git a/pkg/transformers/storage_diffs/maker/pit/repository_test.go b/pkg/transformers/storage_diffs/maker/pit/repository_test.go index 97f3ac3f..84e63653 100644 --- a/pkg/transformers/storage_diffs/maker/pit/repository_test.go +++ b/pkg/transformers/storage_diffs/maker/pit/repository_test.go @@ -48,7 +48,7 @@ var _ = Describe("Pit storage repository", func() { expectedLine := "12345" ilkLineMetadata := shared.StorageValueMetadata{ Name: pit.IlkLine, - Key: expectedIlk, + Keys: map[shared.Key]string{shared.Ilk: expectedIlk}, Type: shared.Uint256, } err = repo.Create(blockNumber, blockHash, ilkLineMetadata, expectedLine) @@ -73,7 +73,7 @@ var _ = Describe("Pit storage repository", func() { expectedSpot := "12345" ilkSpotMetadata := shared.StorageValueMetadata{ Name: pit.IlkSpot, - Key: expectedIlk, + Keys: map[shared.Key]string{shared.Ilk: expectedIlk}, Type: shared.Uint256, } err = repo.Create(blockNumber, blockHash, ilkSpotMetadata, expectedSpot) diff --git a/pkg/transformers/storage_diffs/shared/value.go b/pkg/transformers/storage_diffs/shared/value.go index d19d95b5..965f301f 100644 --- a/pkg/transformers/storage_diffs/shared/value.go +++ b/pkg/transformers/storage_diffs/shared/value.go @@ -24,8 +24,14 @@ const ( Address ) +type Key int + +const ( + Ilk Key = iota +) + type StorageValueMetadata struct { Name string - Key string + Keys map[Key]string Type ValueType }