Skip to content
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

Merged
merged 3 commits into from
Feb 15, 2024
Merged

Conversation

hoank101
Copy link
Contributor

@hoank101 hoank101 commented Feb 14, 2024

  • Export genesis osmosis, snapshot time -> 13-Feb-2024 12:40
  • Run script export list osmosis address hold dig token

Summary by CodeRabbit

  • New Features
    • Introduced a tool to parse and export specific data from large JSON files to CSV, aimed at processing balances and other relevant information.
    • Added documentation for exporting Osmosis genesis files and DIG holder addresses.

Comment on lines 119 to 126
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

Iteration over map may be a possible source of non-determinism
Copy link

coderabbitai bot commented Feb 15, 2024

Walkthrough

This 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

File Path Change Summary
scripts/export_dig_holder.go Added a new Go script for parsing JSON files, calculating balances, and exporting to CSV.
scripts/readme.md Added documentation for exporting Osmosis genesis file and DIG holder addresses.

"In the realm of code and endless night,
A rabbit hopped, spreading light.
With a script in paw and guide at side,
It parsed and calculated, wide-eyed.
🌟 To CSV, the data did glide,
A hop, a skip, in bytes they confide."

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?

Share

Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit-tests for this file.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit tests for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

Copy link

sonarcloud bot commented Feb 15, 2024

Quality Gate Passed Quality Gate passed

Issues
2 New issues

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

@faddat faddat added this pull request to the merge queue Feb 15, 2024
Merged via the queue into master with commit a238699 Feb 15, 2024
5 of 6 checks passed
Copy link

@coderabbitai coderabbitai bot left a 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

Commits Files that changed from the base of the PR and between 8d3986b and b651e58.
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
Copy link

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.

Suggested change
filePath := "/Users/hoank/export.json" // path of genesis file in your server
// Use flag package or os.Getenv to make the file path configurable

Comment on lines +19 to +84
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
Copy link

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.

Suggested change
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
}

Comment on lines +95 to +100
module_address := []string{
"osmo1szvslwsxf3y2s4lt3c7e7mm92zgy44j8krruht5zzanmhrjwyc4qqpt5nz", //pool #621 dig/osmo
"osmo1rqamy6jc3f0rwrg5xz8hy8q7n932t2488f2gqg3d0cadvd3uqaxq4wazn8", // contract address
"osmo18rqwcrvsfyy9s2tlfvmchclxf2cfw2hqvrjvkuljcrhq2vpg4suse8h6tj", // pool #620
"osmo125dgaejga0q9wc6jcpf75lh6aeeyvrdz88xvzd", // ibc-accout
}
Copy link

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.

Suggested change
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

Comment on lines +113 to +116
// Optionally write headers, if needed
err = writer.Write([]string{"Address", "Balance"})
if err != nil {
return
Copy link

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.

Suggested change
// 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

Comment on lines +121 to +122
if slices.Contains(module_address, addr) {
continue
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants