Skip to content

Commit

Permalink
Merge pull request #1012 from tonlabs/1.44.0-rc
Browse files Browse the repository at this point in the history
Version 1.44.0
  • Loading branch information
d3p authored Jul 13, 2023
2 parents 49ebb97 + 7478254 commit f70e3a9
Show file tree
Hide file tree
Showing 58 changed files with 705 additions and 567 deletions.
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,23 @@
All notable changes to this project will be documented in this file.


## [1.44.0] – 2023-07-12

### New

- Ability to call async functions via `tc_request_sync`.
- In rust API, the following functions become sync (slight breaking):
`abi::encode_internal_message`, `abi::attach_signature_to_message_body`, `abi::attach_signature`,
`abi::decode_message`, `abi::decode_message_body`, `abi::decode_account_data`,
`abi::update_initial_data`, `abi::encode_initial_data`, `abi::decode_initial_data`,
`abi::decode_boc`, `abi::encode_boc`, `boc::decode_tvc`, `boc::parse_message`, `boc::parse_transaction`,
`boc::parse_account`, `boc::parse_block`, `boc::parse_shardstate`, `boc::get_blockchain_config`,
`boc::get_boc_hash`, `boc::get_code_from_tvc`, `boc::cache_get`, `boc::cache_set`, `boc::cache_unpin`,
`boc::encode_boc`, `boc::get_code_salt`, `boc::set_code_salt`, `boc::decode_state_init`, `boc::encode_state_init`,
`boc::encode_external_in_message`, `boc::get_compiler_version`, `processing::monitor_messages`,
`processing::get_monitor_info`, `processing::cancel_monitor`
- Code generator for `modules.ts` produces `_sync` wrapper for all API functions.

## [1.43.3] – 2023-06-24

### Fixed
Expand Down
14 changes: 7 additions & 7 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion api/derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
authors = [ 'TON Labs LTD <[email protected]>' ]
edition = '2018'
name = 'api_derive'
version = '1.43.3'
version = '1.44.0'

[dependencies]
quote = '1.0.26'
Expand Down
2 changes: 1 addition & 1 deletion api/info/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
authors = [ 'TON Labs LTD <[email protected]>' ]
edition = '2018'
name = 'api_info'
version = '1.43.3'
version = '1.44.0'

[dependencies]
serde = '1.0.115'
Expand Down
2 changes: 1 addition & 1 deletion api/test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
authors = [ 'TON Labs LTD <[email protected]>' ]
edition = '2018'
name = 'api_test'
version = '1.43.3'
version = '1.44.0'

[dependencies]
serde = '1.0.115'
Expand Down
2 changes: 1 addition & 1 deletion ton_client/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = 'ton_client'
version = '1.43.3'
version = '1.44.0'
authors = [ 'TON Labs LTD <[email protected]>' ]
edition = '2018'
license = 'Apache-2.0'
Expand Down
34 changes: 17 additions & 17 deletions ton_client/src/abi/decode_boc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub struct ParamsOfDecodeBoc {
pub boc: String,
// Do not check if all BOC data is parsed by provided parameters set
// Set it to `true` if don't need to decode the whole BOC data or if you need
// to handle conditional parsing (when TLB constructor or flags should be
// to handle conditional parsing (when TLB constructor or flags should be
// checked to decide how to parse remaining BOC data)
pub allow_partial: bool,
}
Expand All @@ -30,29 +30,29 @@ pub struct ResultOfDecodeBoc {
}

/// Decodes BOC into JSON as a set of provided parameters.
///
/// Solidity functions use ABI types for [builder encoding](https://github.com/tonlabs/TON-Solidity-Compiler/blob/master/API.md#tvmbuilderstore).
/// The simplest way to decode such a BOC is to use ABI decoding.
/// ABI has it own rules for fields layout in cells so manually encoded
/// BOC can not be described in terms of ABI rules.
///
/// To solve this problem we introduce a new ABI type `Ref(<ParamType>)`
/// which allows to store `ParamType` ABI parameter in cell reference and, thus,
/// decode manually encoded BOCs. This type is available only in `decode_boc` function
///
/// Solidity functions use ABI types for [builder encoding](https://github.com/tonlabs/TON-Solidity-Compiler/blob/master/API.md#tvmbuilderstore).
/// The simplest way to decode such a BOC is to use ABI decoding.
/// ABI has it own rules for fields layout in cells so manually encoded
/// BOC can not be described in terms of ABI rules.
///
/// To solve this problem we introduce a new ABI type `Ref(<ParamType>)`
/// which allows to store `ParamType` ABI parameter in cell reference and, thus,
/// decode manually encoded BOCs. This type is available only in `decode_boc` function
/// and will not be available in ABI messages encoding until it is included into some ABI revision.
///
/// Such BOC descriptions covers most users needs. If someone wants to decode some BOC which
/// can not be described by these rules (i.e. BOC with TLB containing constructors of flags
/// defining some parsing conditions) then they can decode the fields up to fork condition,
/// check the parsed data manually, expand the parsing schema and then decode the whole BOC
///
/// Such BOC descriptions covers most users needs. If someone wants to decode some BOC which
/// can not be described by these rules (i.e. BOC with TLB containing constructors of flags
/// defining some parsing conditions) then they can decode the fields up to fork condition,
/// check the parsed data manually, expand the parsing schema and then decode the whole BOC
/// with the full schema.
#[api_function]
pub async fn decode_boc(
pub fn decode_boc(
context: Arc<ClientContext>,
params: ParamsOfDecodeBoc,
) -> ClientResult<ResultOfDecodeBoc> {
let (_, data) = deserialize_cell_from_boc(&context, &params.boc, "").await?;
let (_, data) = deserialize_cell_from_boc(&context, &params.boc, "")?;

let mut abi_params = Vec::with_capacity(params.params.len());
for param in params.params {
Expand Down
4 changes: 2 additions & 2 deletions ton_client/src/abi/decode_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ pub struct ResultOfDecodeAccountData {
///
/// Note: this feature requires ABI 2.1 or higher.
#[api_function]
pub async fn decode_account_data(
pub fn decode_account_data(
context: Arc<ClientContext>,
params: ParamsOfDecodeAccountData,
) -> ClientResult<ResultOfDecodeAccountData> {
let (_, data) = deserialize_cell_from_boc(&context, &params.data, "contract data").await?;
let (_, data) = deserialize_cell_from_boc(&context, &params.data, "contract data")?;
let abi = params.abi.abi()?;

let tokens = abi.decode_storage_fields(slice_from_cell(data)?, params.allow_partial)
Expand Down
29 changes: 14 additions & 15 deletions ton_client/src/abi/decode_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,19 +100,19 @@ pub struct ParamsOfDecodeMessage {
/// Function name or function id if is known in advance
pub function_name: Option<String>,

// For external (inbound and outbound) messages data_layout parameter is ignored.
// For internal: by default SDK tries to decode as output and then if decode is not successfull - tries as input.
// If explicitly specified then tries only the specified layout.
// For external (inbound and outbound) messages data_layout parameter is ignored.
// For internal: by default SDK tries to decode as output and then if decode is not successfull - tries as input.
// If explicitly specified then tries only the specified layout.
pub data_layout: Option<DataLayout>,
}

/// Decodes message body using provided message BOC and ABI.
#[api_function]
pub async fn decode_message(
pub fn decode_message(
context: Arc<ClientContext>,
params: ParamsOfDecodeMessage,
) -> ClientResult<DecodedMessageBody> {
let (abi, message) = prepare_decode(&context, &params).await?;
let (abi, message) = prepare_decode(&context, &params)?;
if let Some(body) = message.body() {
let data_layout = match message.header() {
ton_block::CommonMsgInfo::ExtInMsgInfo(_) => Some(DataLayout::Input),
Expand Down Expand Up @@ -151,29 +151,28 @@ pub struct ParamsOfDecodeMessageBody {
pub function_name: Option<String>,

// By default SDK tries to decode as output and then if decode is not successfull - tries as input.
// If explicitly specified then tries only the specified layout.
// If explicitly specified then tries only the specified layout.
pub data_layout: Option<DataLayout>,
}

/// Decodes message body using provided body BOC and ABI.
#[api_function]
pub async fn decode_message_body(
pub fn decode_message_body(
context: Arc<ClientContext>,
params: ParamsOfDecodeMessageBody,
) -> ClientResult<DecodedMessageBody> {
let abi = params.abi.abi()?;
let (_, body) = deserialize_cell_from_boc(&context, &params.body, "message body").await?;
let (_, body) = deserialize_cell_from_boc(&context, &params.body, "message body")?;
let body = slice_from_cell(body)?;
decode_body(abi, body, params.is_internal, params.allow_partial, params.function_name, params.data_layout)
}

async fn prepare_decode(
fn prepare_decode(
context: &ClientContext,
params: &ParamsOfDecodeMessage,
) -> ClientResult<(AbiContract, ton_block::Message)> {
let abi = params.abi.abi()?;
let message = deserialize_object_from_boc(context, &params.message, "message")
.await
.map_err(|x| Error::invalid_message_for_decode(x))?;
Ok((abi, message.object))
}
Expand Down Expand Up @@ -300,7 +299,7 @@ fn decode_with_function(
function_name,
tokens: decoded,
};
DecodedMessageBody::new(MessageBodyType::Event, decoded, None)
DecodedMessageBody::new(MessageBodyType::Event, decoded, None)
}
}
}
Expand Down Expand Up @@ -358,7 +357,7 @@ pub async fn get_signature_data(
params: ParamsOfGetSignatureData,
) -> ClientResult<ResultOfGetSignatureData> {
let abi = params.abi.abi()?;
let message: ton_block::Message = deserialize_object_from_boc(&context, &params.message, "message").await?.object;
let message: ton_block::Message = deserialize_object_from_boc(&context, &params.message, "message")?.object;
if let Some(body) = message.body() {
let address = message.dst()
.ok_or_else(|| Error::invalid_message_for_decode(
Expand All @@ -367,13 +366,13 @@ pub async fn get_signature_data(
let (signature, hash) = abi.get_signature_data(body, Some(address))
.map_err(|err| Error::invalid_message_for_decode(err))?;
let unsigned = extend_data_to_sign(&context, params.signature_id, Some(hash)).await?;
Ok(ResultOfGetSignatureData {
signature: hex::encode(&signature),
Ok(ResultOfGetSignatureData {
signature: hex::encode(&signature),
unsigned: base64::encode(&unsigned.unwrap()),
})
} else {
Err(Error::invalid_message_for_decode(
"The message body is empty",
))
}
}
}
20 changes: 10 additions & 10 deletions ton_client/src/abi/encode_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,25 +84,25 @@ async fn state_init_from_message(
let (message, _) = message.encode(context).await?;
let message = deserialize_object_from_boc::<ton_block::Message>(
context, &message, "message"
).await?.object;
)?.object;
message
.state_init()
.map(|x| x.clone())
.ok_or(Error::invalid_message_for_decode("missing `state_init`"))
}

async fn state_init_from_bocs(
fn state_init_from_bocs(
context: &ClientContext,
code: &String,
data: &String,
library: &Option<String>,
) -> ClientResult<StateInit> {
Ok(StateInit {
code: Some(deserialize_cell_from_boc(context, code, "account code").await?.1),
data: Some(deserialize_cell_from_boc(context, data, "account data").await?.1),
code: Some(deserialize_cell_from_boc(context, code, "account code")?.1),
data: Some(deserialize_cell_from_boc(context, data, "account data")?.1),
library: if let Some(library) = library {
StateInitLib::with_hashmap(
Some(deserialize_cell_from_boc(context, library, "library").await?.1)
Some(deserialize_cell_from_boc(context, library, "library")?.1)
)
} else {
StateInitLib::default()
Expand All @@ -112,13 +112,13 @@ async fn state_init_from_bocs(
})
}

async fn state_init_from_tvc(
fn state_init_from_tvc(
context: &ClientContext,
tvc: &String,
public_key: &Option<String>,
init_params: &Option<StateInitParams>,
) -> ClientResult<StateInit> {
let (_, cell) = deserialize_cell_from_boc(context, tvc, "TVC image").await?;
let (_, cell) = deserialize_cell_from_boc(context, tvc, "TVC image")?;
let public_key = public_key
.as_ref()
.map(|x| decode_public_key(x))
Expand Down Expand Up @@ -160,12 +160,12 @@ pub async fn encode_account(
code,
data,
library,
} => state_init_from_bocs(&context, code, data, library).await,
} => state_init_from_bocs(&context, code, data, library),
StateInitSource::Tvc {
tvc,
public_key,
init_params,
} => state_init_from_tvc(&context, tvc, public_key, init_params).await,
} => state_init_from_tvc(&context, tvc, public_key, init_params),
}?;
let id = state_init.hash().map_err(|err| Error::invalid_tvc_image(err))?;
let address = MsgAddressInt::with_standart(None, 0, id.clone().into()).unwrap();
Expand All @@ -175,7 +175,7 @@ pub async fn encode_account(
.map_err(|err| Error::invalid_tvc_image(err))?;
account.set_last_tr_time(params.last_trans_lt.unwrap_or(0));
Ok(ResultOfEncodeAccount {
account: serialize_object_to_boc(&context, &account, "account", params.boc_cache).await?,
account: serialize_object_to_boc(&context, &account, "account", params.boc_cache)?,
id: id.as_hex_string(),
})
}
4 changes: 2 additions & 2 deletions ton_client/src/abi/encode_boc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub struct ResultOfAbiEncodeBoc {

/// Encodes given parameters in JSON into a BOC using param types from ABI.
#[api_function]
pub async fn encode_boc(
pub fn encode_boc(
context: Arc<ClientContext>,
params: ParamsOfAbiEncodeBoc,
) -> ClientResult<ResultOfAbiEncodeBoc> {
Expand All @@ -49,6 +49,6 @@ pub async fn encode_boc(
.map_err(|err| Error::invalid_abi(err))?;

Ok(ResultOfAbiEncodeBoc {
boc: serialize_cell_to_boc(&context, cell, "ABI params", params.boc_cache).await?,
boc: serialize_cell_to_boc(&context, cell, "ABI params", params.boc_cache)?,
})
}
Loading

0 comments on commit f70e3a9

Please sign in to comment.