Skip to content
This repository was archived by the owner on May 24, 2021. It is now read-only.

Commit

Permalink
Merge pull request #41 from tonlabs/0.25.0-rc
Browse files Browse the repository at this point in the history
0.25.0 rc
  • Loading branch information
AlexeyVavilin authored Jul 23, 2020
2 parents 66371cc + 2070a41 commit 75a6f89
Show file tree
Hide file tree
Showing 9 changed files with 234 additions and 96 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
# Release Notes
All notable changes to this project will be documented in this file.

## 0.25.0 - Jul 09, 2020
### Featured
- New transaction waiting mechanism. All account's shard blocks are checked for transaction to
guarantee message expiration

### New
- `wait_for_transaction` function hat waits for the transaction, generated by the previously sent message
- `send_message` returns message processing state for `wait_for_transaction` function

## 0.24.0 - Jun 01, 2020
### Featured
- Error resolving after message rejection
Expand Down
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ton-client-rs"
version = "0.24.0"
version = "0.25.0"
description = "TON SDK Client Library for Rust"
authors = ["TON DEV SOLUTIONS LTD <support@tonlabs.io>"]
edition = "2018"
Expand All @@ -26,3 +26,4 @@ ton_client = { git = "https://github.com/tonlabs/TON-SDK.git", tag = "0" }
[dev-dependencies]
lazy_static = "1.4.0"
dirs = "2.0.2"
log = "0.4.11"
11 changes: 5 additions & 6 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,24 @@ use serde::de::DeserializeOwned;
/// `message_processing_timeout` sets timeout in ms for processing messages to contracts which don't support
/// message expiration. It is also used for waiting blocks after message expiration time ends.assert_eq!
///
/// `message_processing_timeout_grow_factor` sets `message_processing_timeout` multiplying coefficient
/// for retriyng messages. `message_processing_timeout` for each retry is calculated by formula
/// `message_processing_timeout * message_processing_timeout_grow_factor^retry_index`. Default is 1.5
///
/// `wait_for_timeout` sets default timeout in ms for `wait_for` function
///
/// `access_key` is key for authenicating user to Tonlabs node
///
#[derive(Default, Serialize)]
/// `out_of_sync_threshold` is maximum allowed time difference between client and node in ms.
/// Default is 15000 ms
///
#[derive(Default, Serialize, Clone, Debug)]
#[serde(rename_all="camelCase")]
pub struct TonClientConfig {
pub base_url: Option<String>,
pub message_retries_count: Option<u8>,
pub message_expiration_timeout: Option<u32>,
pub message_expiration_timeout_grow_factor: Option<f32>,
pub message_processing_timeout: Option<u32>,
pub message_processing_timeout_grow_factor: Option<f32>,
pub wait_for_timeout: Option<u32>,
pub access_key: Option<String>,
pub out_of_sync_threshold: Option<i64>
}

/// Entry point for TON blockchain interaction. Provides useful methods for TON clients
Expand Down
82 changes: 58 additions & 24 deletions src/contracts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,8 @@ pub(crate) struct ParamsOfDeploy {
pub struct ResultOfDeploy {
pub address: TonAddress,
pub already_deployed: bool,
pub fees: Option<TransactionFees>
}

/// Result of `create_deploy_message` function. Contains message and future address of the contract
#[derive(Deserialize, Debug, PartialEq)]
pub struct ResultOfCreateDeployMessage {
pub address: TonAddress,
#[serde(flatten)]
pub message: EncodedMessage,
pub fees: Option<TransactionFees>,
pub transaction: serde_json::Value,
}

#[derive(Serialize, Debug, PartialEq)]
Expand Down Expand Up @@ -109,7 +102,8 @@ pub(crate) struct ParamsOfLocalRunWithMsg {
#[derive(Deserialize, Debug, PartialEq)]
pub struct ResultOfRun {
pub output: Value,
pub fees: TransactionFees
pub fees: TransactionFees,
pub transaction: serde_json::Value,
}

/// Result of `run` function running. Contains parameters returned by contract function
Expand Down Expand Up @@ -140,6 +134,7 @@ pub struct EncodedMessage {
pub message_id: String,
pub message_body: Vec<u8>,
pub expire: Option<u32>,
pub address: TonAddress,
}

#[derive(Serialize, Deserialize, Debug, PartialEq)]
Expand All @@ -164,7 +159,7 @@ pub(crate) struct ParamsOfProcessMessage{
pub abi: Option<serde_json::Value>,
pub function_name: Option<String>,
pub message: EncodedMessage,
pub try_index: Option<u8>,
pub infinite_wait: bool
}

#[derive(Deserialize, Serialize, Debug, Default, PartialEq)]
Expand Down Expand Up @@ -198,7 +193,7 @@ pub(crate) struct ParamsOfResolveError {
pub main_error: InnerSdkError,
}

#[derive(Serialize, Deserialize, Debug, PartialEq)]
#[derive(Serialize, Debug, PartialEq)]
#[serde(rename_all = "camelCase")]
pub(crate) struct ParamsOfProcessTransaction{
pub transaction: serde_json::Value,
Expand All @@ -207,6 +202,23 @@ pub(crate) struct ParamsOfProcessTransaction{
pub address: TonAddress,
}

#[derive(Serialize, Deserialize, Clone, Debug)]
#[serde(rename_all = "camelCase")]
pub struct MessageProcessingState {
last_block_id: String,
sending_time: u32,
}

#[derive(Serialize)]
#[serde(rename_all = "camelCase")]
pub(crate) struct ParamsOfWaitForTransaction {
pub abi: Option<serde_json::Value>,
pub function_name: Option<String>,
pub message: EncodedMessage,
pub message_processing_state: MessageProcessingState,
pub infinite_wait: bool
}

/// Contract management struct
pub struct TonContracts {
context: InteropContext,
Expand Down Expand Up @@ -271,7 +283,7 @@ impl TonContracts {
image_base64: base64::encode(code),
key_pair: keys.clone(),
workchain_id: workchain_id,
try_index: None
try_index: None,
})
}

Expand All @@ -292,7 +304,7 @@ impl TonContracts {
header: option_params_to_value(header)?,
input: input.to_value()?,
key_pair: keys.cloned(),
try_index: None
try_index: None,
})
}

Expand Down Expand Up @@ -395,7 +407,7 @@ impl TonContracts {
header: option_params_to_value(header)?,
input: input.to_value()?,
key_pair: keys.cloned(),
try_index
try_index,
})
}

Expand All @@ -410,7 +422,7 @@ impl TonContracts {
keys: &Ed25519KeyPair,
workchain_id: i32,
try_index: Option<u8>
) -> TonResult<ResultOfCreateDeployMessage> {
) -> TonResult<EncodedMessage> {
Interop::json_request(
self.context,
"contracts.deploy.message",
Expand All @@ -421,13 +433,13 @@ impl TonContracts {
constructor_params: constructor_params.to_value()?,
image_base64: base64::encode(code),
key_pair: keys.clone(),
workchain_id: workchain_id,
try_index
workchain_id,
try_index,
})
}

/// Send message to node without waiting for processing result
pub fn send_message(&self, message: EncodedMessage) -> TonResult<()> {
pub fn send_message(&self, message: EncodedMessage) -> TonResult<MessageProcessingState> {
Interop::json_request(
self.context,
"contracts.send.message",
Expand All @@ -441,16 +453,38 @@ impl TonContracts {
message: EncodedMessage,
abi: Option<JsonValue>,
function_name: Option<&str>,
try_index: Option<u8>
infinite_wait: bool
) -> TonResult<ResultOfRun> {
Interop::json_request(
self.context,
"contracts.process.message",
ParamsOfProcessMessage {
abi: option_params_to_value(abi)?,
function_name: function_name.map(|val| val.to_owned()),
try_index,
message: message.into()
infinite_wait,
message: message
}
)
}

/// Wait for message processing result and (optionally) parse result
pub fn wait_for_transaction(
&self,
message: EncodedMessage,
abi: Option<JsonValue>,
function_name: Option<&str>,
message_processing_state: MessageProcessingState,
infinite_wait: bool
) -> TonResult<ResultOfRun> {
Interop::json_request(
self.context,
"contracts.wait.transaction",
ParamsOfWaitForTransaction {
abi: option_params_to_value(abi)?,
function_name: function_name.map(|val| val.to_owned()),
message_processing_state,
message,
infinite_wait
}
)
}
Expand Down Expand Up @@ -499,14 +533,14 @@ impl TonContracts {
address: &TonAddress,
account: Option<JsonValue>,
message: EncodedMessage,
send_time: u32,
time: u32,
error: InnerSdkError
) -> TonResult<()> {
Interop::json_request(self.context, "contracts.resolve.error", ParamsOfResolveError {
address: address.clone(),
account: option_params_to_value(account)?,
message_base64: base64::encode(&message.message_body),
time: send_time,
time: time,
main_error: error,
})
}
Expand Down
6 changes: 5 additions & 1 deletion src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@
/// Error returned from SDK core
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct InnerSdkError {
pub core_version: String,
pub source: String,
pub code: isize,
pub message: String,
pub message_processing_state: Option<crate::contracts::MessageProcessingState>,
pub data: serde_json::Value,
}

Expand Down Expand Up @@ -77,10 +79,12 @@ error_chain! {
InnerSdkError(inner: InnerSdkError) {
description("Inner SDK error"),
display(
"Inner SDK error.\n source: {}\n code: {}\n message: {}\n data: {:#}\n",
"Inner SDK error.\n core version: {}\n source: {}\n code: {}\n message: {}\n message processing state: {:#?} data: {:#}\n",
inner.core_version,
inner.source,
inner.code,
inner.message,
inner.message_processing_state,
inner.data,
)
}
Expand Down
7 changes: 5 additions & 2 deletions src/json_helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,16 @@ pub(crate) struct EncodedMessageCore {
pub message_id: String,
pub message_body_base64: String,
pub expire: Option<u32>,
pub address: TonAddress,
}

impl Into<EncodedMessageCore> for EncodedMessage {
fn into(self) -> EncodedMessageCore {
EncodedMessageCore {
message_id: self.message_id,
message_body_base64: base64::encode(&self.message_body),
expire: self.expire
expire: self.expire,
address: self.address
}
}
}
Expand All @@ -67,7 +69,8 @@ impl TryFrom<EncodedMessageCore> for EncodedMessage {
Ok(EncodedMessage {
message_id: value.message_id,
message_body: base64::decode(&value.message_body_base64)?,
expire: value.expire
expire: value.expire,
address: value.address
})
}
}
Expand Down
Loading

0 comments on commit 75a6f89

Please sign in to comment.