feat: first scenario implemented

This commit is contained in:
Oleksandr Pravdyvyi
2025-07-30 14:01:40 +03:00
parent 28317b6227
commit 6df4a04f84
11 changed files with 370 additions and 54 deletions
+1 -5
View File
@@ -103,12 +103,8 @@ impl NodeCore {
let genesis_block = client.get_block(genesis_id.genesis_id).await?.block;
let initial_accounts_ser = client.get_initial_testnet_accounts().await?;
let initial_accounts: Vec<Account> =
initial_accounts_ser.into_iter().map(Into::into).collect();
let (mut storage, mut chain_height) = NodeChainStore::new(config.clone(), genesis_block)?;
for acc in initial_accounts {
for acc in config.clone().initial_accounts {
storage.acc_map.insert(acc.address, acc);
}
+8
View File
@@ -46,3 +46,11 @@ pub struct SequencerRpcResponse {
pub result: serde_json::Value,
pub id: u64,
}
#[derive(Debug, Serialize, Deserialize, Clone)]
///Helperstruct for account serialization
pub struct AccountInitialData {
///Hex encoded `AccountAddress`
pub addr: String,
pub balance: u64,
}
+19 -4
View File
@@ -1,8 +1,7 @@
use accounts::account_core::{Account, AccountForSerialization};
use accounts::account_core::Account;
use anyhow::Result;
use common::rpc_primitives::requests::{
GetBlockDataRequest, GetBlockDataResponse, GetGenesisIdRequest, GetGenesisIdResponse,
GetInitialTestnetAccountsRequest, RegisterAccountRequest, RegisterAccountResponse,
GetAccountBalanceRequest, GetAccountBalanceResponse, GetBlockDataRequest, GetBlockDataResponse, GetGenesisIdRequest, GetGenesisIdResponse, GetInitialTestnetAccountsRequest, RegisterAccountRequest, RegisterAccountResponse
};
use common::transaction::Transaction;
use common::{SequencerClientError, SequencerRpcError};
@@ -11,6 +10,7 @@ use reqwest::Client;
use serde_json::Value;
use crate::config::NodeConfig;
use crate::sequencer_client::json::AccountInitialData;
pub mod json;
@@ -69,6 +69,21 @@ impl SequencerClient {
Ok(resp_deser)
}
pub async fn get_account_balance(
&self,
address: String,
) -> Result<GetAccountBalanceResponse, SequencerClientError> {
let block_req = GetAccountBalanceRequest { address };
let req = serde_json::to_value(block_req)?;
let resp = self.call_method_with_payload("get_account_balance", req).await?;
let resp_deser = serde_json::from_value(resp)?;
Ok(resp_deser)
}
pub async fn send_tx(
&self,
transaction: Transaction,
@@ -124,7 +139,7 @@ impl SequencerClient {
pub async fn get_initial_testnet_accounts(
&self,
) -> Result<Vec<AccountForSerialization>, SequencerClientError> {
) -> Result<Vec<AccountInitialData>, SequencerClientError> {
let acc_req = GetInitialTestnetAccountsRequest {};
let req = serde_json::to_value(acc_req).unwrap();