Skip to content

Commit

Permalink
Merge branch 'async' of github.com:tonstack/lite-client into async
Browse files Browse the repository at this point in the history
  • Loading branch information
hacker-volodya committed Jun 21, 2024
2 parents 8a93445 + 86a7cfa commit 8289d25
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 35 deletions.
7 changes: 4 additions & 3 deletions liteapi/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use std::time::Duration;

use adnl::AdnlPeer;
use adnl::AdnlPrivateKey;
use log::error;
use tokio::net::TcpListener;
use tokio::net::ToSocketAddrs;
use tokio_tower::multiplex::Server;
Expand Down Expand Up @@ -40,19 +39,21 @@ pub async fn serve<A, S, M>(addr: &A, private_key: S, mut service_maker: M) -> R
// > will be logged at the `error` level, since it is still a big deal,
// > and then the listener will sleep for 1 second.
if !matches!(e.kind(), ErrorKind::ConnectionRefused | ErrorKind::ConnectionAborted | ErrorKind::ConnectionReset) {
error!("accept error: {e}");
log::error!("accept error: {e}");
tokio::time::sleep(Duration::from_secs(1)).await;
}
continue;
}
};
log::debug!("[{addr:?}] Accepted socket");
poll_fn(|cx| service_maker.poll_ready(cx)).await.expect("polling service maker failed");
let service = service_maker.make_service(addr).await.expect("making service failed");
let private_key = private_key.clone();
tokio::spawn(async move {
let adnl = AdnlPeer::handle_handshake(socket, |_| Some(private_key.clone())).await.expect("handshake failed");
log::debug!("[{addr:?}] Handshake performed");
let lite = LitePeer::new(adnl);
Server::new(lite, service).await.expect("server failed");
});
}
}
}
14 changes: 7 additions & 7 deletions liteapi/src/tl/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl String {

/// int256 8*[ int ] = Int256;
#[derive(TlRead, TlWrite, Derivative)]
#[derivative(Debug, Clone, PartialEq, Eq, Default)]
#[derivative(Debug, Clone, PartialEq, Eq, Default, Hash)]
pub struct Int256(#[derivative(Debug(format_with = "fmt_bytes"))] pub [u8; 32]);

impl FromStr for Int256 {
Expand Down Expand Up @@ -81,7 +81,7 @@ pub struct BlockId {

/// tonNode.blockIdExt workchain:int shard:long seqno:int root_hash:int256 file_hash:int256 = tonNode.BlockIdExt;
#[derive(TlRead, TlWrite, Derivative)]
#[derivative(Debug, Clone, PartialEq)]
#[derivative(Debug, Clone, PartialEq, Eq, Hash)]
pub struct BlockIdExt {
pub workchain: i32,
pub shard: u64,
Expand Down Expand Up @@ -110,7 +110,7 @@ pub struct AccountId {
// #[tl(boxed, id = "liteServer.transactionId3", scheme_inline = r##"liteServer.transactionId3 account:int256 lt:long = liteServer.TransactionId3;"##)]
pub struct TransactionId3 {
pub account: Int256,
pub lt: i64,
pub lt: u64,
}

/// liteServer.signature node_id_short:int256 signature:bytes = liteServer.Signature;
Expand All @@ -131,8 +131,8 @@ pub struct Signature {
scheme_inline = r##"liteServer.signatureSet validator_set_hash:int catchain_seqno:int signatures:(vector liteServer.signature) = liteServer.SignatureSet;"##
)]
pub struct SignatureSet {
pub validator_set_hash: i32,
pub catchain_seqno: i32,
pub validator_set_hash: u32,
pub catchain_seqno: u32,
pub signatures: Vec<Signature>,
}

Expand Down Expand Up @@ -186,7 +186,7 @@ pub struct TransactionId {
#[tl(flags_bit = "mode.0")]
pub account: Option<Int256>,
#[tl(flags_bit = "mode.1")]
pub lt: Option<i64>,
pub lt: Option<u64>,
#[tl(flags_bit = "mode.2")]
pub hash: Option<Int256>,
}
}
36 changes: 24 additions & 12 deletions liteapi/src/tl/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ pub struct WrappedRequest {
scheme_inline = r##"liteServer.waitMasterchainSeqno seqno:int timeout_ms:int = Object;"##
)]
pub struct WaitMasterchainSeqno {
pub seqno: i32,
pub timeout_ms: i32,
pub seqno: u32,
pub timeout_ms: u32,
}

#[derive(TlRead, TlWrite, Derivative)]
Expand Down Expand Up @@ -93,7 +93,7 @@ pub struct RunSmcMethod {
pub mode: u32,
pub id: BlockIdExt,
pub account: AccountId,
pub method_id: i64,
pub method_id: u64,
pub params: Vec<u8>,
}

Expand All @@ -117,15 +117,15 @@ pub struct GetAllShardsInfo {
pub struct GetOneTransaction {
pub id: BlockIdExt,
pub account: AccountId,
pub lt: i64,
pub lt: u64,
}

#[derive(TlRead, TlWrite, Derivative)]
#[derivative(Debug, Clone, PartialEq)]
pub struct GetTransactions {
pub count: i32,
pub count: u32,
pub account: AccountId,
pub lt: i64,
pub lt: u64,
pub hash: Int256,
}

Expand All @@ -135,10 +135,22 @@ pub struct LookupBlock {
#[tl(flags)]
pub mode: (),
pub id: BlockId,
#[tl(flags_bit = "mode.0")]
pub seqno: Option<()>,
#[tl(flags_bit = "mode.1")]
pub lt: Option<i64>,
pub lt: Option<u64>,
#[tl(flags_bit = "mode.2")]
pub utime: Option<i32>,
pub utime: Option<u32>,
#[tl(flags_bit = "mode.4")]
pub with_state_update: Option<()>,
#[tl(flags_bit = "mode.5")]
pub with_value_flow: Option<()>,
#[tl(flags_bit = "mode.8")]
pub with_extra: Option<()>,
#[tl(flags_bit = "mode.9")]
pub with_shard_hashes: Option<()>,
#[tl(flags_bit = "mode.10")]
pub with_prev_blk_signatures: Option<()>,
}

#[derive(TlRead, TlWrite, Derivative)]
Expand All @@ -147,7 +159,7 @@ pub struct ListBlockTransactions {
pub id: BlockIdExt,
#[tl(flags)]
pub mode: (),
pub count: i32,
pub count: u32,
#[tl(flags_bit = "mode.7")]
pub after: Option<TransactionId3>,
#[tl(flags_bit = "mode.6")]
Expand Down Expand Up @@ -217,11 +229,11 @@ pub struct GetValidatorStats {
#[tl(flags)]
pub mode: (),
id: BlockIdExt,
pub limit: i32,
pub limit: u32,
#[tl(flags_bit = "mode.0")]
pub start_after: Option<Int256>,
#[tl(flags_bit = "mode.2")]
pub modified_after: Option<i32>,
pub modified_after: Option<u32>,
}

#[derive(TlRead, TlWrite, Derivative)]
Expand Down Expand Up @@ -307,4 +319,4 @@ pub enum Request {
/// liteServer.getValidatorStats#091a58bc mode:# id:tonNode.blockIdExt limit:int start_after:mode.0?int256 modified_after:mode.2?int = liteServer.ValidatorStats;
#[tl(id = 0xe7253699)]
GetValidatorStats(GetValidatorStats),
}
}
26 changes: 13 additions & 13 deletions liteapi/src/tl/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,28 @@ pub struct MasterchainInfo {
pub struct MasterchainInfoExt {
#[tl(flags)]
pub mode: (),
pub version: i32,
pub capabilities: i64,
pub version: u32,
pub capabilities: u64,
pub last: BlockIdExt,
pub last_utime: i32,
pub now: i32,
pub last_utime: u32,
pub now: u32,
pub state_root_hash: Int256,
pub init: ZeroStateIdExt,
}

#[derive(TlRead, TlWrite, Derivative)]
#[derivative(Debug, Clone, PartialEq)]
pub struct CurrentTime {
pub now: i32,
pub now: u32,
}

#[derive(TlRead, TlWrite, Derivative)]
#[derivative(Debug, Clone, PartialEq)]
pub struct Version {
pub mode: i32,
pub version: i32,
pub capabilities: i64,
pub now: i32,
pub mode: u32,
pub version: u32,
pub capabilities: u64,
pub now: u32,
}

#[derive(TlRead, TlWrite, Derivative)]
Expand Down Expand Up @@ -79,7 +79,7 @@ pub struct BlockHeader {
#[derive(TlRead, TlWrite, Derivative)]
#[derivative(Debug, Clone, PartialEq)]
pub struct SendMsgStatus {
pub status: i32,
pub status: u32,
}

#[derive(TlRead, TlWrite, Derivative)]
Expand Down Expand Up @@ -157,7 +157,7 @@ pub struct TransactionId {
#[tl(flags_bit = "mode.0")]
pub account: Option<Int256>,
#[tl(flags_bit = "mode.1")]
pub lt: Option<i64>,
pub lt: Option<u64>,
#[tl(flags_bit = "mode.2")]
pub hash: Option<Int256>,
}
Expand All @@ -166,7 +166,7 @@ pub struct TransactionId {
#[derivative(Debug, Clone, PartialEq)]
pub struct BlockTransactions {
pub id: BlockIdExt,
pub req_count: i32,
pub req_count: u32,
pub incomplete: bool,
pub ids: Vec<TransactionId>,
pub proof: Vec<u8>,
Expand Down Expand Up @@ -211,7 +211,7 @@ pub struct ValidatorStats {
#[tl(flags)]
pub mode: (),
pub id: BlockIdExt,
pub count: i32,
pub count: u32,
pub complete: bool,
pub state_proof: Vec<u8>,
pub data_proof: Vec<u8>,
Expand Down

0 comments on commit 8289d25

Please sign in to comment.