-
Notifications
You must be signed in to change notification settings - Fork 826
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
Add export endpoint for oneoff export #2049
base: main
Are you sure you want to change the base?
Conversation
s := report.NewService(bk, ak, r.k, r.wk) | ||
r.reports[s.Name()] = s | ||
|
||
ctx = ctx.WithBlockTime(time.Now()) |
Check warning
Code scanning / CodeQL
Calling the system time Warning
go func() { | ||
err := s.Start(ctx) | ||
if err != nil { | ||
log.Printf("failed to start report: %v", err) | ||
} | ||
}() |
Check notice
Code scanning / CodeQL
Spawning a Go routine Note
go func() { | ||
defer inputfile.Close() | ||
defer outputfile.Close() | ||
|
||
scanner := bufio.NewScanner(inputfile) | ||
// optionally, resize scanner's capacity for lines over 64K, see next example | ||
for scanner.Scan() { | ||
address := scanner.Text() | ||
if accAddr, err := sdk.AccAddressFromBech32(address); err == nil { | ||
evmAddr, associated := r.k.GetEVMAddress(ctx, accAddr) | ||
report := &Report{ | ||
Account: address, | ||
} | ||
report.Associated = associated | ||
if !associated { | ||
defaultAddr := r.k.GetEVMAddressOrDefault(ctx, accAddr) | ||
report.EVMAddress = defaultAddr.Hex() | ||
} else { | ||
report.EVMAddress = evmAddr.Hex() | ||
report.EVMNonce = r.k.GetNonce(ctx, evmAddr) | ||
c := r.k.GetCode(ctx, evmAddr) | ||
report.IsEVMContract = len(c) > 0 | ||
} | ||
|
||
reportJSON, err := json.Marshal(report) | ||
if err != nil { | ||
log.Printf("failed to marshal report: %v", err) | ||
continue | ||
} | ||
|
||
// Append the JSON line to the file | ||
if _, err := outputfile.WriteString(string(reportJSON) + "\n"); err != nil { | ||
log.Printf("failed to write report: %v", err) | ||
continue | ||
} | ||
} | ||
} | ||
|
||
if err := scanner.Err(); err != nil { | ||
log.Fatal(err) | ||
} | ||
}() |
Check notice
Code scanning / CodeQL
Spawning a Go routine Note
|
||
go func() { | ||
defer inputfile.Close() | ||
defer outputfile.Close() |
Check warning
Code scanning / CodeQL
Writable file handle closed without error handling Warning
call to OpenFile
go func() { | ||
defer func() { | ||
file.Close() | ||
r.mx.Lock() | ||
r.s[name] = statusDone | ||
r.mx.Unlock() | ||
}() | ||
|
||
ak.IterateAccounts(ctx, func(account authtypes.AccountI) (stop bool) { | ||
if baseAcct, ok := account.(*authtypes.BaseAccount); ok { | ||
if _, multiOk := baseAcct.GetPubKey().(multisig.PubKey); multiOk { | ||
if _, err := file.WriteString(fmt.Sprintf("%s\n", baseAcct.GetAddress().String())); err != nil { | ||
log.Printf("failed to write report: %v", err) | ||
} | ||
} | ||
} | ||
return false | ||
}) | ||
}() |
Check notice
Code scanning / CodeQL
Spawning a Go routine Note
|
||
go func() { | ||
defer func() { | ||
file.Close() |
Check warning
Code scanning / CodeQL
Writable file handle closed without error handling Warning
call to OpenFile
go func() { | ||
defer func() { | ||
file.Close() | ||
r.mx.Lock() | ||
r.s[name] = statusDone | ||
r.mx.Unlock() | ||
}() | ||
|
||
balances := bank.GetAccountsBalances(ctx) | ||
|
||
for _, b := range balances { | ||
report := &Report{ | ||
Account: b.Address, | ||
} | ||
|
||
for _, c := range b.Coins { | ||
coin := &ReportCoin{ | ||
Denom: c.Denom, | ||
Amount: c.Amount, | ||
} | ||
|
||
r.decorateCoinWithDetails(c, ctx, coin) | ||
|
||
report.Coins = append(report.Coins, coin) | ||
} | ||
|
||
if accAddr, err := sdk.AccAddressFromBech32(b.Address); err == nil { | ||
evmAddr, associated := r.k.GetEVMAddress(ctx, accAddr) | ||
report.Associated = associated | ||
if !associated { | ||
defaultAddr := r.k.GetEVMAddressOrDefault(ctx, accAddr) | ||
report.EVMAddress = defaultAddr.Hex() | ||
} else { | ||
report.EVMAddress = evmAddr.Hex() | ||
report.EVMNonce = r.k.GetNonce(ctx, evmAddr) | ||
c := r.k.GetCode(ctx, evmAddr) | ||
report.IsEVMContract = len(c) > 0 | ||
} | ||
} else { | ||
report.Error = err | ||
} | ||
|
||
// Marshal the report to JSON | ||
reportJSON, err := json.Marshal(report) | ||
if err != nil { | ||
log.Printf("failed to marshal report: %v", err) | ||
continue | ||
} | ||
|
||
// Append the JSON line to the file | ||
if _, err := file.WriteString(string(reportJSON) + "\n"); err != nil { | ||
log.Printf("failed to write report: %v", err) | ||
continue | ||
} | ||
} | ||
}() |
Check notice
Code scanning / CodeQL
Spawning a Go routine Note
|
||
go func() { | ||
defer func() { | ||
file.Close() |
Check warning
Code scanning / CodeQL
Writable file handle closed without error handling Warning
call to OpenFile
var uniq = make(map[string]*Coin) | ||
for _, b := range balances { | ||
for _, c := range b.Coins { | ||
coin, ok := uniq[c.Denom] |
Check warning
Code scanning / CodeQL
Useless assignment to local variable Warning
Describe your changes and provide context
Testing performed to validate your change