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

Add export endpoint for oneoff export #2049

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

stevenlanders
Copy link
Contributor

Describe your changes and provide context

Testing performed to validate your change

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

Calling the system time may be a possible source of non-determinism
Comment on lines +101 to +106
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

Spawning a Go routine may be a possible source of non-determinism
Comment on lines +124 to +165
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

Spawning a Go routine may be a possible source of non-determinism

go func() {
defer inputfile.Close()
defer outputfile.Close()

Check warning

Code scanning / CodeQL

Writable file handle closed without error handling Warning

File handle may be writable as a result of data flow from a
call to OpenFile
and closing it may result in data loss upon failure, which is not handled explicitly.
Comment on lines +194 to +212
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

Spawning a Go routine may be a possible source of non-determinism

go func() {
defer func() {
file.Close()

Check warning

Code scanning / CodeQL

Writable file handle closed without error handling Warning

File handle may be writable as a result of data flow from a
call to OpenFile
and closing it may result in data loss upon failure, which is not handled explicitly.
Comment on lines +241 to +296
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

Spawning a Go routine may be a possible source of non-determinism

go func() {
defer func() {
file.Close()

Check warning

Code scanning / CodeQL

Writable file handle closed without error handling Warning

File handle may be writable as a result of data flow from a
call to OpenFile
and closing it may result in data loss upon failure, which is not handled explicitly.
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

This definition of coin is never used.
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.

1 participant