-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add validator list fixer * Add ETH asset's checsum fixer * Fix renaming logic
- Loading branch information
Showing
7 changed files
with
96 additions
and
47 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
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,32 +1,49 @@ | ||
package core | ||
|
||
import ( | ||
"bytes" | ||
"encoding/json" | ||
"io/ioutil" | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
|
||
"github.com/trustwallet/assets-go-libs/pkg" | ||
"github.com/trustwallet/assets-go-libs/pkg/file" | ||
"github.com/trustwallet/assets-go-libs/pkg/validation" | ||
"github.com/trustwallet/go-primitives/address" | ||
"github.com/trustwallet/go-primitives/coin" | ||
|
||
log "github.com/sirupsen/logrus" | ||
) | ||
|
||
func (s *Service) FixInfoJSON(file *file.AssetFile) error { | ||
jsonFile, err := os.Open(file.Info.Path()) | ||
if err != nil { | ||
return err | ||
} | ||
defer jsonFile.Close() | ||
func (s *Service) FixJSON(file *file.AssetFile) error { | ||
return pkg.FormatJSONFile(file.Info.Path()) | ||
} | ||
|
||
data, err := ioutil.ReadAll(jsonFile) | ||
if err != nil { | ||
return err | ||
func (s *Service) FixETHAddressChecksum(file *file.AssetFile) error { | ||
if !coin.IsEVM(file.Info.Chain().ID) { | ||
return nil | ||
} | ||
|
||
var prettyJSON bytes.Buffer | ||
assetDir := filepath.Base(file.Info.Path()) | ||
|
||
err = json.Indent(&prettyJSON, data, "", " ") | ||
err := validation.ValidateETHForkAddress(file.Info.Chain(), assetDir) | ||
if err != nil { | ||
return err | ||
checksum, e := address.EIP55Checksum(assetDir) | ||
if e != nil { | ||
return fmt.Errorf("failed to get checksum: %s", e) | ||
} | ||
|
||
newName := fmt.Sprintf("blockchains/%s/assets/%s", file.Info.Chain().Handle, checksum) | ||
|
||
if e = os.Rename(file.Info.Path(), newName); e != nil { | ||
return fmt.Errorf("failed to rename dir: %s", e) | ||
} | ||
|
||
s.fileService.UpdateFile(file, checksum) | ||
|
||
log.WithField("from", assetDir). | ||
WithField("to", checksum). | ||
Debug("Renamed asset") | ||
} | ||
|
||
return ioutil.WriteFile(file.Info.Path(), prettyJSON.Bytes(), 0600) | ||
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
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