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

api: /{runtime}/accounts/{addr}: Show contract runtime bytecode, show eth address of originating tx #452

Merged
merged 2 commits into from
Jun 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 16 additions & 8 deletions api/spec/v1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2066,8 +2066,14 @@ components:
type: string
description: |
The Oasis cryptographic hash of the transaction that created the smart contract.
Can be omitted for contracts that were created by another contract, as opposed
to a direct `Create` call.
Can be omitted for contracts that were created by another contract, as opposed
to a direct `Create` call.
eth_creation_tx:
type: string
description: |
The Ethereum transaction hash of the transaction in `creation_tx`.
Encoded as a lowercase hex string.
Copy link
Member

Choose a reason for hiding this comment

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

I guess the "Can be omitted for contracts..." note is naturally implied by the descrption of creation_tx so it can be omitted.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

😁 yeah I figured this is better than repeating the whole description of when it can be omitted, especially since the condition might change in the (far-ish) future if we implement contract execution tracing.

example: 'dc19a122e268128b5ee20366299fc7b5b199c8e3'
creation_bytecode:
type: string
format: byte
Expand All @@ -2076,12 +2082,14 @@ components:
and the constructor parameters. When run, this code generates the runtime bytecode.
Can be omitted for contracts that were created by another contract, as opposed
to a direct `Create` call.
# runtime_bytecode:
# type: string
# format: byte
# description: |
# The runtime bytecode of the smart contract. This is the code stored on-chain that
# descibes a smart contract.
runtime_bytecode:
type: string
format: byte
description: |
The runtime bytecode of the smart contract. This is the code stored on-chain that
descibes a smart contract. Every contract has this info, but the indexer fetches
it separately, so the field may be missing for very fresh contracts (or if the fetching
process is stalled).
verification:
$ref: '#/components/schemas/RuntimeEvmContractVerification'
description: |
Expand Down
2 changes: 2 additions & 0 deletions storage/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1383,7 +1383,9 @@ func (c *StorageClient) RuntimeAccount(ctx context.Context, address staking.Addr
address.String(),
).Scan(
&evmContract.CreationTx,
&evmContract.EthCreationTx,
&evmContract.CreationBytecode,
&evmContract.RuntimeBytecode,
)
switch err {
case nil:
Expand Down
16 changes: 12 additions & 4 deletions storage/client/queries/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,10 +403,18 @@ const (
OFFSET $9::bigint`

RuntimeEvmContract = `
SELECT creation_tx, creation_bytecode
FROM chain.evm_contracts
WHERE (runtime = $1) AND
(contract_address = $2::text)`
SELECT
creation_tx,
(
SELECT tx_eth_hash FROM chain.runtime_transactions rtt
WHERE (rtt.runtime = $1) AND (rtt.tx_hash = creation_tx)
ORDER BY timestamp DESC LIMIT 1 -- Technically more than one tx might share the same hash, but it's so vanishingly rare that this hack is fine.
) AS eth_creation_tx,
creation_bytecode,
runtime_bytecode
FROM chain.evm_contracts

WHERE (runtime = $1) AND (contract_address = $2::text)`

AddressPreimage = `
SELECT context_identifier, context_version, address_data
Expand Down