Skip to content

Commit

Permalink
Merge pull request #452 from oasisprotocol/mitjat/api-contract-info
Browse files Browse the repository at this point in the history
api: /{runtime}/accounts/{addr}: Show contract runtime bytecode, show eth address of originating tx
  • Loading branch information
mitjat committed Jun 16, 2023
2 parents b63be91 + 2da9ca0 commit dca1d02
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 12 deletions.
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.
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

0 comments on commit dca1d02

Please sign in to comment.