Skip to content

Commit

Permalink
Implement GetMasterchainInfoExt
Browse files Browse the repository at this point in the history
  • Loading branch information
hacker-volodya committed Jun 18, 2024
1 parent 2344fe2 commit d711aeb
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 4 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,14 @@ services:
| | **impemented**
| ✅ | WaitMasterchainSeqno
| ✅ | GetMasterchainInfo
| ✅ | GetMasterchainInfoExt
| ✅ | GetBlockHeader
| ✅ | GetAllShardsInfo
| ✅ | ListBlockTransactions
| ✅ | GetBlock
| ✅ | GetAccountState | no shard_proof for now
| ⚠️ | GetTransactions | lt block search in progress
| ✅ | LookupBlock | utime search is not working for now
| | GetTransactions
| ✅ | LookupBlock
| | **high priority** (toncenter)
| ⚠️ | SendMessage | TVM required
| 🔜 | GetConfigParams
Expand Down
37 changes: 35 additions & 2 deletions src/liteserver.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::{sync::Arc, task::Poll, time::Duration};

use anyhow::{anyhow, Result};
use broxus_util::now;
use futures_util::future::BoxFuture;
use ton_block::{AccountIdPrefixFull, Block, Deserializable, GetRepresentationHash, HashmapAugType, InRefValue, MerkleProof, MsgAddrStd, Serializable, ShardIdent, ShardStateUnsplit, Transaction, TraverseNextStep};
use ton_indexer::{utils::ShardStateStuff, Engine, GlobalConfig};
Expand All @@ -10,9 +11,9 @@ use ton_liteapi::{
tl::{
common::{BlockIdExt, Int256, ZeroStateIdExt},
request::{
GetAccountState, GetAllShardsInfo, GetBlock, GetBlockHeader, GetConfigAll, GetTransactions, ListBlockTransactions, LookupBlock, Request, WaitMasterchainSeqno, WrappedRequest
GetAccountState, GetAllShardsInfo, GetBlock, GetBlockHeader, GetConfigAll, GetMasterchainInfoExt, GetTransactions, ListBlockTransactions, LookupBlock, Request, WaitMasterchainSeqno, WrappedRequest
},
response::{AccountState, AllShardsInfo, BlockData, BlockHeader, BlockTransactions, ConfigInfo, MasterchainInfo, Response, TransactionId, TransactionList},
response::{AccountState, AllShardsInfo, BlockData, BlockHeader, BlockTransactions, ConfigInfo, MasterchainInfo, MasterchainInfoExt, Response, TransactionId, TransactionList},
},
types::LiteError,
};
Expand Down Expand Up @@ -49,6 +50,35 @@ impl LiteServer {
})
}

pub async fn get_masterchain_info_ext(&self, req: GetMasterchainInfoExt) -> Result<MasterchainInfoExt> {
if req.mode != 0 {
return Err(anyhow!("Unsupported mode"));
}
let last = self.engine.load_last_applied_mc_block_id()?;
let state = self.engine.load_state(&last).await?;
let root_hash = state.root_cell().repr_hash();
Ok(MasterchainInfoExt {
last: BlockIdExt {
workchain: last.shard_id.workchain_id(),
shard: last.shard_id.shard_prefix_with_tag(),
seqno: last.seq_no,
root_hash: Int256(last.root_hash.into()),
file_hash: Int256(last.file_hash.into()),
},
state_root_hash: Int256(root_hash.into()),
init: ZeroStateIdExt {
workchain: self.config.zero_state.shard_id.workchain_id(),
root_hash: Int256(self.config.zero_state.root_hash.into()),
file_hash: Int256(self.config.zero_state.file_hash.into()),
},
mode: (),
version: 0x101,
capabilities: 7,
last_utime: state.state().gen_time(),
now: now(),
})
}

fn make_block_proof(
block_root: Cell,
with_state_update: bool,
Expand Down Expand Up @@ -406,6 +436,9 @@ impl LiteServer {
Request::GetMasterchainInfo => Ok(Response::MasterchainInfo(
self.get_masterchain_info().await?,
)),
Request::GetMasterchainInfoExt(req) => Ok(Response::MasterchainInfoExt(
self.get_masterchain_info_ext(req).await?,
)),
Request::GetBlockHeader(req) => {
Ok(Response::BlockHeader(self.get_block_header(req).await?))
}
Expand Down

0 comments on commit d711aeb

Please sign in to comment.