Skip to content

Commit ede975d

Browse files
committed
add txcount
1 parent 65f8f54 commit ede975d

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

ex/lib/api/api_chain.ex

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,20 @@ defmodule API.Chain do
8383
}
8484
end
8585

86+
def kpi() do
87+
{_, uaw} = API.Contract.richlist()
88+
tx_cnt = RocksDB.get_cf_prop(:tx, "rocksdb.estimate-num-keys") |> :erlang.binary_to_integer()
89+
%{
90+
ama_burned: Float.round(API.Contract.total_burned().float, 2),
91+
fees_paid: Float.round(API.Contract.total_burned().float * 2, 2),
92+
active_validator_keys: 67 + length(API.Epoch.score()),
93+
active_peers: length(API.Peer.all()),
94+
block_time: 500,
95+
total_tx: tx_cnt,
96+
uaw: uaw,
97+
}
98+
end
99+
86100
def total_supply_y3() do
87101
cached = :persistent_term.get(:total_supply_y3, nil)
88102
if cached do cached else

ex/lib/api/db_entry.ex

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,12 @@ defmodule DB.Entry do
107107
RocksDB.put(key, hash, db_handle(db_opts, :tx_filter, %{}))
108108
end)
109109

110+
if entry.header.height >= 445_00000 do
111+
old_cnt = RocksDB.get("tx_count", db_handle(db_opts, :sysconf, %{})) || "0"
112+
new_cnt = :erlang.binary_to_integer(old_cnt) + length(entry.txs)
113+
RocksDB.put("tx_count", :erlang.integer_to_binary(new_cnt), db_handle(db_opts, :sysconf, %{}))
114+
end
115+
110116
receipts_by_txid = Map.new(receipts, fn r -> {r.txid, Map.drop(r, [:txid])} end)
111117
Enum.each(entry.txs, fn(txu)->
112118
receipt = Map.fetch!(receipts_by_txid, txu.hash)
@@ -164,6 +170,12 @@ defmodule DB.Entry do
164170
RocksDB.delete(key, db_handle(db_opts, :tx_filter, %{}))
165171
end)
166172

173+
if entry.header.height >= 445_00000 do
174+
old_cnt = RocksDB.get("tx_count", db_handle(db_opts, :sysconf, %{})) || "0"
175+
new_cnt = :erlang.binary_to_integer(old_cnt) - length(entry.txs)
176+
RocksDB.put("tx_count", :erlang.integer_to_binary(new_cnt), db_handle(db_opts, :sysconf, %{}))
177+
end
178+
167179
Enum.each(entry.txs, fn(txu)->
168180
RocksDB.delete(txu.hash, db_handle(db_opts, :tx, %{}))
169181

ex/lib/http/multiserver.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ defmodule Ama.MultiServer do
206206
function: query[:function],
207207

208208
limit: :erlang.binary_to_integer(query[:limit] || "100"),
209-
sort: case filters.sort do "desc" -> :desc; _ -> :asc end,
209+
sort: case query[:sort] do "desc" -> :desc; _ -> :asc end,
210210
cursor: if query[:cursor_b58] do Base58.decode(query.cursor_b58) else query[:cursor] end,
211211
}
212212
{cursor, txs} = API.TX.get_by_filter(filters)

0 commit comments

Comments
 (0)