Skip to content

Commit

Permalink
Merge pull request #675 from tonlabs/1.32.0-rc
Browse files Browse the repository at this point in the history
Version 1.32.0
  • Loading branch information
d3p authored Mar 30, 2022
2 parents 7b70f3d + 6fc4202 commit c731155
Show file tree
Hide file tree
Showing 24 changed files with 813 additions and 105 deletions.
124 changes: 69 additions & 55 deletions CHANGELOG.md

Large diffs are not rendered by default.

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.31.0'
version = '1.32.0'

[dependencies]
quote = '1.0'
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.31.0'
version = '1.32.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.31.0'
version = '1.32.0'

[dependencies]
serde = '1.0.115'
Expand Down
20 changes: 20 additions & 0 deletions docs/reference/types-and-methods/mod_client.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ Provides information about library.

[NetworkConfig](#networkconfig)

[NetworkQueriesProtocol](#networkqueriesprotocol) – Network protocol used to perform GraphQL queries.

[CryptoConfig](#cryptoconfig) – Crypto config.

[AbiConfig](#abiconfig)
Expand Down Expand Up @@ -248,6 +250,7 @@ type NetworkConfig = {
latency_detection_interval?: number,
max_latency?: number,
query_timeout?: number,
queries_protocol?: NetworkQueriesProtocol,
access_key?: string
}
```
Expand Down Expand Up @@ -275,10 +278,27 @@ type NetworkConfig = {
<br>Must be specified in milliseconds. Default is 60000 (1 min).
- `query_timeout`?: _number_ – Default timeout for http requests.
<br>Is is used when no timeout specified for the request to limit the answer waiting time. If no answer received during the timeout requests ends with<br>error.<br><br>Must be specified in milliseconds. Default is 60000 (1 min).
- `queries_protocol`?: _[NetworkQueriesProtocol](mod_client.md#networkqueriesprotocol)_ – Queries protocol.
<br>`HTTP` or `WS`. <br>Default is `HTTP`.
- `access_key`?: _string_ – Access key to GraphQL API.
<br>At the moment is not used in production.
## NetworkQueriesProtocol
Network protocol used to perform GraphQL queries.
```ts
enum NetworkQueriesProtocol {
HTTP = "HTTP",
WS = "WS"
}
```
One of the following value:

- `HTTP = "HTTP"` – Each GraphQL query uses separate HTTP request.
- `WS = "WS"` – All GraphQL queries will be served using single web socket connection.


## CryptoConfig
Crypto config.

Expand Down
4 changes: 2 additions & 2 deletions ton_client/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = 'ton_client'
version = '1.31.0'
version = '1.32.0'
authors = [ 'TON Labs LTD <[email protected]>' ]
edition = '2018'
license = 'Apache-2.0'
Expand All @@ -23,7 +23,7 @@ ton_sdk = { default-features = false, path = '../ton_sdk' }
ton_abi = { git = 'https://github.com/tonlabs/ton-labs-abi.git', tag = '2.1.14' }
ton_block = { git = 'https://github.com/tonlabs/ton-labs-block.git', tag = '1.7.39' }
ton_block_json = { git = 'https://github.com/tonlabs/ton-labs-block-json.git', tag = '0.7.5' }
ton_executor = { default-features = false, git = 'https://github.com/tonlabs/ton-labs-executor.git', tag = '1.15.56' }
ton_executor = { default-features = false, git = 'https://github.com/tonlabs/ton-labs-executor.git', tag = '1.15.57' }
ton_types = { git = 'https://github.com/tonlabs/ton-labs-types.git', tag = '1.10.12' }
ton_vm = { default-features = false, git = 'https://github.com/tonlabs/ton-labs-vm.git', tag = '1.8.32' }

Expand Down
17 changes: 17 additions & 0 deletions ton_client/src/debot/calltype.rs
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,7 @@ fn build_onerror_body(onerror_id: u32, e: ClientError) -> ClientResult<SliceData
.data
.pointer("/local_error/data/exit_code")
.or(e.data.pointer("/exit_code"))
.or(e.data.pointer("/compute/exit_code"))
.and_then(|val| val.as_i64())
.unwrap_or(0);
new_body.append_u32(error_code as u32).map_err(msg_err)?;
Expand Down Expand Up @@ -517,6 +518,22 @@ async fn emulate_transaction(
},
)
.await?;

let exit_code = result
.transaction
.pointer("/compute/exit_code")
.and_then(|val| val.as_i64())
.unwrap_or(0);

if exit_code != 0 {
let err = ClientError{
code: 0,
message: String::from(""),
data: result.transaction,
};
return Err(err);
}

let mut out = vec![];
for out_msg in result.out_messages {
let parsed = parse_message(client.clone(), ParamsOfParse { boc: out_msg })
Expand Down
18 changes: 18 additions & 0 deletions ton_client/src/debot/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1476,6 +1476,24 @@ async fn test_debot_query_query() {
).await;
}

#[tokio::test(core_threads = 2)]
async fn test_debot_transaction_result() {
let client = std::sync::Arc::new(TestClient::new());
let DebotData { debot_addr, target_addr: _, keys, abi } = init_simple_debot(client.clone(), "testDebot19").await;
TestBrowser::execute_with_details(
client.clone(),
debot_addr.clone(),
keys,
vec![],
vec![],
build_info(abi, 19, vec![
format!("0x475a5d1729acee4601c2a8cb67240e4da5316cc90a116e1b181d905e79401c51"),
format!("0xc13024e101c95e71afb1f5fa6d72f633d51e721de0320d73dfd6121a54e4d40a"),
]),
vec![],
).await;
}

fn build_info(abi: String, n: u32, interfaces: Vec<String>) -> DebotInfo {
let name = format!("TestDeBot{}", n);
DebotInfo {
Expand Down
1 change: 1 addition & 0 deletions ton_client/src/json_interface/modules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ fn register_client(handlers: &mut RuntimeHandlers) {
module.register_type::<crate::error::ClientError>();
module.register_type::<crate::client::ClientConfig>();
module.register_type::<crate::net::NetworkConfig>();
module.register_type::<crate::net::NetworkQueriesProtocol>();
module.register_type::<crate::crypto::CryptoConfig>();
module.register_type::<crate::abi::AbiConfig>();
module.register_type::<crate::boc::BocConfig>();
Expand Down
4 changes: 2 additions & 2 deletions ton_client/src/net/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ pub use transaction_tree::{
ResultOfQueryTransactionTree, TransactionNode,
};
pub use types::{
NetworkConfig, ACCOUNTS_COLLECTION, BLOCKS_COLLECTION, MESSAGES_COLLECTION,
TRANSACTIONS_COLLECTION,
NetworkConfig, NetworkQueriesProtocol, ACCOUNTS_COLLECTION, BLOCKS_COLLECTION,
MESSAGES_COLLECTION, TRANSACTIONS_COLLECTION,
};

use crate::client::ClientContext;
Expand Down
75 changes: 66 additions & 9 deletions ton_client/src/net/server_link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use crate::client::{ClientEnv, FetchMethod};
use crate::error::{AddNetworkUrl, ClientError, ClientResult};
use crate::net::endpoint::Endpoint;
use crate::net::ton_gql::GraphQLQuery;
use crate::net::types::NetworkQueriesProtocol;
use crate::net::websocket_link::WebsocketLink;
use crate::net::{
Error, GraphQLQueryEvent, NetworkConfig, ParamsOfAggregateCollection, ParamsOfQueryCollection,
Expand Down Expand Up @@ -88,7 +89,12 @@ pub(crate) struct NetworkState {
time_checked: AtomicBool,
}

async fn query_by_url(client_env: &ClientEnv, address: &str, query: &str, timeout: u32) -> ClientResult<Value> {
async fn query_by_url(
client_env: &ClientEnv,
address: &str,
query: &str,
timeout: u32,
) -> ClientResult<Value> {
let response = client_env
.fetch(
&format!("{}?query={}", address, query),
Expand Down Expand Up @@ -340,22 +346,35 @@ pub(crate) struct ServerLink {
}

fn strip_endpoint(endpoint: &str) -> &str {
endpoint.trim_start_matches("https://").trim_start_matches("http://").trim_end_matches("/").trim_end_matches("\\")
endpoint
.trim_start_matches("https://")
.trim_start_matches("http://")
.trim_end_matches("/")
.trim_end_matches("\\")
}

fn replace_endpoints(mut endpoints: Vec<String>) -> Vec<String> {
for entry in &ENDPOINTS_REPLACE {
let len = endpoints.len();
endpoints.retain(|endpoint| strip_endpoint(&endpoint) != entry.url);
if len != endpoints.len() {
endpoints.extend_from_slice(&entry.aliases.iter().map(|val| (*val).to_owned()).collect::<Vec<String>>());
endpoints.extend_from_slice(
&entry
.aliases
.iter()
.map(|val| (*val).to_owned())
.collect::<Vec<String>>(),
);
}
}

let mut result: Vec<String> = vec![];

for endpoint in endpoints {
if !result.iter().any(|val| strip_endpoint(val) == strip_endpoint(&endpoint)) {
if !result
.iter()
.any(|val| strip_endpoint(val) == strip_endpoint(&endpoint))
{
result.push(endpoint);
}
}
Expand Down Expand Up @@ -410,7 +429,9 @@ impl ServerLink {
) -> ClientResult<Subscription> {
let event_receiver = self
.websocket_link
.start_operation(GraphQLQuery::with_collection_subscription(table, filter, fields))
.start_operation(GraphQLQuery::with_collection_subscription(
table, filter, fields,
))
.await?;

let operation_id = Arc::new(Mutex::new(0u32));
Expand Down Expand Up @@ -500,7 +521,7 @@ impl ServerLink {
return None;
}

pub(crate) async fn query(
pub(crate) async fn query_http(
&self,
query: &GraphQLQuery,
endpoint: Option<&Endpoint>,
Expand Down Expand Up @@ -544,9 +565,9 @@ impl ServerLink {
Err(err) => Err(err),
Ok(value) => match Self::try_extract_error(&value) {
Some(err) => Err(err),
None => Ok(value)
}
}
None => Ok(value),
},
},
};

if let Err(err) = &result {
Expand All @@ -565,6 +586,42 @@ impl ServerLink {
}
}

pub(crate) async fn query_ws(&self, query: &GraphQLQuery) -> ClientResult<Value> {
let mut receiver = self.websocket_link.start_operation(query.clone()).await?;
let mut id = None::<u32>;
let mut result = Ok(Value::Null);
loop {
match receiver.recv().await {
Some(GraphQLQueryEvent::Id(received_id)) => id = Some(received_id),
Some(GraphQLQueryEvent::Data(data)) => {
result = Ok(json!({ "data": data }));
break;
}
Some(GraphQLQueryEvent::Complete) => break,
Some(GraphQLQueryEvent::Error(err)) => {
result = Err(err);
break;
}
None => break,
}
}
if let Some(id) = id {
self.websocket_link.stop_operation(id).await;
}
result
}

pub(crate) async fn query(
&self,
query: &GraphQLQuery,
endpoint: Option<&Endpoint>,
) -> ClientResult<Value> {
match self.config.queries_protocol {
NetworkQueriesProtocol::HTTP => self.query_http(query, endpoint).await,
NetworkQueriesProtocol::WS => self.query_ws(query).await,
}
}

pub async fn batch_query(
&self,
params: &[ParamsOfQueryOperation],
Expand Down
41 changes: 41 additions & 0 deletions ton_client/src/net/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1283,10 +1283,51 @@ async fn low_level_subscribe() {
.get_tokens_from_giver_async(&client.giver_address().await, None)
.await;

std::thread::sleep(std::time::Duration::from_millis(1000));
assert_ne!(messages.lock().await.len(), 0);

let _: () = client
.request_async("net.unsubscribe", handle)
.await
.unwrap();
}

#[tokio::test(core_threads = 2)]
async fn query_using_ws() {
let client = TestClient::new_with_config(json!({
"network": {
"endpoints": TestClient::endpoints(),
"queries_protocol": "WS"
}
}));

let accounts: ResultOfQueryCollection = client
.request_async(
"net.query_collection",
ParamsOfQueryCollection {
collection: "accounts".to_owned(),
filter: Some(json!({})),
result: "id".to_owned(),
..Default::default()
},
)
.await
.unwrap();

assert!(accounts.result.len() > 0);
let messages: ResultOfQueryCollection = client
.request_async(
"net.query_collection",
ParamsOfQueryCollection {
collection: "messages".to_owned(),
filter: Some(json!({})),
result: "id".to_owned(),
..Default::default()
},
)
.await
.unwrap();

assert!(messages.result.len() > 0);
}

Loading

0 comments on commit c731155

Please sign in to comment.