-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added migration to transform unicode erc20 unicode decimals to numeric * Fix: erc20 tokens decimals filling with numbers, instead of unicode string * Improved multicallErc20 token decimals assigning
- Loading branch information
Showing
6 changed files
with
92 additions
and
13 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 |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package migrations | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"github.com/dipdup-io/starknet-metadata/internal/storage" | ||
"github.com/rs/zerolog/log" | ||
"github.com/uptrace/bun" | ||
) | ||
|
||
func init() { | ||
DbMigrations.MustRegister(func(ctx context.Context, db *bun.DB) error { | ||
var erc20Tokens []storage.TokenMetadata | ||
err := db.NewSelect(). | ||
Model(&erc20Tokens). | ||
Where("type = ?", storage.TokenTypeERC20). | ||
Scan(ctx) | ||
|
||
if err != nil { | ||
fmt.Println("Error:", err) | ||
} | ||
|
||
for _, token := range erc20Tokens { | ||
if token.Metadata == nil { | ||
continue | ||
} | ||
unicodeDecimals, ok := token.Metadata["decimals"].(string) | ||
if !ok || unicodeDecimals == "" { | ||
continue | ||
} | ||
runeDecimals := []rune(unicodeDecimals)[0] | ||
token.Metadata["decimals"] = int(runeDecimals) | ||
_, err = db.NewUpdate(). | ||
Model(&token). | ||
Column("metadata"). | ||
Where("id = ?", token.Id). | ||
Exec(ctx) | ||
if err != nil { | ||
log.Err(err).Uint64("token id", token.Id).Msg("error updating token") | ||
} | ||
} | ||
log.Info(). | ||
Int("updated erc20 tokens amount", len(erc20Tokens)). | ||
Msg("migration applied") | ||
return nil | ||
|
||
}, func(ctx context.Context, db *bun.DB) error { | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package migrations | ||
|
||
import ( | ||
"github.com/uptrace/bun/migrate" | ||
) | ||
|
||
var DbMigrations = migrate.NewMigrations() |