-
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.
fix: array input and contract info setup
- Loading branch information
Showing
5 changed files
with
114 additions
and
84 deletions.
There are no files selected for viewing
7 changes: 4 additions & 3 deletions
7
cmd/solizard/embeds/address_book.json → cmd/solizard/embeds/contract_infos.json
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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
{ | ||
"ERC20": { | ||
[ | ||
{ | ||
"name": "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
This file was deleted.
Oops, something went wrong.
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,49 @@ | ||
package config | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"os" | ||
|
||
"github.com/ethereum/go-ethereum/common" | ||
) | ||
|
||
type ContractInfo struct { | ||
Name string `json:"name"` | ||
Address string `json:"address"` | ||
} | ||
|
||
func ReadContractInfos(path string) ([]ContractInfo, error) { | ||
data, err := os.ReadFile(path) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
var ci []ContractInfo | ||
if err = json.Unmarshal(data, &ci); err != nil { | ||
return nil, err | ||
} | ||
return ci, nil | ||
} | ||
|
||
func (ci ContractInfo) Validate() error { | ||
if ci.Name == "" { | ||
return fmt.Errorf("contract name is empty") | ||
} | ||
if ci.Address == "" { | ||
return fmt.Errorf("contract address is empty") | ||
} | ||
if !common.IsHexAddress(ci.Address) { | ||
return fmt.Errorf("contract address is invalid") | ||
} | ||
return nil | ||
} | ||
|
||
func ValidateContractInfos(cis []ContractInfo) error { | ||
for _, c := range cis { | ||
if err := c.Validate(); err != nil { | ||
return err | ||
} | ||
} | ||
return nil | ||
} |