-
Notifications
You must be signed in to change notification settings - Fork 68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: add list address dig holders in osmosis chain #639
Conversation
scripts/export_dig_holder.go
Outdated
for addr, balance := range mapAddr { | ||
totalBalance += balance | ||
if slices.Contains(module_address, addr) { | ||
continue | ||
} | ||
row := []string{addr, fmt.Sprint(balance)} | ||
writer.Write(row) | ||
} |
Check warning
Code scanning / CodeQL
Iteration over map Warning
WalkthroughThis update introduces a new Go script and documentation to facilitate the export of specific data from the Osmosis genesis file and DIG holder addresses. It simplifies the process of parsing large JSON files, calculating balances, and exporting this information into a CSV format. Additionally, a README file is provided to guide users through the export process, making it easier to manage and analyze blockchain data. Changes
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
Quality Gate passedIssues Measures |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 5
Configuration used: CodeRabbit UI
Files ignored due to path filters (1)
scripts/output.csv
is excluded by:!**/*.csv
Files selected for processing (2)
- scripts/export_dig_holder.go (1 hunks)
- scripts/readme.md (1 hunks)
Additional comments: 1
scripts/readme.md (1)
- 1-12: The instructions are clear and concise.
func main() { | ||
|
||
// snapshot time -> 13-Feb-2024 12:40 | ||
filePath := "/Users/hoank/export.json" // path of genesis file in your server |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hardcoded file path in filePath
variable. Consider making this configurable through command-line arguments or environment variables.
- filePath := "/Users/hoank/export.json" // path of genesis file in your server
+ // Use flag package or os.Getenv to make the file path configurable
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
filePath := "/Users/hoank/export.json" // path of genesis file in your server | |
// Use flag package or os.Getenv to make the file path configurable |
func findTextInLargeFile(filePath string, searchText string) bool { | ||
file, err := os.Open(filePath) | ||
if err != nil { | ||
fmt.Println("File not found.") | ||
return false | ||
} | ||
defer file.Close() | ||
|
||
const chunkSize = 1024 * 1024 * 10 // 10 MB chunk size, adjust as needed | ||
reader := bufio.NewReader(file) | ||
buffer := make([]byte, chunkSize) | ||
|
||
for { | ||
n, err := reader.Read(buffer) | ||
if err != nil && err.Error() != "EOF" { | ||
fmt.Println("Error reading file:", err) | ||
break | ||
} | ||
if n == 0 { | ||
break | ||
} | ||
chunk := string(buffer[:n]) | ||
if strings.Contains(chunk, searchText) { | ||
tmps := strings.Split(chunk, "},{\"address") | ||
for _, tmp := range tmps { | ||
s := "{\"address" + tmp + "}" | ||
var result map[string]interface{} | ||
if err := json.Unmarshal([]byte(s), &result); err != nil { | ||
continue | ||
} | ||
coins, ok := result["coins"].([]interface{}) | ||
if !ok { | ||
continue | ||
} | ||
balance := 0 | ||
for _, coin := range coins { | ||
coinMap, ok := coin.(map[string]interface{}) | ||
if !ok { | ||
continue | ||
} | ||
if coinMap["denom"] == DigIbcDenom { | ||
amountStr, ok := coinMap["amount"].(string) | ||
if !ok { | ||
fmt.Println("Amount is not a string") | ||
continue | ||
} | ||
amount, err := strconv.ParseFloat(amountStr, 64) | ||
if err != nil { | ||
fmt.Println("Error converting amount to float:", err) | ||
continue | ||
} | ||
balance = int(amount) | ||
break | ||
} | ||
} | ||
address, ok := result["address"].(string) | ||
if balance > 0 && ok && mapAddr[address] == 0 { | ||
mapAddr[address] = balance | ||
} | ||
} | ||
} | ||
if err != nil { | ||
break | ||
} | ||
} | ||
return true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The findTextInLargeFile
function lacks error handling for JSON unmarshalling and does not log or handle errors beyond continuing the loop. Consider adding error logging for debugging purposes.
- if err := json.Unmarshal([]byte(s), &result); err != nil {
- continue
+ if err := json.Unmarshal([]byte(s), &result); err != nil {
+ fmt.Println("Error unmarshalling JSON:", err)
+ continue
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
func findTextInLargeFile(filePath string, searchText string) bool { | |
file, err := os.Open(filePath) | |
if err != nil { | |
fmt.Println("File not found.") | |
return false | |
} | |
defer file.Close() | |
const chunkSize = 1024 * 1024 * 10 // 10 MB chunk size, adjust as needed | |
reader := bufio.NewReader(file) | |
buffer := make([]byte, chunkSize) | |
for { | |
n, err := reader.Read(buffer) | |
if err != nil && err.Error() != "EOF" { | |
fmt.Println("Error reading file:", err) | |
break | |
} | |
if n == 0 { | |
break | |
} | |
chunk := string(buffer[:n]) | |
if strings.Contains(chunk, searchText) { | |
tmps := strings.Split(chunk, "},{\"address") | |
for _, tmp := range tmps { | |
s := "{\"address" + tmp + "}" | |
var result map[string]interface{} | |
if err := json.Unmarshal([]byte(s), &result); err != nil { | |
continue | |
} | |
coins, ok := result["coins"].([]interface{}) | |
if !ok { | |
continue | |
} | |
balance := 0 | |
for _, coin := range coins { | |
coinMap, ok := coin.(map[string]interface{}) | |
if !ok { | |
continue | |
} | |
if coinMap["denom"] == DigIbcDenom { | |
amountStr, ok := coinMap["amount"].(string) | |
if !ok { | |
fmt.Println("Amount is not a string") | |
continue | |
} | |
amount, err := strconv.ParseFloat(amountStr, 64) | |
if err != nil { | |
fmt.Println("Error converting amount to float:", err) | |
continue | |
} | |
balance = int(amount) | |
break | |
} | |
} | |
address, ok := result["address"].(string) | |
if balance > 0 && ok && mapAddr[address] == 0 { | |
mapAddr[address] = balance | |
} | |
} | |
} | |
if err != nil { | |
break | |
} | |
} | |
return true | |
func findTextInLargeFile(filePath string, searchText string) bool { | |
file, err := os.Open(filePath) | |
if err != nil { | |
fmt.Println("File not found.") | |
return false | |
} | |
defer file.Close() | |
const chunkSize = 1024 * 1024 * 10 // 10 MB chunk size, adjust as needed | |
reader := bufio.NewReader(file) | |
buffer := make([]byte, chunkSize) | |
for { | |
n, err := reader.Read(buffer) | |
if err != nil && err.Error() != "EOF" { | |
fmt.Println("Error reading file:", err) | |
break | |
} | |
if n == 0 { | |
break | |
} | |
chunk := string(buffer[:n]) | |
if strings.Contains(chunk, searchText) { | |
tmps := strings.Split(chunk, "},{\"address") | |
for _, tmp := range tmps { | |
s := "{\"address" + tmp + "}" | |
var result map[string]interface{} | |
if err := json.Unmarshal([]byte(s), &result); err != nil { | |
fmt.Println("Error unmarshalling JSON:", err) | |
continue | |
} | |
coins, ok := result["coins"].([]interface{}) | |
if !ok { | |
continue | |
} | |
balance := 0 | |
for _, coin := range coins { | |
coinMap, ok := coin.(map[string]interface{}) | |
if !ok { | |
continue | |
} | |
if coinMap["denom"] == DigIbcDenom { | |
amountStr, ok := coinMap["amount"].(string) | |
if !ok { | |
fmt.Println("Amount is not a string") | |
continue | |
} | |
amount, err := strconv.ParseFloat(amountStr, 64) | |
if err != nil { | |
fmt.Println("Error converting amount to float:", err) | |
continue | |
} | |
balance = int(amount) | |
break | |
} | |
} | |
address, ok := result["address"].(string) | |
if balance > 0 && ok && mapAddr[address] == 0 { | |
mapAddr[address] = balance | |
} | |
} | |
} | |
if err != nil { | |
break | |
} | |
} | |
return true | |
} |
module_address := []string{ | ||
"osmo1szvslwsxf3y2s4lt3c7e7mm92zgy44j8krruht5zzanmhrjwyc4qqpt5nz", //pool #621 dig/osmo | ||
"osmo1rqamy6jc3f0rwrg5xz8hy8q7n932t2488f2gqg3d0cadvd3uqaxq4wazn8", // contract address | ||
"osmo18rqwcrvsfyy9s2tlfvmchclxf2cfw2hqvrjvkuljcrhq2vpg4suse8h6tj", // pool #620 | ||
"osmo125dgaejga0q9wc6jcpf75lh6aeeyvrdz88xvzd", // ibc-accout | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The module_address
slice contains hardcoded addresses. If these addresses are subject to change, consider externalizing them to a configuration file or environment variables.
- module_address := []string{
- "osmo1szvslwsxf3y2s4lt3c7e7mm92zgy44j8krruht5zzanmhrjwyc4qqpt5nz", //pool #621 dig/osmo
- ...
+ // Consider loading these addresses from a configuration file or environment variables
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
module_address := []string{ | |
"osmo1szvslwsxf3y2s4lt3c7e7mm92zgy44j8krruht5zzanmhrjwyc4qqpt5nz", //pool #621 dig/osmo | |
"osmo1rqamy6jc3f0rwrg5xz8hy8q7n932t2488f2gqg3d0cadvd3uqaxq4wazn8", // contract address | |
"osmo18rqwcrvsfyy9s2tlfvmchclxf2cfw2hqvrjvkuljcrhq2vpg4suse8h6tj", // pool #620 | |
"osmo125dgaejga0q9wc6jcpf75lh6aeeyvrdz88xvzd", // ibc-accout | |
} | |
// Consider loading these addresses from a configuration file or environment variables |
// Optionally write headers, if needed | ||
err = writer.Write([]string{"Address", "Balance"}) | ||
if err != nil { | ||
return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing error handling after writing headers to the CSV file. If an error occurs, it should be logged or handled appropriately.
- err = writer.Write([]string{"Address", "Balance"})
- if err != nil {
- return
+ err = writer.Write([]string{"Address", "Balance"})
+ if err != nil {
+ fmt.Println("Error writing headers to CSV:", err)
+ return
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
// Optionally write headers, if needed | |
err = writer.Write([]string{"Address", "Balance"}) | |
if err != nil { | |
return | |
// Optionally write headers, if needed | |
err = writer.Write([]string{"Address", "Balance"}) | |
if err != nil { | |
fmt.Println("Error writing headers to CSV:", err) | |
return |
if slices.Contains(module_address, addr) { | ||
continue |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using slices.Contains
to filter out specific addresses. Ensure that this is the intended behavior and consider if there's a more efficient way to handle exclusions, especially if the list grows.
Consider using a map for module_address
for O(1) lookups instead of O(n) with slices.Contains
.
Summary by CodeRabbit