Skip to content

Commit

Permalink
default assets: overwrite and add bsc tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
Thykof committed Jun 5, 2024
1 parent 6bbbff6 commit 7306f65
Showing 1 changed file with 57 additions and 10 deletions.
67 changes: 57 additions & 10 deletions pkg/assets/default_assets.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,30 @@ func (s *AssetsStore) InitDefault() error {
return err
}

if _, err := os.Stat(defaultAssetsJSONPath); os.IsNotExist(err) {
if err := s.createFileDefault(defaultAssetsJSONPath); err != nil {
// if the file does not exist, create the default assets JSON file
_, err = os.Stat(defaultAssetsJSONPath)
if os.IsNotExist(err) {
// Create the default assets JSON file
return s.createFileDefault(defaultAssetsJSONPath)
}

// if the file exists, read the content and compare it with the default assets
if err == nil {
// read the content of the default assets JSON file
content, err := os.ReadFile(defaultAssetsJSONPath)
if err != nil {
return err
}

// if the content is different, overwrite the default assets JSON file
if string(content) != assetsJSON {
if err := s.createFileDefault(defaultAssetsJSONPath); err != nil {
return err
}
}
}

return nil
return err
}

// getDefaultJSONPath returns the path to the default assets JSON file.
Expand All @@ -69,7 +86,14 @@ func getDefaultJSONPath(assetsJSONDir string) (string, error) {

// createFileDefault creates the default assets JSON file with the default assets.
func (s *AssetsStore) createFileDefault(path string) error {
if err := os.WriteFile(path, []byte(`[
if err := os.WriteFile(path, []byte(assetsJSON), permissionUrwGrOr); err != nil {
return err
}

return nil
}

const assetsJSON = `[
{
"address": "AS12k8viVmqPtRuXzCm6rKXjLgpQWqbuMjc37YHhB452KSUUb9FgL",
"name": "Sepolia USDC",
Expand Down Expand Up @@ -118,10 +142,33 @@ func (s *AssetsStore) createFileDefault(path string) error {
"symbol": "WETH.e",
"decimals": 18,
"MEXCSymbol": "ETHUSDT"
},
{
"address": "",
"name": "Wrapped Ether",
"symbol": "WETH.b",
"decimals": 18,
"MEXCSymbol": "ETHUSDT"
},
{
"address": "",
"name": "Wrapped Binance USD",
"symbol": "USDT.b",
"decimals": 18,
"MEXCSymbol": "USD"
},
{
"address": "AS12RmCXTA9NZaTBUBnRJuH66AGNmtEfEoqXKxLdmrTybS6GFJPFs",
"name": "Wrapped Ether",
"symbol": "WETH.bt",
"decimals": 18,
"MEXCSymbol": "ETHUSDT"
},
{
"address": "AS12ix1Qfpue7BB8q6mWVtjNdNE9UV3x4MaUo7WhdUubov8sJ3CuP",
"name": "Wrapped Binance USD",
"symbol": "USDT.bt",
"decimals": 18,
"MEXCSymbol": "USD"
}
]`), permissionUrwGrOr); err != nil {
return err
}

return nil
}
]`

0 comments on commit 7306f65

Please sign in to comment.