-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5c38c83
commit bfec573
Showing
9 changed files
with
89 additions
and
190 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package environment | ||
|
||
type AddressBook interface { | ||
// TODO: Need manualTV override | ||
Save(chainSelector uint64, address string) error | ||
Addresses() (map[uint64]map[string]struct{}, error) | ||
// Allows for merging address books | ||
Merge(other AddressBook) error | ||
} | ||
|
||
type AddressBookMap struct { | ||
AddressesByChain map[uint64]map[string]struct{} | ||
} | ||
|
||
func (m *AddressBookMap) Save(chainSelector uint64, address string) error { | ||
if _, exists := m.AddressesByChain[chainSelector]; !exists { | ||
m.AddressesByChain[chainSelector] = make(map[string]struct{}) | ||
} else { | ||
// Error? | ||
} | ||
m.AddressesByChain[chainSelector][address] = struct{}{} | ||
return nil | ||
} | ||
|
||
func (m *AddressBookMap) Addresses() (map[uint64]map[string]struct{}, error) { | ||
return m.AddressesByChain, nil | ||
} | ||
|
||
// Attention this will mutate existing book | ||
func (m *AddressBookMap) Merge(ab AddressBook) error { | ||
addresses, err := ab.Addresses() | ||
if err != nil { | ||
return err | ||
} | ||
for chain, chainAddresses := range addresses { | ||
for address := range chainAddresses { | ||
return m.Save(chain, address) | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
func NewMemoryAddressBook() *AddressBookMap { | ||
return &AddressBookMap{ | ||
AddressesByChain: make(map[uint64]map[string]struct{}), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package environment |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.