-
Notifications
You must be signed in to change notification settings - Fork 2
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
Showing
4 changed files
with
123 additions
and
20 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"ERC20": { | ||
"address": "0xdAC17F958D2ee523a2206206994597C13D831ec7" | ||
} | ||
} |
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,44 @@ | ||
package config | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"os" | ||
|
||
"github.com/ethereum/go-ethereum/common" | ||
) | ||
|
||
type AddressBook map[string]struct { | ||
Address string `json:"address"` | ||
} | ||
|
||
// ReadAddressBook reads the address book from the given path | ||
func ReadAddressBook(path string) (AddressBook, error) { | ||
data, err := os.ReadFile(path) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
var ab AddressBook | ||
if err = json.Unmarshal(data, &ab); err != nil { | ||
return nil, err | ||
} | ||
return ab, nil | ||
} | ||
|
||
func (ab AddressBook) Validate() error { | ||
// check if the address book is empty | ||
if len(ab) == 0 { | ||
return fmt.Errorf("address book is empty") | ||
} | ||
for name, entry := range ab { | ||
if entry.Address == "" { | ||
return fmt.Errorf("address book entry %s has empty address", name) | ||
} | ||
if !common.IsHexAddress(entry.Address) { | ||
return fmt.Errorf("address book entry %s has invalid address", name) | ||
} | ||
} | ||
|
||
return nil | ||
} |
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