Skip to content

Commit

Permalink
Fix asset decimal pointer (#904)
Browse files Browse the repository at this point in the history
* clean code

* create a copy of the decimal value
  • Loading branch information
Thykof authored Apr 4, 2024
1 parent 570f1bc commit a8f8f1b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
9 changes: 5 additions & 4 deletions pkg/assets/asset.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ func NewAssetsStore(assetsJSONPath string) (*AssetsStore, error) {
store := &AssetsStore{
Assets: make(map[string]Assets),
}
if err := store.loadaccountsStore(assetsJSONPath); err != nil {
if err := store.loadAccountsStore(assetsJSONPath); err != nil {
return nil, errors.Wrap(err, "failed to create AssetsStore")
}

return store, nil
}

// loadaccountsStore loads the data from the assets JSON file into the AssetsStore.
func (s *AssetsStore) loadaccountsStore(assetsJSONPath string) error {
// loadAccountsStore loads the data from the assets JSON file into the AssetsStore.
func (s *AssetsStore) loadAccountsStore(assetsJSONPath string) error {
// Check if the file exists, and if not, create a new one with an empty object
if _, err := os.Stat(assetsJSONPath); os.IsNotExist(err) {
if err := createJSONFile(assetsJSONPath); err != nil {
Expand Down Expand Up @@ -85,11 +85,12 @@ func (s *AssetsStore) loadaccountsStore(assetsJSONPath string) error {
}

for _, asset := range accountData.Assets {
decimals := asset.Decimals // Copy the decimals value to avoid a pointer to a local variable
assetInfo := models.AssetInfo{
Address: asset.ContractAddress,
Name: asset.Name,
Symbol: asset.Symbol,
Decimals: &asset.Decimals,
Decimals: &decimals,
}
accountAssets.ContractAssets[asset.ContractAddress] = assetInfo
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/types/address.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (a *Address) validate() error {
return nil
}

// Custom YAML marshaller for EncryptedPrivateKey
// Custom YAML marshaller for Address
func (a Address) MarshalYAML() (interface{}, error) {
data, err := a.MarshalText()

Expand Down

0 comments on commit a8f8f1b

Please sign in to comment.