Skip to content

Commit

Permalink
api/runtime/transactions: Support method filter
Browse files Browse the repository at this point in the history
  • Loading branch information
ptrus committed Dec 11, 2024
1 parent f6673ae commit 38440a0
Show file tree
Hide file tree
Showing 10 changed files with 1,189 additions and 26 deletions.
6 changes: 6 additions & 0 deletions api/spec/v1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -935,6 +935,12 @@ paths:
the sender or the recipient of tokens.
Nexus detects related accounts inside EVM transactions and events on a
best-effort basis. For example, it inspects ERC20 methods inside `evm.Call` txs.
- in: query
name: method
schema:
type: string
description: A filter on the runtime transaction method.
example: 'accounts.Transfer'
responses:
'200':
description: |
Expand Down
1 change: 1 addition & 0 deletions storage/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1450,6 +1450,7 @@ func (c *StorageClient) RuntimeTransactions(ctx context.Context, p apiTypes.GetR
p.Block,
txHash, // tx_hash; used only by GetRuntimeTransactionsTxHash
ocAddrRel,
p.Method,
p.After,
p.Before,
p.Limit,
Expand Down
9 changes: 5 additions & 4 deletions storage/client/queries/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -538,12 +538,13 @@ const (
($2::bigint IS NULL OR txs.round = $2::bigint) AND
($3::text IS NULL OR txs.tx_hash = $3::text OR txs.tx_eth_hash = $3::text) AND
($4::text IS NULL OR rel.account_address = $4::text) AND
($5::timestamptz IS NULL OR txs.timestamp >= $5::timestamptz) AND
($6::timestamptz IS NULL OR txs.timestamp < $6::timestamptz) AND
($5::text IS NULL or txs.method = $5::text) AND
($6::timestamptz IS NULL OR txs.timestamp >= $6::timestamptz) AND
($7::timestamptz IS NULL OR txs.timestamp < $7::timestamptz) AND
(signer0.signer_address IS NOT NULL) -- HACK: excludes malformed transactions that do not have the required fields
ORDER BY txs.round DESC, txs.tx_index DESC
LIMIT $7::bigint
OFFSET $8::bigint
LIMIT $8::bigint
OFFSET $9::bigint
`

RuntimeEvents = `
Expand Down
36 changes: 14 additions & 22 deletions storage/migrations/01_runtimes.up.sql
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,6 @@ CREATE TABLE chain.runtime_transactions
gas_used UINT63 NOT NULL,
size UINT31 NOT NULL,

-- Added in 31_runtime_txs_oasis_encryption.up.sql
-- Encrypted data in encrypted Oasis-format transactions.
-- oasis_encrypted_format call_format,
-- oasis_encrypted_public_key BYTEA,
-- oasis_encrypted_data_nonce BYTEA,
-- oasis_encrypted_data_data BYTEA,
-- oasis_encrypted_result_nonce BYTEA,
-- oasis_encrypted_result_data BYTEA,

-- Transaction contents.
method TEXT, -- accounts.Transfer, consensus.Deposit, consensus.Withdraw, evm.Create, evm.Call. NULL for malformed and encrypted txs.
body JSONB, -- For EVM txs, the EVM method and args are encoded in here. NULL for malformed and encrypted txs.
Expand Down Expand Up @@ -90,15 +81,15 @@ CREATE TABLE chain.runtime_transactions
error_module TEXT,
error_code UINT63,
error_message TEXT,
-- The unparsed transaction error message. The "parsed" version will be
-- The unparsed transaction error message. The "parsed" version will be
-- identical in the majority of cases. One notable exception are txs that
-- were reverted inside the EVM; for those, the raw msg is abi-encoded.
error_message_raw TEXT,
-- Custom errors may be arbitrarily defined by the contract abi. This field
-- stores the full abi-decoded error object. Note that the error name is
-- stores the full abi-decoded error object. Note that the error name is
-- stored separately in the existing error_message column. For example, if we
-- have an error like `InsufficientBalance{available: 4, required: 10}`.
-- the error_message column would hold `InsufficientBalance`, and
-- the error_message column would hold `InsufficientBalance`, and
-- the error_params column would store `{available: 4, required: 10}`.
error_params JSONB,
-- Internal tracking for parsing evm.Call transactions using the contract
Expand All @@ -110,6 +101,7 @@ CREATE INDEX ix_runtime_transactions_tx_eth_hash ON chain.runtime_transactions U
CREATE INDEX ix_runtime_transactions_timestamp ON chain.runtime_transactions (runtime, timestamp);
CREATE INDEX ix_runtime_transactions_to ON chain.runtime_transactions(runtime, "to");
CREATE INDEX ix_runtime_transactions_to_abi_parsed_at ON chain.runtime_transactions (runtime, "to", abi_parsed_at);
-- CREATE INDEX ix_runtime_transactions_method_round ON chain.runtime_transactions (runtime, method, round, tx_index); -- Added in 08_runtime_transactions_method_idx.up.sql

CREATE TABLE chain.runtime_transaction_signers
(
Expand Down Expand Up @@ -150,7 +142,7 @@ CREATE TABLE chain.runtime_events
tx_hash HEX64,
tx_eth_hash HEX64,
timestamp TIMESTAMP WITH TIME ZONE NOT NULL,

-- TODO: add link to openapi spec section with runtime event types.
type TEXT NOT NULL,
-- The raw event, as returned by the oasis-sdk runtime client.
Expand Down Expand Up @@ -235,13 +227,13 @@ CREATE TABLE chain.runtime_accounts
-- we've encountered the preimage before to find out what the address was
-- derived from.
--
-- If you need to go the other way, from context + data to address, you'd
-- If you need to go the other way, from context + data to address, you'd
-- normally just run the derivation. See oasis-core/go/common/crypto/address/address.go
-- for details. Consider inserting the preimage here if you're ingesting new
-- for details. Consider inserting the preimage here if you're ingesting new
-- blockchain data.
--
-- However, we do provide an index going the other way because certain queries
-- require computing the derivation within Postgres and implementing/importing
-- However, we do provide an index going the other way because certain queries
-- require computing the derivation within Postgres and implementing/importing
-- the right hash function will take some work.
-- TODO: import keccak hash into postgres.
--
Expand All @@ -261,7 +253,7 @@ CREATE TABLE chain.address_preimages
-- Ethereum address. For a "staking" context, this is the ed25519 pubkey.
address_data BYTEA NOT NULL
);
CREATE INDEX ix_address_preimages_address_data ON chain.address_preimages (address_data)
CREATE INDEX ix_address_preimages_address_data ON chain.address_preimages (address_data)
WHERE context_identifier = 'oasis-runtime-sdk/address: secp256k1eth' AND context_version = 0;

-- -- -- -- -- -- -- -- -- -- -- -- -- Module evm -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Expand Down Expand Up @@ -290,13 +282,13 @@ CREATE TABLE chain.evm_tokens
-- NOT an uint because a non-conforming token contract could issue a fake burn event,
-- causing a negative dead-reckoned total_supply.
total_supply NUMERIC(1000,0),

num_transfers UINT63 NOT NULL DEFAULT 0,

-- Block analyzer bumps this when it sees the mutable fields of the token
-- change (e.g. total supply) based on dead reckoning.
last_mutate_round UINT63 NOT NULL DEFAULT 0,

-- Token analyzer bumps this when it downloads info about the token.
last_download_round UINT63
);
Expand All @@ -309,7 +301,7 @@ CREATE TABLE analysis.evm_token_balances
token_address oasis_addr NOT NULL,
account_address oasis_addr NOT NULL,
PRIMARY KEY (runtime, token_address, account_address),

last_mutate_round UINT63 NOT NULL,
last_download_round UINT63
);
Expand Down
5 changes: 5 additions & 0 deletions storage/migrations/08_runtime_transactions_method_idx.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
BEGIN;

CREATE INDEX IF NOT EXISTS ix_runtime_transactions_method_round ON chain.runtime_transactions (runtime, method, round, tx_index);

COMMIT;
1 change: 1 addition & 0 deletions tests/e2e_regression/common_test_cases.sh
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ commonTestCases=(
'validators /v1/consensus/validators?limit=200'
'emerald_blocks /v1/emerald/blocks'
'emerald_txs /v1/emerald/transactions'
'emerald_txs_by_method /v1/emerald/transactions?method=consensus.Withdraw'
'emerald_events /v1/emerald/events'
'emerald_events_by_type /v1/emerald/events?type=accounts.transfer'
'emerald_tokens /v1/emerald/evm_tokens'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"is_total_count_clipped": false,
"total_count": 0,
"transactions": []
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
HTTP/1.1 200 OK
Content-Type: application/json
Vary: Origin
Date: UNINTERESTING
Content-Length: UNINTERESTING

Loading

0 comments on commit 38440a0

Please sign in to comment.