Print name of invoked method in transaction #3

Merged
alexvanin merged 1 commit from AndrewDanilin/monza:print_name_of_invoked_method_in_transacation into master 2024-07-03 06:50:27 +00:00
Collaborator

Signed-off-by: AndrewDanilin andnilin@gmail.com

I created an ExtractUtilites.go file that has an ExtractCalls function that parses the bytecode and returns the SYSCALL opcode.
Also I add methods that cache SYSCALL parameters into bbolt DB.

Signed-off-by: AndrewDanilin <andnilin@gmail.com> I created an ExtractUtilites.go file that has an ExtractCalls function that parses the bytecode and returns the SYSCALL opcode. Also I add methods that cache SYSCALL parameters into bbolt DB.
requested reviews from alexvanin, fyrchik 2023-11-22 07:18:13 +00:00
fyrchik changed title from [#2] print name of invoked method in transaction to кrint name of invoked method in transaction 2023-11-29 06:26:33 +00:00
fyrchik changed title from кrint name of invoked method in transaction to Print name of invoked method in transaction 2023-11-29 06:26:43 +00:00
alexvanin requested changes 2023-11-29 14:36:32 +00:00
@ -0,0 +1,138 @@
package internal
Owner

Internal package usually is an aggregation of packages, which cannot be imported from external repositories. So I suggest to move this file in a separate internal package (see /internal/chain) and use lowercase name for the file, e.g.

/internal/bytecode/extract.go
Internal package usually is an aggregation of packages, which cannot be imported from external repositories. So I suggest to move this file in a separate internal package (see `/internal/chain`) and use lowercase name for the file, e.g. ``` /internal/bytecode/extract.go ```
alexvanin marked this conversation as resolved
@ -0,0 +16,4 @@
}
// ExtractCalls Extract parameters of SYSCALL opcode from bytecode of transaction
func ExtractCalls(script []byte) ([]SyscallParameters, error) {
Owner

Let's write some unit tests for this function. Use correct and incorrect bytecodes. Also you can try a bytecode with multiple contract method invocations.

Let's write some unit tests for this function. Use correct and incorrect bytecodes. Also you can try a bytecode with multiple contract method invocations.
alexvanin marked this conversation as resolved
@ -0,0 +49,4 @@
offset1 += 4
}
src := script[offset1 : offset1+n]
nameOfMethod, _ := hex.DecodeString(hex.EncodeToString(src))
Owner

Are we 100% sure these decoding errors never happen? ExtractCalls returns error anyway so it is cheap to return error here in case of something bad happens with the byte code. Same for Uint160DecodeBytesBE.

Are we 100% sure these decoding errors never happen? `ExtractCalls` returns error anyway so it is cheap to return error here in case of something bad happens with the byte code. Same for `Uint160DecodeBytesBE`.
alexvanin marked this conversation as resolved
@ -0,0 +75,4 @@
// Skip n bytes (params of current opcode) to next opcode
err := skipBytes(&i, script)
if err != nil {
return nil, fmt.Errorf("%s%v", "Error while parsing bytecode:", err)
Owner

This error formatting is a bit odd:

  • use lowercase in errors,
  • use %w to wrap an error
return nil, fmt.Errorf("bytecode parsing error: %w", err)
This error formatting is a bit odd: - use lowercase in errors, - use %w to wrap an error ```go return nil, fmt.Errorf("bytecode parsing error: %w", err) ```
alexvanin marked this conversation as resolved
@ -5,2 +5,4 @@
"encoding/binary"
"encoding/json"
"fmt"
"git.frostfs.info/TrueCloudLab/monza/internal"
Owner

Don't forget to set up your IDE to group import dependencies or use something like goimports.

We are trying to use two groups as it stated in uber style guide.

Don't forget to set up your IDE to group import dependencies or use something like [goimports](https://pkg.go.dev/golang.org/x/tools/cmd/goimports). We are trying to use two groups as it stated in [uber style guide](https://github.com/uber-go/guide/blob/master/style.md#import-group-ordering).
alexvanin marked this conversation as resolved
Author
Collaborator

Sorry for a long time inactive, my laptop was tired and wanted to break down :(
I added some tests for checking correct behaviour of ExtractCalls function.

Sorry for a long time inactive, my laptop was tired and wanted to break down :( I added some tests for checking correct behaviour of ExtractCalls function.
requested review from alexvanin 2023-12-26 05:10:58 +00:00
alexvanin approved these changes 2023-12-26 13:07:12 +00:00
alexvanin left a comment
Owner

Looks good! Please, take your time to update commit messages. At TrueCloudLab, we try to use recommendations from this article.

In short: start commit headers with upper-case. Optionally add [#2] prefix so it will be easier to track commits from issue #2.

Looks good! Please, take your time to update commit messages. At TrueCloudLab, we try to use recommendations from [this](https://cbea.ms/git-commit/) article. In short: start commit headers with upper-case. Optionally add `[#2]` prefix so it will be easier to track commits from issue #2.
alexvanin force-pushed print_name_of_invoked_method_in_transacation from 71829af56a to aca2229ab7 2024-07-03 06:49:52 +00:00 Compare
alexvanin merged commit aca2229ab7 into master 2024-07-03 06:50:27 +00:00
alexvanin deleted branch print_name_of_invoked_method_in_transacation 2024-07-03 06:50:28 +00:00
Sign in to join this conversation.
No description provided.