-
Notifications
You must be signed in to change notification settings - Fork 28
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
Use special strings for methodSig to handle contract call by pre-compiled ABI data #123
Use special strings for methodSig to handle contract call by pre-compiled ABI data #123
Conversation
846d6e6
to
71e716f
Compare
71e716f
to
d1b0d80
Compare
return argStr, nil | ||
} | ||
return methodArgs, nil | ||
case []string: |
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.
do we need to handle this case?
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.
For this specific project, no. Doing it for generalization.
} | ||
|
||
switch args := methodArgs.(type) { | ||
case []interface{}: |
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.
Will calling fallback ever have more than 1 args?
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.
As far as I know, no. The arg is the pre-compiled data, which is one piece.
// preprocessArgs converts methodArgs to a string value if methodSig is an empty string. | ||
// We are calling a contract written with fallback pattern, which has no method signature. | ||
func preprocessArgs(methodSig string, methodArgs interface{}) (interface{}, error) { | ||
if methodSig != "" && methodSig != NoMethodSig { |
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.
Let's simplify your impl like this:
func preprocessArgs(methodSig string, methodArgs interface{}) (interface{}, error) {
if methodSig == "" || methodSig == NoMethodSig {
switch args := methodArgs.(type) {
case []interface{}:
if len(args) == 1 {
if argStr, ok := args[0].(string); ok {
return argStr, nil
}
return nil, fmt.Errorf("failed to convert method arg \"%T\" to string", args[0])
}
case []string:
if len(args) == 1 {
return args[0], nil
}
}
}
return methodArgs, nil
}
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.
Updated the PR.
d182269
to
2de207e
Compare
✅ Heimdall Review Status
|
Motivation
This PR is to add some logic to the preprocess API to handle fallback pattern contract call. This type of contract call does not have a method signature.
Solution
We will use either empty string or a unique string "NO-METHOD-SIG" to indicate it. The pre-compiled ABI data will be passed in as methodArgs, either in the string format or the first element of an array.
Testing
Open questions