Skip to content

Commit

Permalink
fix getLogs
Browse files Browse the repository at this point in the history
  • Loading branch information
tudor-malene committed Jul 1, 2024
1 parent d632548 commit 41fabfa
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
8 changes: 6 additions & 2 deletions tools/walletextension/rpcapi/filter_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,14 +192,18 @@ func (api *FilterAPI) GetLogs(ctx context.Context, crit common.FilterCriteria) (
&ExecCfg{
cacheCfg: &CacheCfg{
CacheTypeDynamic: func() CacheStrategy {
// when the toBlock is not specified, the request is open-ended
if crit.ToBlock != nil && crit.ToBlock.Int64() > 0 {
return LongLiving
}
if crit.BlockHash != nil {
return LongLiving
}
// when the toBlock or the block Hash are not specified, the request is open-ended
return LatestBatch
},
},
tryUntilAuthorised: true,
tryAll: true,
accumulateResults: true, // we want the events that are relevant to all accounts registered by the current user
adjustArgs: func(acct *GWAccount) []any {
// convert to something serializable
return []any{common.FromCriteria(crit)}
Expand Down
21 changes: 20 additions & 1 deletion tools/walletextension/rpcapi/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"fmt"
"time"

"github.com/ethereum/go-ethereum/core/types"

"github.com/ten-protocol/go-ten/go/common/measure"
"github.com/ten-protocol/go-ten/go/enclave/core"

Expand Down Expand Up @@ -50,6 +52,7 @@ type ExecCfg struct {
computeFromCallback func(user *GWUser) *gethcommon.Address
tryAll bool
tryUntilAuthorised bool
accumulateResults bool
adjustArgs func(acct *GWAccount) []any
cacheCfg *CacheCfg
}
Expand Down Expand Up @@ -120,6 +123,7 @@ func ExecAuthRPC[R any](ctx context.Context, w *Services, cfg *ExecCfg, method s
}

var rpcErr error
accumulatedResponse := make([]*types.Log, 0)
for i := range candidateAccts {
acct := candidateAccts[i]
result, err := withEncRPCConnection(ctx, w, acct, func(rpcClient *tenrpc.EncRPCClient) (*R, error) {
Expand All @@ -144,7 +148,22 @@ func ExecAuthRPC[R any](ctx context.Context, w *Services, cfg *ExecCfg, method s
rpcErr = err
continue
}
return result, nil
if cfg.accumulateResults {
resArray, ok := (any(result)).(*[]*types.Log)
if !ok {
return nil, fmt.Errorf("accumulate result only supported for getLogs")
}
accumulatedResponse = append(accumulatedResponse, *resArray...)
} else {
return result, nil
}
}
if cfg.accumulateResults {
r, ok := any(accumulatedResponse).(R)
if !ok {
return nil, fmt.Errorf("cannot accumulate result on non arrays")
}
return &r, nil
}
return nil, rpcErr
})
Expand Down

0 comments on commit 41fabfa

Please sign in to comment.