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

Solsig indexed #75

Merged
merged 3 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions pkg/abi/abi.go
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,7 @@ func (e *Entry) SolidityDef() (string, []string, error) {
func (e *Entry) SolidityDefCtx(ctx context.Context) (string, []string, error) {
// Everything apart from event and error is a type of function
isFunction := e.Type != Error && e.Type != Event
isEvent := e.Type == Event

allChildStructs := []string{}
buff := new(strings.Builder)
Expand All @@ -713,7 +714,7 @@ func (e *Entry) SolidityDefCtx(ctx context.Context) (string, []string, error) {
if i > 0 {
buff.WriteString(", ")
}
s, childStructs, err := p.SolidityDefCtx(ctx, isFunction)
s, childStructs, err := p.SolidityDefCtx(ctx, isFunction, isEvent)
if err != nil {
return "", nil, err
}
Expand All @@ -736,7 +737,7 @@ func (e *Entry) SolidityDefCtx(ctx context.Context) (string, []string, error) {
if i > 0 {
buff.WriteString(", ")
}
s, childStructs, err := p.SolidityDefCtx(ctx, isFunction)
s, childStructs, err := p.SolidityDefCtx(ctx, true, false)
peterbroadhurst marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return "", nil, err
}
Expand Down Expand Up @@ -782,13 +783,13 @@ func (p *Parameter) SignatureStringCtx(ctx context.Context) (string, error) {
return tc.String(), nil
}

func (p *Parameter) SolidityDefCtx(ctx context.Context, inFunction bool) (string, []string, error) {
func (p *Parameter) SolidityDefCtx(ctx context.Context, isFunction, isEvent bool) (string, []string, error) {
// Ensure the type component tree has been parsed
tc, err := p.TypeComponentTreeCtx(ctx)
if err != nil {
return "", nil, err
}
solDef, childStructs := tc.SolidityParamDef(inFunction)
solDef, childStructs := tc.SolidityParamDef(isFunction, isEvent)
return solDef, childStructs, nil
}

Expand Down
7 changes: 6 additions & 1 deletion pkg/abi/abi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,11 @@ const sampleABI5 = `[
"internalType": "struct AribtraryWidgets.Widget[]",
"name": "widgets",
"type": "tuple[]"
},
{
"name": "account",
"type": "address",
"indexed": true
}
],
"name": "Invoiced",
Expand Down Expand Up @@ -1015,7 +1020,7 @@ func TestComplexStructSolidityDef(t *testing.T) {

solDef, childStructs, err = abi.Events()["Invoiced"].SolidityDef()
assert.NoError(t, err)
assert.Equal(t, "event Invoiced(Customer customer, Widget[] widgets)", solDef)
assert.Equal(t, "event Invoiced(Customer customer, Widget[] widgets, address indexed account)", solDef)
assert.Equal(t, []string{
"struct Customer { address owner; bytes32 locator; }",
"struct Widget { string description; uint256 price; string[] attributes; }",
Expand Down
17 changes: 11 additions & 6 deletions pkg/abi/typecomponents.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ type TypeComponent interface {
DecodeABIData(d []byte, offset int) (*ComponentValue, error)
DecodeABIDataCtx(ctx context.Context, d []byte, offest int) (*ComponentValue, error)

SolidityParamDef(inFunction bool) (solDef string, structDefs []string) // gives a string that can be used to define this param in solidity
SolidityParamDef(isFunction, isEvent bool) (solDef string, structDefs []string) // gives a string that can be used to define this param in solidity
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From what I understand they are mutuality exclusive, feels like this should be an enum as it's either one or the other

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok - moving interface to enum and refactoring

SolidityTypeDef() (isRef bool, typeDef string, childStructs []string)
SolidityStructDef() (structName string, structs []string)
}
Expand Down Expand Up @@ -371,13 +371,18 @@ func (tc *typeComponent) String() string {
}
}

func (tc *typeComponent) SolidityParamDef(inFunction bool) (string, []string) {
func (tc *typeComponent) SolidityParamDef(isFunction, isEvent bool) (string, []string) {
isRef, paramDef, childStructs := tc.SolidityTypeDef()
if isRef && inFunction {
paramDef = fmt.Sprintf("%s memory", paramDef)
if isRef && isFunction {
paramDef += " memory"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why the change from sprintF to +=?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just felt more readable

}
if tc.parameter != nil && tc.parameter.Name != "" {
paramDef = fmt.Sprintf("%s %s", paramDef, tc.parameter.Name)
if tc.parameter != nil {
if isEvent && tc.parameter.Indexed {
paramDef += " indexed"
}
if tc.parameter.Name != "" {
paramDef = fmt.Sprintf("%s %s", paramDef, tc.parameter.Name)
}
}
return paramDef, childStructs
}
Expand Down
5 changes: 3 additions & 2 deletions pkg/rpcbackend/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package rpcbackend
import (
"context"
"encoding/json"
"errors"
"fmt"
"sync/atomic"
"time"
Expand Down Expand Up @@ -91,7 +92,7 @@ type RPCError struct {
}

func (e *RPCError) Error() error {
return fmt.Errorf(e.Message)
return errors.New(e.Message)
}

func (e *RPCError) String() string {
Expand Down Expand Up @@ -208,7 +209,7 @@ func (rc *RPCClient) SyncRequest(ctx context.Context, rpcReq *RPCRequest) (rpcRe
rpcMsg = i18n.NewError(ctx, signermsgs.MsgRPCRequestFailed, res.Status()).Error()
}
log.L(ctx).Errorf("RPC[%s] <-- [%d]: %s", rpcTraceID, res.StatusCode(), errLog)
err := fmt.Errorf(rpcMsg)
err := errors.New(rpcMsg)
return rpcRes, err
}
log.L(ctx).Infof("RPC[%s] <-- %s [%d] OK (%.2fms)", rpcTraceID, rpcReq.Method, res.StatusCode(), float64(time.Since(rpcStartTime))/float64(time.Millisecond))
Expand Down
Loading