Skip to content

Commit

Permalink
feat: blocks in vn ui (#671)
Browse files Browse the repository at this point in the history
Description
---
Changes in the VN UI
- Add `blocks`
- Remove `recent transactions`

Motivation and Context
---

How Has This Been Tested?
---
Manually.

What process can a PR reviewer use to test or verify this change?
---
Run a VN on network with blocks.

Breaking Changes
---

- [x] None
- [ ] Requires data directory to be deleted
- [ ] Other - Please specify
  • Loading branch information
Cifko authored Sep 29, 2023
1 parent 2a66aed commit ccf9c61
Show file tree
Hide file tree
Showing 22 changed files with 1,082 additions and 480 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 43 additions & 2 deletions applications/tari_validator_node/src/json_rpc/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ use tari_validator_node_client::types::{
AddPeerResponse,
CommitteeShardInfo,
DryRunTransactionFinalizeResult,
GetBlockRequest,
GetBlockResponse,
GetBlocksCountResponse,
GetCommitteeRequest,
GetEpochManagerStatsResponse,
GetIdentityResponse,
Expand Down Expand Up @@ -168,8 +171,7 @@ impl JsonRpcHandlers {
target: LOG_TARGET,
"Transaction {} has {} involved shards",
transaction.hash(),
transaction
.num_involved_shards()
transaction.num_involved_shards()
);

let tx_id = *transaction.id();
Expand Down Expand Up @@ -389,6 +391,45 @@ impl JsonRpcHandlers {
}))
}

pub async fn get_block(&self, value: JsonRpcExtractor) -> JrpcResult {
let answer_id = value.get_answer_id();
let data: GetBlockRequest = value.parse_params()?;
let mut tx = self.state_store.create_read_tx().unwrap();
match Block::get(&mut tx, &data.block_id) {
Ok(block) => {
let res = GetBlockResponse { block };
Ok(JsonRpcResponse::success(answer_id, res))
},
Err(e) => Err(JsonRpcResponse::error(
answer_id,
JsonRpcError::new(
JsonRpcErrorReason::InvalidParams,
format!("Something went wrong: {}", e),
json::Value::Null,
),
)),
}
}

pub async fn get_blocks_count(&self, value: JsonRpcExtractor) -> JrpcResult {
let answer_id = value.get_answer_id();
let mut tx = self.state_store.create_read_tx().unwrap();
match Block::get_count(&mut tx) {
Ok(count) => {
let res = GetBlocksCountResponse { count };
Ok(JsonRpcResponse::success(answer_id, res))
},
Err(e) => Err(JsonRpcResponse::error(
answer_id,
JsonRpcError::new(
JsonRpcErrorReason::InternalError,
format!("Something went wrong: {}", e),
json::Value::Null,
),
)),
}
}

pub async fn register_validator_node(&self, value: JsonRpcExtractor) -> JrpcResult {
let answer_id = value.get_answer_id();
let req: RegisterValidatorNodeRequest = value.parse_params()?;
Expand Down
9 changes: 8 additions & 1 deletion applications/tari_validator_node/src/json_rpc/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ async fn handler(Extension(handlers): Extension<Arc<JsonRpcHandlers>>, value: Js
"get_substates_created_by_transaction" => handlers.get_substates_created_by_transaction(value).await,
"get_substates_destroyed_by_transaction" => handlers.get_substates_destroyed_by_transaction(value).await,
"list_blocks" => handlers.list_blocks(value).await,
// Blocks
"get_block" => handlers.get_block(value).await,
"get_blocks_count" => handlers.get_blocks_count(value).await,
// Template
"get_template" => handlers.get_template(value).await,
"get_templates" => handlers.get_templates(value).await,
Expand All @@ -94,7 +97,11 @@ async fn handler(Extension(handlers): Extension<Arc<JsonRpcHandlers>>, value: Js
if let Err(ref e) = result {
match &e.result {
JsonRpcAnswer::Result(val) => {
error!(target: LOG_TARGET, "🚨 JSON-RPC request failed: {}", serde_json::to_string_pretty(val).unwrap_or_else(|e| e.to_string()));
error!(
target: LOG_TARGET,
"🚨 JSON-RPC request failed: {}",
serde_json::to_string_pretty(val).unwrap_or_else(|e| e.to_string())
);
},
JsonRpcAnswer::Error(err) => {
error!(target: LOG_TARGET, "🚨 JSON-RPC request failed: {}", err);
Expand Down
19 changes: 14 additions & 5 deletions applications/tari_validator_node_web_ui/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import Committees from "./routes/Committees/CommitteesLayout";
import ValidatorNode from "./routes/VN/ValidatorNode";
import Connections from "./routes/Connections/Connections";
import Fees from "./routes/Fees/Fees";
import RecentTransactions from "./routes/RecentTransactions/RecentTransactions";
import Blocks from "./routes/Blocks/Blocks";
import Templates from "./routes/Templates/Templates";
import ValidatorNodes from "./routes/ValidatorNodes/ValidatorNodes";
import ErrorPage from "./routes/ErrorPage";
Expand All @@ -42,6 +42,7 @@ import {
getShardKey,
} from "./utils/json_rpc";
import TransactionDetails from "./routes/Transactions/TransactionDetails";
import BlockDetails from "./routes/Blocks/BlockDetails";

interface IContext {
epoch: IEpoch | undefined;
Expand Down Expand Up @@ -83,6 +84,16 @@ export const breadcrumbRoutes = [
path: "/transactions",
dynamic: false,
},
{
label: "Blocks",
path: "/blocks",
dynamic: false,
},
{
label: "Blocks",
path: "/blocks/:blockId",
dynamic: true,
},
{
label: "Templates",
path: "/templates",
Expand Down Expand Up @@ -168,9 +179,6 @@ export default function App() {
);
}
}, [epoch, identity]);
useEffect(() => {
getRecentTransactions();
}, []);

return (
<>
Expand All @@ -181,14 +189,15 @@ export default function App() {
<Route path="committees" element={<Committees />} />
<Route path="connections" element={<Connections />} />
<Route path="fees" element={<Fees />} />
<Route path="transactions" element={<RecentTransactions />} />
<Route path="blocks" element={<Blocks/>} />
<Route path="templates" element={<Templates />} />
<Route path="vns" element={<ValidatorNodes />} />
<Route path="mempool" element={<Mempool />} />
<Route
path="transactions/:transactionHash"
element={<TransactionDetails />}
/>
<Route path="blocks/:blockId" element={<BlockDetails />} />
<Route path="templates/:address" element={<TemplateFunctions />} />
<Route path="committees/:address" element={<CommitteeMembers />} />
<Route path="*" element={<ErrorPage />} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import {
IoLayers,
IoCodeDownloadOutline,
IoCodeDownload,
IoBarChartSharp,
} from 'react-icons/io5';
import Tooltip from '@mui/material/Tooltip';
import Fade from '@mui/material/Fade';
Expand All @@ -65,10 +66,10 @@ const mainItems = [
link: '/',
},
{
title: 'Recent Transactions',
icon: <IoBarChartOutline style={iconStyle} />,
title: 'Blocks',
icon: <IoBarChartSharp style={iconStyle} />,
activeIcon: <IoBarChart style={activeIconStyle} />,
link: 'transactions',
link: 'blocks',
},
{
title: 'Committees',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ const TransactionFilter: React.FC<ISearchProps> = ({
// original array, and set its "show" property to true
filteredRows.forEach((filteredRow: any) => {
const index = updatedObject.findIndex(
(item : any) => item.transaction_hash === filteredRow.transaction_hash
(item : any) => item.id === filteredRow.id
);
if (index !== -1) {
updatedObject[index].show = true;
Expand Down
11 changes: 8 additions & 3 deletions applications/tari_validator_node_web_ui/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,14 @@ import Committees from './routes/Committees/CommitteesLayout';
import Connections from './routes/Connections/Connections';
import Fees from './routes/Fees/Fees';
import Mempool from './routes/Mempool/Mempool';
import RecentTransactions from './routes/RecentTransactions/RecentTransactions';
import Blocks from './routes/Blocks/Blocks';
import Templates from './routes/Templates/Templates';
import ValidatorNodes from './routes/ValidatorNodes/ValidatorNodes';
import ErrorPage from './routes/ErrorPage';
import TemplateFunctions from './routes/VN/Components/TemplateFunctions';
import CommitteeMembers from './routes/Committees/CommitteeMembers';
import TransactionDetails from './routes/Transactions/TransactionDetails';
import BlockDetails from './routes/Blocks/BlockDetails';

const router = createBrowserRouter([
{
Expand All @@ -53,8 +54,12 @@ const router = createBrowserRouter([
element: <Fees />,
},
{
path: 'transactions',
element: <RecentTransactions />,
path: 'blocks',
element: <Blocks />,
},
{
path: 'blocks/:blockId',
element: <BlockDetails />,
},
{
path: 'templates',
Expand Down
Loading

0 comments on commit ccf9c61

Please sign in to comment.