Skip to content

Commit 0a8a309

Browse files
authored
Merge pull request #144 from tonlabs/0.25.0-rc
0.25.0 rc
2 parents b1dbf1c + 6863b92 commit 0a8a309

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1924
-1451
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,6 @@ Cargo.lock
1818
.idea
1919
.vscode
2020
.DS_Store
21+
/ton_client/platforms/ton-client-react-native/build/
22+
/ton_client/platforms/ton-client-web/build/tonclient.wasm
23+
/ton_client/platforms/ton-client-web/build/index.js

CHANGELOG.md

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
# Release Notes
22
All notable changes to this project will be documented in this file.
33

4-
## Jun 05, 2020
5-
### New
6-
- time sync check while initializing
7-
8-
## Jun 03, 2020
4+
## 0.25.0 Jul 8, 2020
95
### New
6+
- supports for core context in all platforms
107
- local run functions return updated contract state when running with `full_run = true`
8+
- time sync check while initializing
9+
- parallel requests on different contexts don't block each other. Requests on the same context
10+
remain sequential
11+
- new transaction wait mechanism. All account's shard blocks are checked for transaction to
12+
guarantee message expiration
13+
- `contracts.wait.transaction` function for awaiting previously sent message processing
14+
- `contracts.send.message` returns message processing state for `contracts.wait.transaction` function
15+
- `contracts.find.shard` function for account shard matching
16+
- added logging on warning messages
1117

1218
## May 28, 2020
1319
### New

graphite/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ websocket = "0.22.4"
1212
serde_json = "1.0.41"
1313
futures = "0.3.4"
1414
reqwest = "0.10.4"
15+
failure = "0.1"

graphite/src/client.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ impl GqlClient {
2828
pub fn new(queries_server: &str, subscriptions_server: &str) -> Result<Self, GraphiteError> {
2929
let client = ClientBuilder::new()
3030
.build()
31-
.map_err(|err| GraphiteError::new(err.to_string()))?;
31+
.map_err(|err| GraphiteError::NetworkError(
32+
format!("Can not create client: {}", err.to_string())))?;
3233

3334
Ok(Self {
3435
client_htpp: client,
@@ -41,17 +42,18 @@ impl GqlClient {
4142
async fn process_response(response: Response) -> Result<serde_json::Value, GraphiteError> {
4243
match response.text().await {
4344
Ok(res_str) => {
44-
if let Ok(value) = serde_json::from_str(res_str.as_str()) {
45+
match serde_json::from_str(res_str.as_str()) {
46+
Ok(value) => {
4547
if let Some(error) = crate::types::try_extract_error(&value) {
4648
return Err(error);
4749
}
4850
Ok(value)
49-
} else {
50-
Err(GraphiteError::new(format!(
51-
"Invalid JSON: {}", res_str)))
51+
},
52+
Err(error) => Err(GraphiteError::SerdeError(error, res_str))
5253
}
5354
},
54-
Err(err) => Err(GraphiteError::new(err.to_string().clone()))
55+
Err(err) => Err(GraphiteError::NetworkError(
56+
format!("Can not get response text: {}", err.to_string())))
5557
}
5658
}
5759

@@ -61,7 +63,7 @@ impl GqlClient {
6163
.send()
6264
.await
6365
.map_err(|err|
64-
GraphiteError::new(format!("Can't send request: {}", err)))?;
66+
GraphiteError::NetworkError(format!("Can't send request: {}", err)))?;
6567

6668
Self::process_response(response).await
6769
}
@@ -81,7 +83,7 @@ impl GqlClient {
8183
.send()
8284
.await
8385
.map_err(|err|
84-
GraphiteError::new(format!("Can't send request: {}", err)))?;
86+
GraphiteError::NetworkError(format!("Can't send request: {}", err)))?;
8587

8688
Self::process_response(response).await
8789
}
@@ -90,7 +92,7 @@ impl GqlClient {
9092
Ok(SubscribeStream::new(
9193
std::time::SystemTime::now()
9294
.duration_since(std::time::UNIX_EPOCH)
93-
.map_err(|err| GraphiteError::new(format!("Cannot get time: {}", err)))?
95+
.map_err(|err| GraphiteError::Other(format!("Cannot get time: {}", err)))?
9496
.subsec_nanos(),
9597
request,
9698
&self.graphql_socket_host)?)

graphite/src/types.rs

Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -16,31 +16,27 @@ extern crate websocket;
1616

1717
use futures::task::{Poll, Context};
1818
use futures::stream::Stream;
19-
use std::fmt;
2019
use serde_json::Value;
2120
use websocket::{ClientBuilder, OwnedMessage};
2221
use websocket::client::sync::Client;
2322
use websocket::stream::sync::NetworkStream;
2423

2524

26-
#[derive(Debug, Clone)]
27-
pub struct GraphiteError {
28-
message: String,
29-
}
25+
#[derive(Debug, failure::Fail)]
26+
pub enum GraphiteError {
3027

31-
impl GraphiteError {
32-
pub fn new(message: String) -> Self {
33-
Self { message: message }
34-
}
35-
}
28+
#[fail(display = "Network error: {}", 0)]
29+
NetworkError(String),
3630

37-
impl fmt::Display for GraphiteError {
38-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
39-
write!(f, "({})", self.message)
40-
}
41-
}
31+
#[fail(display = "Grpahql server returned error: {}", 0)]
32+
GraprhqlError(String),
4233

43-
impl std::error::Error for GraphiteError {}
34+
#[fail(display = "Server response parse error: {}\nresponse: {}", 0, 1)]
35+
SerdeError(serde_json::Error, String),
36+
37+
#[fail(display = "{}", 0)]
38+
Other(String)
39+
}
4440

4541
pub struct VariableRequest {
4642
query: String,
@@ -73,12 +69,12 @@ impl SubscribeStream {
7369
pub fn new(id: u32, request: VariableRequest, host:&str) -> Result<Self, GraphiteError> {
7470
let client = ClientBuilder::new(host)
7571
.map_err(|err|
76-
GraphiteError::new(
72+
GraphiteError::NetworkError(
7773
format!("Can't create websocket client with address {}. Error {}", host, err)))?
7874
.add_protocol("graphql-ws")
7975
.connect(None)
8076
.map_err(|err|
81-
GraphiteError::new(
77+
GraphiteError::NetworkError(
8278
format!("Can't connect to websocket server {}. Error {}", host, err)))?;
8379

8480
let mut future = Self {
@@ -105,7 +101,7 @@ impl SubscribeStream {
105101
let msg = OwnedMessage::Text(request);
106102
self.client.send_message(&msg)
107103
.map_err(|err|
108-
GraphiteError::new(
104+
GraphiteError::NetworkError(
109105
format!("Sending message across stdin channel failed. Error: {}", err)))?;
110106

111107
Ok(())
@@ -116,7 +112,7 @@ impl SubscribeStream {
116112
let msg = OwnedMessage::Text(query.to_string());
117113
self.client.send_message(&msg)
118114
.map_err(|err|
119-
GraphiteError::new(
115+
GraphiteError::NetworkError(
120116
format!("Sending message across stdin channel failed. Error: {}", err)))?;
121117

122118
Ok(())
@@ -146,7 +142,7 @@ pub fn try_extract_error(value: &Value) -> Option<GraphiteError> {
146142
if let Some(error) = errors.get(0) {
147143
if let Some(message) = error.get("message") {
148144
if let Some(string) = message.as_str() {
149-
return Some(GraphiteError::new(string.to_string()))
145+
return Some(GraphiteError::GraprhqlError(string.to_string()))
150146
}
151147
}
152148
}
@@ -166,21 +162,27 @@ impl Stream for SubscribeStream {
166162
Ok(message) => {
167163
match message {
168164
OwnedMessage::Text(text) => {
169-
if let Ok(value) = serde_json::from_str(text.as_str()) {
170-
if let Some(error) = try_extract_error(&value) {
171-
return Poll::Ready(Some(Err(error)));
165+
match serde_json::from_str(text.as_str()) {
166+
Ok(value) => {
167+
if let Some(error) = try_extract_error(&value) {
168+
return Poll::Ready(Some(Err(error)));
169+
}
170+
Poll::Ready(Some(Ok(value)))
172171
}
173-
Poll::Ready(Some(Ok(value)))
174-
} else {
175-
Poll::Ready(Some(Err(GraphiteError::new(format!(
176-
"Invalid JSON: {}", text)))))
172+
Err(error) => {
173+
Poll::Ready(Some(Err(GraphiteError::SerdeError(error, text))))
174+
}
175+
177176
}
178177
},
179178
_ => Poll::Pending
180179
}
181-
182-
} ,
183-
Err(err) => Poll::Ready(Some(Err(GraphiteError::new(err.to_string())))),
180+
},
181+
Err(err) => Poll::Ready(
182+
Some(
183+
Err(
184+
GraphiteError::NetworkError(
185+
format!("Can not recieve next message: {}", err.to_string()))))),
184186
}
185187
} else {
186188
Poll::Pending

ton_client/client/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "ton_client"
3-
version = "0.24.0"
3+
version = "0.25.0"
44
authors = ["Michael Vlasov"]
55
edition = "2018"
66
license = "Apache-2.0"
@@ -23,7 +23,7 @@ sha2 = "0.8"
2323
base64 = "0.10.0"
2424
lazy_static = "1.1.0"
2525
num-bigint = "0.2.2"
26-
sodalite = { version = "0.3.0", features = ["rand"] }
26+
sodalite = { git = "https://github.com/tonlabs/sodalite.git", features = ["rand"] }
2727
chrono = "0.4.6"
2828
scrypt = { version = "0.2.0", default-features = false }
2929
bip39 = { git = "https://github.com/tonlabs/bip39-rs.git" }
@@ -32,7 +32,7 @@ base58 = "0.1.0"
3232
pbkdf2 = { version = "0.3.0", default-features = false, features = [] }
3333
byteorder = "1.3.2"
3434
libsecp256k1 = "0.2.2"
35-
log = "0.4.6"
35+
log = "0.4.11"
3636
crc-any = "2.2.3"
3737
failure = "0.1"
3838
num-traits = "0.2"

ton_client/client/src/client.rs

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use crate::dispatch::DispatchTable;
1515
use crate::types::{ApiResult, ApiError};
1616
use super::{JsonResponse, InteropContext};
1717
use std::collections::HashMap;
18-
use std::sync::{Mutex, MutexGuard};
18+
use std::sync::{Arc, Mutex, MutexGuard};
1919
use ton_sdk::NodeClient;
2020

2121
#[cfg(feature = "node_interaction")]
@@ -50,7 +50,7 @@ pub(crate) struct ClientContext {
5050
pub client: Option<NodeClient>,
5151
#[cfg(feature = "node_interaction")]
5252
pub runtime: Option<Runtime>,
53-
pub handle: u32
53+
pub handle: InteropContext
5454
}
5555

5656
impl ClientContext {
@@ -66,7 +66,7 @@ impl ClientContext {
6666

6767
pub(crate) struct Client {
6868
next_context_handle: InteropContext,
69-
contexts: HashMap<InteropContext, ClientContext>,
69+
contexts: HashMap<InteropContext, Arc<Mutex<ClientContext>>>,
7070
}
7171

7272

@@ -93,39 +93,42 @@ impl Client {
9393
self.next_context_handle = handle.wrapping_add(1);
9494

9595
#[cfg(feature = "node_interaction")]
96-
self.contexts.insert(handle, ClientContext {
96+
self.contexts.insert(handle, Arc::new(Mutex::new(ClientContext {
9797
handle,
9898
client: None,
9999
runtime: None,
100-
});
100+
})));
101101

102102
#[cfg(not(feature = "node_interaction"))]
103-
self.contexts.insert(handle, ClientContext {
103+
self.contexts.insert(handle, Arc::new(Mutex::new(ClientContext {
104104
handle,
105105
client: None,
106-
});
106+
})));
107107

108108
handle
109109
}
110110

111111
pub fn destroy_context(&mut self, handle: InteropContext) {
112-
self.required_context(handle).unwrap();
113-
if self.contexts.len() == 1 {
114-
self.json_sync_request(handle, "uninit".to_owned(), "{}".to_owned());
112+
if let Ok(context) = self.required_context(handle) {
113+
let mut context = context.lock().unwrap();
114+
sync_request(&mut context, "uninit".to_owned(), "{}".to_owned());
115115
}
116116
self.contexts.remove(&handle);
117117
}
118118

119-
pub fn required_context(&mut self, context: InteropContext) -> ApiResult<&mut ClientContext> {
120-
self.contexts.get_mut(&context).ok_or(
121-
ApiError::invalid_context_handle(context)
122-
)
119+
pub fn required_context(&mut self, context: InteropContext) -> ApiResult<Arc<Mutex<ClientContext>>> {
120+
Ok(Arc::clone(self.contexts.get_mut(&context)
121+
.ok_or(ApiError::invalid_context_handle(context))?))
123122
}
124123

125-
pub fn json_sync_request(&mut self, context: InteropContext, method_name: String, params_json: String) -> JsonResponse {
126-
let context = self.required_context(context);
124+
pub fn json_sync_request(handle: InteropContext, method_name: String, params_json: String) -> JsonResponse {
125+
let context = Self::shared().required_context(handle);
127126
match context {
128-
Ok(context) => sync_request(context, method_name, params_json),
127+
Ok(context) => {
128+
let mut context = context.lock().unwrap();
129+
let result = sync_request(&mut context, method_name, params_json);
130+
result
131+
}
129132
Err(err) => JsonResponse::from_error(err)
130133
}
131134
}

0 commit comments

Comments
 (0)