Use map for key in storage value metadata
- Enables inserting multiple keys for one storage row (e.g. ilk and urn)
This commit is contained in:
parent
09abcb841a
commit
dba4e48a3e
@ -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,
|
||||
}
|
||||
}
|
||||
|
@ -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,
|
||||
}
|
||||
|
||||
|
@ -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:
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user