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

feat: add further block times to different endpoints #1442

Merged
merged 1 commit into from
Jul 6, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/ae_mdw/auction_bids.ex
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ defmodule AeMdw.AuctionBids do
state,
Model.auction_bid(
index: plain_name,
block_index_txi_idx: {block_index, _txi_idx},
expire_height: expire_height,
bids: [last_bid | _rest_bids] = bids
),
Expand All @@ -112,6 +113,7 @@ defmodule AeMdw.AuctionBids do
name: plain_name,
status: "auction",
active: false,
activation_time: DbUtil.block_index_to_time(state, block_index),
info: %{
auction_end: expire_height,
approximate_expire_time:
Expand Down
8 changes: 8 additions & 0 deletions lib/ae_mdw/db/util.ex
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ defmodule AeMdw.Db.Util do
@typep height() :: Blocks.height()
@typep txi() :: Txs.txi()
@typep time() :: Blocks.time()
@typep block_index() :: Blocks.block_index()

@tx_types_to_fname %{
:contract_create_tx => ~w(Chain.clone Chain.create),
Expand Down Expand Up @@ -318,6 +319,13 @@ defmodule AeMdw.Db.Util do
def height_to_time(_state, height, last_height, last_micro_time),
do: last_micro_time + (height - last_height) * @approximate_key_block_rate

@spec block_index_to_time(state(), block_index()) :: time()
def block_index_to_time(state, block_index) do
Model.block(hash: block_hash) = State.fetch!(state, Model.Block, block_index)

block_time(block_hash)
end

@spec block_time(Blocks.block_hash()) :: time()
def block_time(block_hash) do
block_hash
Expand Down
4 changes: 3 additions & 1 deletion lib/ae_mdw/oracles.ex
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,8 @@ defmodule AeMdw.Oracles do
index: pk,
expire: expire_height,
register:
{{register_height, _mbi}, {register_txi, _register_idx}} = register_bi_txi_idx,
{{register_height, _mbi} = register_bi, {register_txi, _register_idx}} =
register_bi_txi_idx,
extends: extends,
previous: _previous
),
Expand All @@ -337,6 +338,7 @@ defmodule AeMdw.Oracles do
oracle: Enc.encode(:oracle_pubkey, pk),
active: is_active?,
active_from: register_height,
register_time: DBUtil.block_index_to_time(state, register_bi),
expire_height: expire_height,
approximate_expire_time:
DBUtil.height_to_time(state, expire_height, last_gen, last_micro_time),
Expand Down
1 change: 1 addition & 0 deletions lib/ae_mdw_web/views/logs_view.ex
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ defmodule AeMdwWeb.LogsView do
contract_id: encode_contract(ct_pk),
call_txi: call_txi,
call_tx_hash: encode(:tx_hash, call_tx_hash),
block_time: DBUtil.block_time(block_hash),
args: format_args(event_name, args, encode_args),
data: maybe_encode_base64(data),
event_hash: Base.hex_encode32(event_hash),
Expand Down
Loading
Loading