diff --git a/tools/walletextension/rpcapi/filter_api.go b/tools/walletextension/rpcapi/filter_api.go index b7f049833c..3638f8e51c 100644 --- a/tools/walletextension/rpcapi/filter_api.go +++ b/tools/walletextension/rpcapi/filter_api.go @@ -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)} diff --git a/tools/walletextension/rpcapi/utils.go b/tools/walletextension/rpcapi/utils.go index 9dbca7148a..fd5943e853 100644 --- a/tools/walletextension/rpcapi/utils.go +++ b/tools/walletextension/rpcapi/utils.go @@ -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" @@ -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 } @@ -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) { @@ -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 })