-
Notifications
You must be signed in to change notification settings - Fork 194
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
Feature/port chifra abis #2661
Merged
Merged
Feature/port chifra abis #2661
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
52a4810
WIP: Load* functions
dszlachta bb45d6b
Fixed known paths
dszlachta da7a9a7
Renamed pkg/articulation to pkg/abi
dszlachta 3e3a59a
Added cache read/write functions for ABIs
dszlachta f62a19a
Added Set/Get cache functions for ABIs
dszlachta e14bcb0
WIP: loading ABIs from cache and json files
dszlachta 9b15af1
Fixed reading known files
dszlachta c1abe2b
Fixed known json files (valid JSON, valid SimpleFunction)
dszlachta 34c5b16
Fixed binary cache build
dszlachta 670e71f
WIP: LoadAbiFromAddress
dszlachta e838994
Fixed abi/known/moloch.json
dszlachta 32cc583
Fixes for abi loading
dszlachta a45ed10
WIP: Routed basic abis command through new code
dszlachta 676e3cc
Fixed all non-API tests
dszlachta a1b2ba2
Removed constructor and anonymous fn filtering
dszlachta 20ad816
Fixed API tests
dszlachta 1479483
Fixed chifra abis --find tests
dszlachta fd4eb54
Added ABI downloading
dszlachta c937bcf
Minor fix
dszlachta 68659ab
Added flushing stdout
dszlachta 29f9535
Better Etherscan error handling
dszlachta 4dd7ecf
Revert "Added flushing stdout"
dszlachta 72ebce6
Fixed cache filename bug
dszlachta 74f1a97
Fixed gold tests
dszlachta File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Fixed chifra abis --find tests
- Loading branch information
commit 1479483118d1cd2fef2d2523af16161cc270ab85
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ package abisPkg | |
import ( | ||
"bufio" | ||
"bytes" | ||
"context" | ||
"encoding/hex" | ||
"io" | ||
"os" | ||
|
@@ -18,95 +19,123 @@ import ( | |
"github.com/ethereum/go-ethereum/crypto" | ||
ants "github.com/panjf2000/ants/v2" | ||
|
||
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/internal/globals" | ||
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/config" | ||
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/logger" | ||
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/output" | ||
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/progress" | ||
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types" | ||
) | ||
|
||
func (opts *AbisOptions) HandleAbiFind() error { | ||
testMode := opts.Globals.TestMode | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll just assume this works if the tests pass. |
||
/* wanted */ /* freq */ /* max */ | ||
scanBar := progress.NewScanBar(uint64(len(opts.Find)), 13919, 50000000, .5) | ||
|
||
// TODO: SimpleFunctionOutput is a temporary fix for outputing ABIs, we can remove it | ||
// TODO: once we start using StreamMany in this code | ||
var results []types.SimpleFunctionOutput | ||
|
||
var wg sync.WaitGroup | ||
checkOne, _ := ants.NewPoolWithFunc(runtime.NumCPU()*2, func(testSig interface{}) { | ||
defer wg.Done() | ||
byts := []byte(testSig.(string)) | ||
sigBytes := crypto.Keccak256(byts) | ||
for _, arg := range opts.Find { | ||
if !opts.Globals.TestMode { | ||
scanBar.Report(os.Stderr, "Scanning", testSig.(string)) | ||
} | ||
str, _ := hex.DecodeString(arg[2:]) | ||
if bytes.Equal(sigBytes[:len(str)], str) { | ||
scanBar.Found++ | ||
if len(opts.Find) < 2 || !opts.Globals.TestMode { | ||
logger.Log(logger.Progress, "Found ", scanBar.Found, " of ", scanBar.Wanted, arg, testSig) | ||
ctx, cancel := context.WithCancel(context.Background()) | ||
fetchData := func(modelChan chan types.Modeler[types.RawFunction], errorChan chan error) { | ||
var results []types.SimpleFunction | ||
var wg sync.WaitGroup | ||
mutex := sync.Mutex{} | ||
checkOne, _ := ants.NewPoolWithFunc(runtime.NumCPU()*2, func(testSig interface{}) { | ||
defer wg.Done() | ||
byts := []byte(testSig.(string)) | ||
sigBytes := crypto.Keccak256(byts) | ||
for _, arg := range opts.Find { | ||
if !opts.Globals.TestMode { | ||
scanBar.Report(os.Stderr, "Scanning", testSig.(string)) | ||
} | ||
str, _ := hex.DecodeString(arg[2:]) | ||
if bytes.Equal(sigBytes[:len(str)], str) { | ||
scanBar.Found++ | ||
if len(opts.Find) < 2 || !opts.Globals.TestMode { | ||
logger.Log(logger.Progress, "Found ", scanBar.Found, " of ", scanBar.Wanted, arg, testSig) | ||
} | ||
found := types.SimpleFunction{Encoding: arg, Signature: testSig.(string)} | ||
if testMode { | ||
mutex.Lock() | ||
results = append(results, found) | ||
mutex.Unlock() | ||
} else { | ||
modelChan <- &found | ||
} | ||
return | ||
} | ||
results = append(results, types.SimpleFunctionOutput{Encoding: arg, Signature: testSig.(string)}) | ||
return | ||
} | ||
}) | ||
defer checkOne.Release() | ||
|
||
// TODO: UnchainedIndex --> This could be part of unchained index | ||
sigsFile, err := os.OpenFile(config.GetPathToRootConfig()+"abis/known-000/uniq_sigs.tab", os.O_RDONLY, 0) | ||
if err != nil { | ||
errorChan <- err | ||
cancel() | ||
return | ||
} | ||
}) | ||
defer checkOne.Release() | ||
|
||
// TODO: UnchainedIndex --> This could be part of unchained index | ||
sigsFile, err := os.OpenFile(config.GetPathToRootConfig()+"abis/known-000/uniq_sigs.tab", os.O_RDONLY, 0) | ||
if err != nil { | ||
return err | ||
} | ||
defer func() { | ||
sigsFile.Close() | ||
}() | ||
sigsFile.Seek(0, io.SeekStart) | ||
sigsScanner := bufio.NewScanner(sigsFile) | ||
sigsScanner.Split(bufio.ScanLines) | ||
|
||
// TODO: UnchainedIndex --> This could be part of unchained index | ||
funcsFile, _ := os.OpenFile(config.GetPathToRootConfig()+"abis/known-000/uniq_funcs.tab", os.O_RDONLY, 0) | ||
defer func() { | ||
funcsFile.Close() | ||
}() | ||
|
||
for sigsScanner.Scan() { | ||
s := sigsScanner.Text() | ||
hitsSignature := opts.hitsHint(s) | ||
|
||
funcsFile.Seek(0, io.SeekStart) | ||
funcsScanner := bufio.NewScanner(funcsFile) | ||
funcsScanner.Split(bufio.ScanLines) | ||
|
||
for funcsScanner.Scan() { | ||
f := funcsScanner.Text() | ||
hitsFunction := opts.hitsHint(f) | ||
if hitsSignature || hitsFunction { | ||
wg.Add(1) | ||
call := f + "(" + s + ")" | ||
_ = checkOne.Invoke(call) | ||
defer func() { | ||
sigsFile.Close() | ||
}() | ||
sigsFile.Seek(0, io.SeekStart) | ||
sigsScanner := bufio.NewScanner(sigsFile) | ||
sigsScanner.Split(bufio.ScanLines) | ||
|
||
// TODO: UnchainedIndex --> This could be part of unchained index | ||
funcsFile, _ := os.OpenFile(config.GetPathToRootConfig()+"abis/known-000/uniq_funcs.tab", os.O_RDONLY, 0) | ||
defer func() { | ||
funcsFile.Close() | ||
}() | ||
|
||
for sigsScanner.Scan() { | ||
s := sigsScanner.Text() | ||
hitsSignature := opts.hitsHint(s) | ||
|
||
funcsFile.Seek(0, io.SeekStart) | ||
funcsScanner := bufio.NewScanner(funcsFile) | ||
funcsScanner.Split(bufio.ScanLines) | ||
|
||
for funcsScanner.Scan() { | ||
f := funcsScanner.Text() | ||
hitsFunction := opts.hitsHint(f) | ||
if hitsSignature || hitsFunction { | ||
wg.Add(1) | ||
call := f + "(" + s + ")" | ||
_ = checkOne.Invoke(call) | ||
} | ||
} | ||
} | ||
|
||
if scanBar.Satisfied() { | ||
break | ||
if scanBar.Satisfied() { | ||
break | ||
} | ||
} | ||
} | ||
|
||
defer wg.Wait() | ||
defer wg.Wait() | ||
|
||
if opts.Globals.TestMode { | ||
// Otherwise the test is not reproducable | ||
sort.Slice(results, func(i, j int) bool { | ||
return results[i].Signature < results[j].Signature | ||
}) | ||
if opts.Globals.TestMode { | ||
// Otherwise the test is not reproducable | ||
sort.Slice(results, func(i, j int) bool { | ||
return results[i].Signature < results[j].Signature | ||
}) | ||
for _, item := range results { | ||
modelChan <- &item | ||
} | ||
} | ||
} | ||
|
||
// TODO: Fix export without arrays | ||
return globals.RenderSlice(&opts.Globals, results) | ||
return output.StreamMany(ctx, fetchData, output.OutputOptions{ | ||
Writer: opts.Globals.Writer, | ||
Chain: opts.Globals.Chain, | ||
TestMode: opts.Globals.TestMode, | ||
NoHeader: opts.Globals.NoHeader, | ||
ShowRaw: opts.Globals.ShowRaw, | ||
Verbose: opts.Globals.Verbose, | ||
LogLevel: opts.Globals.LogLevel, | ||
Format: opts.Globals.Format, | ||
OutputFn: opts.Globals.OutputFn, | ||
Append: opts.Globals.Append, | ||
JsonIndent: " ", | ||
Extra: map[string]interface{}{ | ||
"encodingSignatureOnly": true, | ||
}, | ||
}) | ||
} | ||
|
||
func (opts *AbisOptions) hitsHint(test string) bool { | ||
|
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 |
---|---|---|
|
@@ -22,7 +22,6 @@ func RenderSlice[ | |
types.ReportClean | | ||
types.ReportCheck | | ||
types.SimpleFunction | | ||
types.SimpleFunctionOutput | | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you! |
||
types.SimpleMonitor | | ||
types.SimpleChunkRecord | | ||
types.SimpleAppearance | | ||
|
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
abis?find=0x1aa3a008&fmt=csv | ||
"encoding","signature" | ||
"0x1aa3a008","register()" | ||
encoding,signature | ||
0x1aa3a008,register() |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I'm confused by this a little bit. The "Handle" routines typically generate output, but doesn't this return without having generated output? If yes, my question is why do we come in here at all? Why not do this test before calling?
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.
But we only return if there was an error. Should we ignore it and continue even if we cannot read the binary cache?