diff --git a/go/enclave/storage/enclavedb/batch.go b/go/enclave/storage/enclavedb/batch.go index 005cb69f73..a3ed53c042 100644 --- a/go/enclave/storage/enclavedb/batch.go +++ b/go/enclave/storage/enclavedb/batch.go @@ -428,11 +428,14 @@ func BatchWasExecuted(ctx context.Context, db *sql.DB, hash common.L2BatchHash) } func GetTransactionsPerAddress(ctx context.Context, db *sql.DB, config *params.ChainConfig, address *gethcommon.Address, pagination *common.QueryPagination) (types.Receipts, error) { - return selectReceipts(ctx, db, config, "where tx.sender_address = ? ORDER BY height DESC LIMIT ? OFFSET ? ", address.Bytes(), pagination.Size, pagination.Offset) + return selectReceipts(ctx, db, config, "join externally_owned_account eoa on tx.sender_address = eoa.id where eoa.address = ? ORDER BY height DESC LIMIT ? OFFSET ? ", address.Bytes(), pagination.Size, pagination.Offset) } func CountTransactionsPerAddress(ctx context.Context, db *sql.DB, address *gethcommon.Address) (uint64, error) { - row := db.QueryRowContext(ctx, "select count(1) from receipt join tx on tx.id=receipt.tx join batch on batch.sequence=receipt.batch "+" where tx.sender_address = ?", address.Bytes()) + row := db.QueryRowContext(ctx, "select count(1) from receipt "+ + "join tx on tx.id=receipt.tx "+ + "join externally_owned_account eoa on eoa.id = tx.sender_address "+ + "where eoa.address = ?", address.Bytes()) var count uint64 err := row.Scan(&count) diff --git a/go/obsclient/authclient.go b/go/obsclient/authclient.go index eeba52980a..7c379002ce 100644 --- a/go/obsclient/authclient.go +++ b/go/obsclient/authclient.go @@ -250,21 +250,21 @@ func (ac *AuthObsClient) EstimateGasAndGasPrice(txData types.TxData) types.TxDat } } -// GetPrivateTransactions retrieves the receipts for the specified account (must be registered on this client) -func (ac *AuthObsClient) GetPrivateTransactions(ctx context.Context, address *gethcommon.Address, pagination common.QueryPagination) (types.Receipts, error) { +// GetPrivateTransactions retrieves the receipts for the specified account (must be registered on this client), returns requested range of receipts and the total number of receipts for that acc +func (ac *AuthObsClient) GetPrivateTransactions(ctx context.Context, address *gethcommon.Address, pagination common.QueryPagination) (types.Receipts, uint64, error) { queryParam := &common.ListPrivateTransactionsQueryParams{ Address: *address, Pagination: pagination, } queryParamStr, err := json.Marshal(queryParam) if err != nil { - return nil, fmt.Errorf("unable to marshal query params - %w", err) + return nil, 0, fmt.Errorf("unable to marshal query params - %w", err) } var result common.PrivateTransactionsQueryResponse err = ac.rpcClient.CallContext(ctx, &result, rpc.GetStorageAt, common.ListPrivateTransactionsCQMethod, string(queryParamStr), nil) if err != nil { - return nil, err + return nil, 0, err } - return result.Receipts, nil + return result.Receipts, result.Total, nil } diff --git a/integration/networktest/tests/tenscan/tenscan_rpc_test.go b/integration/networktest/tests/tenscan/tenscan_rpc_test.go index 3885f6d7ff..3ccb517b45 100644 --- a/integration/networktest/tests/tenscan/tenscan_rpc_test.go +++ b/integration/networktest/tests/tenscan/tenscan_rpc_test.go @@ -69,7 +69,7 @@ func TestPersonalTransactions(t *testing.T) { Offset: 0, Size: 20, } - personalTxs, err := user.GetPersonalTransactions(ctx, pagination) + personalTxs, total, err := user.GetPersonalTransactions(ctx, pagination) if err != nil { return fmt.Errorf("unable to get personal transactions - %w", err) } @@ -78,6 +78,11 @@ func TestPersonalTransactions(t *testing.T) { if len(personalTxs) != 2 { return fmt.Errorf("expected 2 transactions, got %d", len(personalTxs)) } + + // verify total set + if total != 2 { + return fmt.Errorf("expected total receipts to be at least 2, got %d", total) + } return nil }), ), diff --git a/integration/networktest/userwallet/authclient.go b/integration/networktest/userwallet/authclient.go index 76ccadaed5..143e7dc0ab 100644 --- a/integration/networktest/userwallet/authclient.go +++ b/integration/networktest/userwallet/authclient.go @@ -132,7 +132,7 @@ func (s *AuthClientUser) Wallet() wallet.Wallet { return s.wal } -func (s *AuthClientUser) GetPersonalTransactions(ctx context.Context, pagination common.QueryPagination) (types.Receipts, error) { +func (s *AuthClientUser) GetPersonalTransactions(ctx context.Context, pagination common.QueryPagination) (types.Receipts, uint64, error) { address := s.wal.Address() return s.client.GetPrivateTransactions(ctx, &address, pagination) } diff --git a/integration/networktest/userwallet/gateway.go b/integration/networktest/userwallet/gateway.go index 44232c5fbb..7ca839b496 100644 --- a/integration/networktest/userwallet/gateway.go +++ b/integration/networktest/userwallet/gateway.go @@ -113,7 +113,7 @@ func (g *GatewayUser) NativeBalance(ctx context.Context) (*big.Int, error) { return g.client.BalanceAt(ctx, g.wal.Address(), nil) } -func (g *GatewayUser) GetPersonalTransactions(ctx context.Context, pagination common.QueryPagination) (types.Receipts, error) { +func (g *GatewayUser) GetPersonalTransactions(ctx context.Context, pagination common.QueryPagination) (types.Receipts, uint64, error) { rpcClient := g.client.Client() queryParams := &common.ListPrivateTransactionsQueryParams{ Address: g.wal.Address(), @@ -121,19 +121,19 @@ func (g *GatewayUser) GetPersonalTransactions(ctx context.Context, pagination co } queryParamsStr, err := json.Marshal(queryParams) if err != nil { - return nil, fmt.Errorf("unable to marshal query params - %w", err) + return nil, 0, fmt.Errorf("unable to marshal query params - %w", err) } var resultBytes hexutil.Bytes err = rpcClient.CallContext(ctx, &resultBytes, "eth_getStorageAt", common.ListPrivateTransactionsCQMethod, queryParamsStr, nil) if err != nil { - return nil, fmt.Errorf("rpc call failed - %w", err) + return nil, 0, fmt.Errorf("rpc call failed - %w", err) } var result common.PrivateTransactionsQueryResponse err = json.Unmarshal(resultBytes, &result) if err != nil { - return nil, fmt.Errorf("failed to unmarshal result - %w", err) + return nil, 0, fmt.Errorf("failed to unmarshal result - %w", err) } - return result.Receipts, nil + return result.Receipts, result.Total, nil } func (g *GatewayUser) Wallet() wallet.Wallet { diff --git a/integration/networktest/userwallet/user.go b/integration/networktest/userwallet/user.go index 33b9048e6c..c4e1388720 100644 --- a/integration/networktest/userwallet/user.go +++ b/integration/networktest/userwallet/user.go @@ -20,5 +20,5 @@ type User interface { SendFunds(ctx context.Context, addr gethcommon.Address, value *big.Int) (*gethcommon.Hash, error) AwaitReceipt(ctx context.Context, txHash *gethcommon.Hash) (*types.Receipt, error) NativeBalance(ctx context.Context) (*big.Int, error) - GetPersonalTransactions(ctx context.Context, pagination common.QueryPagination) (types.Receipts, error) + GetPersonalTransactions(ctx context.Context, pagination common.QueryPagination) (types.Receipts, uint64, error) }