Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Version 1.11.0 #369

Merged
merged 16 commits into from
Mar 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

All notable changes to this project will be documented in this file.

## [1.11.0] – 2021-03-05

### New
- [`utils.calc_storage_fee`](docs/mod_utils.md#calc_storage_fee) function to calculate account storage fee over a some time period.
- **Debot Module**:
- Added unstable functions to `Sdk` interface: `getAccountsDataByHash`

## [1.10.0] – 2021-03-04

### New
Expand Down
2 changes: 1 addition & 1 deletion api/derive/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "api_derive"
version = "1.10.0"
version = "1.11.0"
authors = ["TON DEV SOLUTIONS LTD <[email protected]>"]
edition = "2018"

Expand Down
2 changes: 1 addition & 1 deletion api/info/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "api_info"
version = "1.10.0"
version = "1.11.0"
authors = ["TON DEV SOLUTIONS LTD <[email protected]>"]
edition = "2018"

Expand Down
2 changes: 1 addition & 1 deletion api/test/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "api_test"
version = "1.10.0"
version = "1.11.0"
authors = ["TON DEV SOLUTIONS LTD <[email protected]>"]
edition = "2018"

Expand Down
54 changes: 54 additions & 0 deletions docs/mod_utils.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,19 @@ Misc utility Functions.
## Functions
[convert_address](#convert_address) – Converts address from any TON format to any TON format

[calc_storage_fee](#calc_storage_fee) – Calculates storage fee for an account over a specified time period

## Types
[AddressStringFormat](#AddressStringFormat)

[ParamsOfConvertAddress](#ParamsOfConvertAddress)

[ResultOfConvertAddress](#ResultOfConvertAddress)

[ParamsOfCalcStorageFee](#ParamsOfCalcStorageFee)

[ResultOfCalcStorageFee](#ResultOfCalcStorageFee)


# Functions
## convert_address
Expand Down Expand Up @@ -43,6 +49,34 @@ function convert_address(
- `address`: _string_ – Address in the specified format


## calc_storage_fee

Calculates storage fee for an account over a specified time period

```ts
type ParamsOfCalcStorageFee = {
account: string,
period: number
}

type ResultOfCalcStorageFee = {
fee: string
}

function calc_storage_fee(
params: ParamsOfCalcStorageFee,
): Promise<ResultOfCalcStorageFee>;
```
### Parameters
- `account`: _string_
- `period`: _number_


### Result

- `fee`: _string_


# Types
## AddressStringFormat
```ts
Expand Down Expand Up @@ -101,3 +135,23 @@ type ResultOfConvertAddress = {
- `address`: _string_ – Address in the specified format


## ParamsOfCalcStorageFee
```ts
type ParamsOfCalcStorageFee = {
account: string,
period: number
}
```
- `account`: _string_
- `period`: _number_


## ResultOfCalcStorageFee
```ts
type ResultOfCalcStorageFee = {
fee: string
}
```
- `fee`: _string_


2 changes: 2 additions & 0 deletions docs/modules.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ Where:

[convert_address](mod_utils.md#convert_address) – Converts address from any TON format to any TON format

[calc_storage_fee](mod_utils.md#calc_storage_fee) – Calculates storage fee for an account over a specified time period

## [tvm](mod_tvm.md)

[run_executor](mod_tvm.md#run_executor) – Emulates all the phases of contract execution locally
Expand Down
3 changes: 2 additions & 1 deletion examples/rust/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ async fn main() {
"in": [
"0:841288ed3b55d9cdafa806807f02a0ae0c169aa5edfe88a789a6482429756a94",
"0:2bb4a0e8391e7ea8877f4825064924bd41ce110fce97e939d3323999e1efbb13",
"0:5b168970a9c63dd5c42a6afbcf706ef652476bb8960a22e1d8a2ad148e60c0ea"
"0:5b168970a9c63dd5c42a6afbcf706ef652476bb8960a22e1d8a2ad148e60c0ea",
"0:b5e9240fc2d2f1ff8cbb1d1dee7fb7cae155e5f6320e585fcc685698994a19a5",
]
}
})),
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.10.0"
version = "1.11.0"
authors = ["TON DEV SOLUTIONS LTD <[email protected]>"]
edition = "2018"
license = "Apache-2.0"
Expand Down
4 changes: 3 additions & 1 deletion ton_client/src/boc/tests.rs

Large diffs are not rendered by default.

53 changes: 53 additions & 0 deletions ton_client/src/debot/sdk_interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use crate::crypto::{
ParamsOfMnemonicFromRandom, ParamsOfMnemonicVerify, ParamsOfNaclSignKeyPairFromSecret,
ParamsOfNaclBox, ParamsOfNaclBoxOpen, ParamsOfNaclBoxKeyPairFromSecret,
};
use crate::net::{query_collection, ParamsOfQueryCollection, OrderBy, SortDirection};
use crate::encoding::decode_abi_bigint;
use serde_json::Value;

Expand Down Expand Up @@ -250,6 +251,17 @@ const ABI: &str = r#"
{"name":"publicKey","type":"uint256"},
{"name":"secretKey","type":"uint256"}
]
},
{
"name": "getAccountsDataByHash",
"inputs": [
{"name":"answerId","type":"uint32"},
{"name":"codeHash","type":"uint256"},
{"name":"gt","type":"address"}
],
"outputs": [
{"components":[{"name":"id","type":"address"},{"name":"data","type":"cell"}],"name":"accounts","type":"tuple[]"}
]
},
{
"name": "constructor",
Expand Down Expand Up @@ -546,6 +558,46 @@ impl SdkInterface {
}),
))
}

async fn query_accounts(&self, args: &Value, result: &str) -> InterfaceResult {
let answer_id = decode_answer_id(args)?;
let code_hash = get_arg(args, "codeHash")?;
let gt_addr = get_arg(args, "gt")?;
let code_hash = decode_abi_bigint(&code_hash)
.map_err(|e| format!("failed to parse integer \"{}\": {}", code_hash, e))?;

let accounts = query_collection(
self.ton.clone(),
ParamsOfQueryCollection {
collection: "accounts".to_owned(),
filter: Some(json!({
"code_hash": { "eq": format!("{:x}", code_hash) },
"id": {"gt": gt_addr }
})),
result: result.to_owned(),
order: Some(vec![
OrderBy {
path: "id".to_owned(),
direction: SortDirection::ASC,
}
]),
limit: None,
},
)
.await
.map_err(|e| format!("account query failed: {}", e))?
.result;

Ok((
answer_id,
json!({ "accounts": accounts })
))
}

async fn get_accounts_data_by_hash(&self, args: &Value) -> InterfaceResult {
let res = self.query_accounts(args,"id data").await.map_err(|e| format!("query account failed: {}", e))?;
Ok(res)
}
}

#[async_trait::async_trait]
Expand Down Expand Up @@ -578,6 +630,7 @@ impl DebotInterface for SdkInterface {
"naclBox" => self.nacl_box(args),
"naclBoxOpen" => self.nacl_box_open(args),
"naclKeypairFromSecret" => self.nacl_box_keypair_from_secret_key(args),
"getAccountsDataByHash" => self.get_accounts_data_by_hash(args).await,
_ => Err(format!("function \"{}\" is not implemented", func)),
}
}
Expand Down
66 changes: 64 additions & 2 deletions ton_client/src/debot/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@

use crate::abi::{CallSet, DeploySet, ParamsOfEncodeMessage, Signer, Abi,
ParamsOfDecodeMessageBody, DecodedMessageBody, ResultOfEncodeInternalMessage, ParamsOfEncodeInternalMessage};
use crate::boc::{ParamsOfParse, ResultOfParse};
use crate::boc::{ParamsOfParse, ResultOfParse, ParamsOfGetCodeFromTvc, ResultOfGetCodeFromTvc,
ResultOfGetBocHash, ParamsOfGetBocHash};
use crate::client::ParamsOfAppRequest;
use crate::crypto::KeyPair;
use crate::encoding::decode_abi_number;
Expand All @@ -38,6 +39,7 @@ lazy_static!(
const TEST_DEBOT2: &'static str = "testDebot2";
const TEST_DEBOT3: &'static str = "testDebot3";
const TEST_DEBOT4: &'static str = "testDebot4";
const TEST_DEBOT5: &'static str = "testDebot5";
const TEST_DEBOTA: &'static str = "tda";
const TEST_DEBOTB: &'static str = "tdb";

Expand Down Expand Up @@ -616,7 +618,7 @@ async fn init_debot4(client: Arc<TestClient>) -> DebotData {
call_set: CallSet::some_with_function("constructor"),
};
let target_addr = client.encode_message(target_deploy_params.clone()).await.unwrap().address;
client.get_grams_from_giver_async(&target_addr, None).await;
client.get_tokens_from_giver_async(&target_addr, None).await;
let call_set = CallSet::some_with_function_and_input(
"constructor",
json!({
Expand Down Expand Up @@ -688,6 +690,50 @@ async fn init_debot3(client: Arc<TestClient>) -> DebotData {
}
}

async fn init_debot5(client: Arc<TestClient>, count: u32) -> String {
let debot_abi = TestClient::abi(TEST_DEBOT5, Some(2));
let debot5_tvc = TestClient::tvc(TEST_DEBOT5, Some(2));

let result: ResultOfGetCodeFromTvc = client.request_async(
"boc.get_code_from_tvc",
ParamsOfGetCodeFromTvc { tvc: debot5_tvc }
).await.unwrap();

let result: ResultOfGetBocHash = client.request_async(
"boc.get_boc_hash",
ParamsOfGetBocHash { boc: result.code }
).await.unwrap();

let call_set = CallSet::some_with_function_and_input(
"constructor",
json!({ "codeHash": format!("0x{}", result.hash) }),
);
let mut deploy_debot_params = ParamsOfEncodeMessage {
abi: debot_abi.clone(),
deploy_set: DeploySet::some_with_tvc(TestClient::tvc(TEST_DEBOT5, Some(2))),
call_set,
..Default::default()
};

let mut addrs = vec![];
for i in 0..count {
let keys = client.generate_sign_keys();
deploy_debot_params.signer = Signer::Keys { keys: keys.clone() };
let debot_addr = client.deploy_with_giver_async(deploy_debot_params.clone(), Some(1_000_000_000u64)).await;
addrs.push(debot_addr.clone());
if i == 0 {
let _ = client.net_process_function(
debot_addr.clone(),
debot_abi.clone(),
"setABI",
json!({ "dabi": hex::encode(&debot_abi.json_string().unwrap().as_bytes()) }),
Signer::Keys { keys: keys.clone() },
).await.unwrap();
}
}
addrs[0].clone()
}

async fn init_debot_pair(client: Arc<TestClient>, debot1: &str, debot2: &str) -> (String, String) {
let keys = client.generate_sign_keys();
let debot1_abi = TestClient::abi(debot1, Some(2));
Expand Down Expand Up @@ -1063,6 +1109,22 @@ async fn test_debot_invoke_msgs() {
).await;
}

#[tokio::test(core_threads = 2)]
async fn test_debot_sdk_get_accounts_by_hash() {
let client = std::sync::Arc::new(TestClient::new());
let count = 6;
let debot = init_debot5(client.clone(), count).await;

let steps = serde_json::from_value(json!([])).unwrap();
TestBrowser::execute(
client.clone(),
debot.clone(),
KeyPair::default(),
steps,
vec![ format!("{} contracts.", count) ],
).await;
}

async fn download_account(client: &Arc<TestClient>, addr: &str) -> Option<String> {
let client = client.clone();
let accounts: ResultOfQueryCollection = client.request_async(
Expand Down
4 changes: 4 additions & 0 deletions ton_client/src/json_interface/modules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,10 @@ fn register_utils(handlers: &mut RuntimeHandlers) {
crate::utils::convert_address,
crate::utils::conversion::convert_address_api,
);
module.register_async_fn(
crate::utils::calc_storage_fee,
crate::utils::calc_storage_fee::calc_storage_fee_api,
);
module.register();
}

Expand Down
10 changes: 5 additions & 5 deletions ton_client/src/net/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ async fn wait_for() {
let client = TestClient::new();

client
.get_grams_from_giver_async(&TestClient::get_giver_address(), None)
.get_tokens_from_giver_async(&TestClient::giver_address(), None)
.await;

request.await.unwrap();
Expand Down Expand Up @@ -259,7 +259,7 @@ async fn subscribe_for_transactions_with_addresses() {
).await.unwrap();

// send grams to create first transaction
client.get_grams_from_giver_async(&msg.address, None).await;
client.get_tokens_from_giver_async(&msg.address, None).await;

// give some time for subscription to receive all data
std::thread::sleep(std::time::Duration::from_millis(1000));
Expand Down Expand Up @@ -431,7 +431,7 @@ async fn subscribe_for_messages() {
.unwrap();

client
.get_grams_from_giver_async(&TestClient::get_giver_address(), None)
.get_tokens_from_giver_async(&TestClient::giver_address(), None)
.await;

assert_eq!(messages.lock().await.len(), 0);
Expand All @@ -450,7 +450,7 @@ async fn find_last_shard_block() {
.request_async(
"net.find_last_shard_block",
ParamsOfFindLastShardBlock {
address: TestClient::get_giver_address(),
address: TestClient::giver_address(),
},
)
.await
Expand Down Expand Up @@ -489,7 +489,7 @@ async fn test_wait_resume() {

let duration = tokio::spawn(async move {
client_copy
.fetch_account(&TestClient::network_giver())
.fetch_account(&TestClient::giver_address())
.await;

start.elapsed().as_millis()
Expand Down
Loading