Skip to content

Commit

Permalink
Merge pull request #15 from ston-fi/release-0.6.1
Browse files Browse the repository at this point in the history
Release 0.6.1
  • Loading branch information
ruslanracheev authored Jul 19, 2023
2 parents fb7ac6d + bed0247 commit 91ccdae
Show file tree
Hide file tree
Showing 7 changed files with 134 additions and 12 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Build
/target
/Cargo.lock
/.cargo

# Editors
.DS_Store
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "tonlib"
version = "0.5.4"
version = "0.6.1"
edition = "2021"
description = "Rust SDK for The Open Network"
license = "MIT"
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ let wallet_address = contract.get_wallet_address(&owner_address).await?;
Create key pair from secret phrase (mnemonic)

```rust
let mnemonic_str = "<your secret phrase composed of 24 words>"
let mnemonic_str = "<your secret phrase composed of 24 words>";
let mnemonic: Mnemonic = Mnemonic::from_str(mnemonic_str, &None).unwrap();
let key_pair: KeyPair = mnemonic.to_key_pair().unwrap();
```
Expand Down Expand Up @@ -255,7 +255,7 @@ let body = wallet.create_external_body(now + 60, SEQNO, transfer)?;
let signed = wallet.sign_external_body(&body)?;
let wrapped = wallet.wrap_signed_body(signed)?;
let boc = BagOfCells::from_root(wrapped);
let tx = boc.serialize(true)?
let tx = boc.serialize(true)?;
let hash = client.send_raw_message_return_hash(tx.as_slice()).await?;
```

Expand Down
47 changes: 46 additions & 1 deletion src/client/types.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::client::connection::TonConnection;
use crate::config::MAINNET_CONFIG;
use crate::tl::TonFunction;
use crate::{client::connection::TonConnection, tl::stack::TvmCell};
use anyhow::anyhow;
use async_trait::async_trait;
use lazy_static::lazy_static;
Expand Down Expand Up @@ -232,6 +232,51 @@ pub trait TonFunctions {
Ok(result)
}

async fn smc_load_by_transaction(
&self,
account_address: &str,
transaction_id: &InternalTransactionId,
) -> anyhow::Result<(TonConnection, i64)> {
let func = TonFunction::SmcLoadByTransaction {
account_address: AccountAddress {
account_address: String::from(account_address),
},
transaction_id: transaction_id.clone(),
};
let (conn, result) = self.invoke_on_connection(&func).await?;
match result {
TonResult::SmcInfo(smc_info) => Ok((conn, smc_info.id)),
r => Err(anyhow!("Expected SmcInfo, got: {:?}", r)),
}
}

async fn smc_get_code(&self, id: i64) -> anyhow::Result<TvmCell> {
let func = TonFunction::SmcGetCode { id: id };
let result = self.invoke(&func).await?;
match result {
TonResult::TvmCell(cell) => Ok(cell),
r => Err(anyhow!("Expected TvmCell, got: {:?}", r)),
}
}

async fn smc_get_data(&self, id: i64) -> anyhow::Result<TvmCell> {
let func = TonFunction::SmcGetData { id: id };
let result = self.invoke(&func).await?;
match result {
TonResult::TvmCell(cell) => Ok(cell),
r => Err(anyhow!("Expected TvmCell, got: {:?}", r)),
}
}

async fn smc_get_state(&self, id: i64) -> anyhow::Result<TvmCell> {
let func = TonFunction::SmcGetState { id: id };
let result = self.invoke(&func).await?;
match result {
TonResult::TvmCell(cell) => Ok(cell),
r => Err(anyhow!("Expected TvmCell, got: {:?}", r)),
}
}

async fn get_masterchain_info(&self) -> anyhow::Result<BlocksMasterchainInfo> {
let func = TonFunction::BlocksGetMasterchainInfo {};
let result = self.invoke(&func).await?;
Expand Down
18 changes: 18 additions & 0 deletions src/tl/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,29 @@ pub enum TonFunction {
SmcLoad {
account_address: AccountAddress,
},
#[serde(rename = "smc.loadByTransaction")]
SmcLoadByTransaction {
account_address: AccountAddress,
transaction_id: InternalTransactionId,
},

// tonlib_api.tl, line 302
#[serde(rename = "smc.forget")]
SmcForget {
id: i64,
},
#[serde(rename = "smc.getCode")]
SmcGetCode {
id: i64,
},
#[serde(rename = "smc.getData")]
SmcGetData {
id: i64,
},
#[serde(rename = "smc.getState")]
SmcGetState {
id: i64,
},
// tonlib_api.tl, line 298
#[serde(rename = "smc.runGetMethod")]
SmcRunGetMethod {
Expand Down
18 changes: 11 additions & 7 deletions src/tl/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use anyhow::anyhow;
use serde::{Deserialize, Serialize};
use strum::IntoStaticStr;

use crate::tl::stack::TvmCell;
use crate::tl::types::{
BlockIdExt, BlocksHeader, BlocksMasterchainInfo, BlocksShards, BlocksTransactions,
FullAccountState, LogVerbosityLevel, OptionsInfo, RawExtMessageInfo, RawFullAccountState,
Expand Down Expand Up @@ -36,28 +37,31 @@ pub enum TonResult {
// tonlib_api.tl, line 88
#[serde(rename = "fullAccountState")]
FullAccountState(FullAccountState),
// tonlib_api.tl, line 176
// tonlib_api.tl, line 177
#[serde(rename = "smc.info")]
SmcInfo(SmcInfo),
// tonlib_api.tl, line 181
// tonlib_api.tl, line 182
#[serde(rename = "smc.runResult")]
SmcRunResult(SmcRunResult),
// tonlib_api.tl, line 187
// tonlib_api.tl, line 165
#[serde(rename = "tvm.cell")]
TvmCell(TvmCell),
// tonlib_api.tl, line 188
#[serde(rename = "updateSyncState")]
UpdateSyncState(UpdateSyncState),
// tonlib_api.tl, line 202
// tonlib_api.tl, line 345
#[serde(rename = "logVerbosityLevel")]
LogVerbosityLevel(LogVerbosityLevel),
// tonlib_api.tl, line 212
#[serde(rename = "blocks.masterchainInfo")]
BlocksMasterchainInfo(BlocksMasterchainInfo),
// tonlib_api.tl, line 213
// tonlib_api.tl, line 214
#[serde(rename = "blocks.shards")]
BlocksShards(BlocksShards),
// tonlib_api.tl, line 216
// tonlib_api.tl, line 218
#[serde(rename = "blocks.transactions")]
BlocksTransactions(BlocksTransactions),
// tonlib_api.tl, line 217
// tonlib_api.tl, line 219
#[serde(rename = "blocks.header")]
BlocksHeader(BlocksHeader),
}
Expand Down
56 changes: 55 additions & 1 deletion tests/client_test.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::thread;
use std::time::Duration;
use std::{str::FromStr, thread};

use tokio;
use tokio::time::timeout;
Expand Down Expand Up @@ -97,6 +97,60 @@ async fn client_smc_run_get_method_works() -> anyhow::Result<()> {
Ok(())
}

#[tokio::test]
async fn client_smc_load_by_transaction_works() -> anyhow::Result<()> {
common::init_logging();

let client = common::new_test_client().await?;
let address = "EQCVx4vipWfDkf2uNhTUkpT97wkzRXHm-N1cNn_kqcLxecxT";
let internal_transaction_id = InternalTransactionId::from_str(
"32016630000001:91485a21ba6eaaa91827e357378fe332228d11f3644e802f7e0f873a11ce9c6f",
)?;

let state = client.get_raw_account_state(address).await.unwrap();

println!("TRANSACTION_ID{}", &state.last_transaction_id);
let res = client
.smc_load_by_transaction(address, &internal_transaction_id)
.await;

assert!(res.is_ok());
Ok(())
}

#[tokio::test]
async fn client_smc_get_code_works() -> anyhow::Result<()> {
common::init_logging();
let client = common::new_test_client().await?;
let address = "EQDk2VTvn04SUKJrW7rXahzdF8_Qi6utb0wj43InCu9vdjrR";
let (_, id1) = client.smc_load(address).await?;
let cell = client.smc_get_code(id1).await?;
println!("\n\r\x1b[1;35m-----------------------------------------CODE-----------------------------------------\x1b[0m:\n\r {:?}",cell);
Ok(())
}

#[tokio::test]
async fn client_smc_get_data_works() -> anyhow::Result<()> {
common::init_logging();
let client = common::new_test_client().await?;
let address = "EQDk2VTvn04SUKJrW7rXahzdF8_Qi6utb0wj43InCu9vdjrR";
let (_, id1) = client.smc_load(address).await?;
let cell = client.smc_get_data(id1).await?;
println!("\n\r\x1b[1;35m-----------------------------------------DATA-----------------------------------------\x1b[0m:\n\r {:?}",cell);
Ok(())
}

#[tokio::test]
async fn client_smc_get_state_works() -> anyhow::Result<()> {
common::init_logging();
let client = common::new_test_client().await?;
let address = "EQDk2VTvn04SUKJrW7rXahzdF8_Qi6utb0wj43InCu9vdjrR";
let (_, id1) = client.smc_load(address).await?;
let cell = client.smc_get_state(id1).await?;
println!("\n\r\x1b[1;35m-----------------------------------------STATE----------------------------------------\x1b[0m:\n\r {:?}",cell);
Ok(())
}

#[tokio::test]
async fn client_get_block_header_works() -> anyhow::Result<()> {
common::init_logging();
Expand Down

0 comments on commit 91ccdae

Please sign in to comment.