Skip to content

Commit

Permalink
Merge pull request #231 from tonlabs/1.1.0-rc
Browse files Browse the repository at this point in the history
Version 1.1.0
  • Loading branch information
g9d authored Nov 9, 2020
2 parents b66b0e7 + af9f1a6 commit 1b00b1a
Show file tree
Hide file tree
Showing 100 changed files with 2,950 additions and 1,765 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ target/
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
Cargo.lock

# Vim temporary files
*.swp

# These are backup files generated by rustfmt
**/*.rs.bk

Expand All @@ -29,6 +32,7 @@ Cargo.lock
/ton_client/platforms/ton-client-web/build/index.js
/ton_client/client/bin/
/ton_client/client/build/
/ton_client/client/src/build_info.json
/ton_client/platforms/ton-client-react-native/android/src/main/jniLibs/
/ton_client/platforms/ton-client-react-native/ios/libtonclient.a
/examples/c/libton_client.dylib
Expand All @@ -38,3 +42,4 @@ Cargo.lock
/tools/**/*.d.ts
/tools/**/*.tsbuildinfo
/tools/package-lock.json
/**/clion-log.txt
29 changes: 29 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,35 @@
# Release Notes
All notable changes to this project will be documented in this file.

## 1.1.0 Nov 3, 2020

### New
- ChaCha20 encryption support `crypto.chacha20`.
- `boc.parse_shardstate` function for shardstates parsing.
- `boc.get_boc_hash` function for calculating BOC root hash
- `client.build_info` fully defined and documented.
- `processing.wait_for_transaction` and `processing.process_message` functions execute contract
locally in case if transaction waiting fails in order to resolve the contract execution error
- `run_executor`, `run_tvm` now return `exit_arg` in case of TVM errors.
- Create the `build_info.json` on the build stage.
- `Abi::Contract` variant as an alias to deprecated `Abi::Serialized`
- `Abi::Json` variant to specify an ABI as a raw JSON string.
- `api.json` now contains details about numeric types: Number and BigInt are now
have new fields `number_type` and `number_size`.
- `api.json` ref type names are fully qualified now in form of `module.type`,
for example `abi.Signer`.

### Fixed
- TS generator fix some field names that is an invalid JS identifiers.
- Use `install_name_tool` to fix loading library paths at `libton_client.dylib`.
- `api.json` is reduced, so it can't contains tuple types, only structs.
All types are exactly match to JSON.
- `out_of_sync_threshold` config parameter is `u32`

### Unstable
- `tc_request_ptr` function to use pointers `void*` instead of request_id `u32`.
This feature is **UNSTABLE** yet.

## 1.0.0 Oct 27, 2020

### Differences between Core SDK v0 and v1
Expand Down
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,5 @@ members = [
exclude = [
"ton_client/platforms/ton-client-node-js",
"ton_client/platforms/ton-client-web",
"ton_client/platforms/ton-client-react-native",
"examples/rust"
]
69 changes: 60 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# TON Client Library for TON DApp development
# TONOS Client Library for TON DApp development

**Community links:**

Expand All @@ -8,9 +8,9 @@

[GraphQL API and SDK documentation](https://docs.ton.dev/86757ecb2/p/92b041-overview)

# What is TON Client Library
# What is TONOS Client Library

TON Client Library is a library written in Rust that can be dynamically linked. It provides all
TONOS Client Library is a library written in Rust that can be dynamically linked. It provides all
heavy-computation components and functions, such as TON Virtual Machine, TON Transaction
Executor, ABI-related functions, boc-related functions, crypto functions.

Expand Down Expand Up @@ -55,6 +55,57 @@ You have some options:
If you choose using JSON Interface please read this document [JSON Interface](docs/json_interface.md).
Here you can find directions how to use `json_interface` and write your own binding.

# How to avoid Soft Breaking Problems

Soft Breaking is API changes that include only new optional fields in the existing structures. This changes are fully backward compatible for JSON Interface.

But in Rust such changes can produce some problems with an old client code.

Look at the example below:

1) There is an API v1.0 function `foo` and the corresponding params structure:

```rust
#[derive(Default)]
struct ParamsOfFoo {
pub foo: String,
}

pub fn foo(params: ParamsOfFoo)
```

2) Application uses this function in this way:

```rust
foo(ParamsOfFoo {
foo: "foo".into(),
});
```

3) API v.1.1 introduces new field in `ParamsOfFoo`:

```rust
#[derive(Default)]
struct ParamsOfFoo {
pub foo: String,
pub bar: Option<String>,
}
```

From the perspective of JSON-interface it isn't breaking change because the new parameter is optional. But code snippet (2) will produce Rust compilation error.

4) To avoid such problems we recommend to use default implementation inside structure initialisation:

```rust
oo(ParamsOfFoo {
foo: "foo".into(),
..Default::default(),
});
```

For all Ton Client API structures `Default` trait is implemented.


# Bindings

Binding is a thin client library written on the specific language that acts like a bridge between
Expand Down Expand Up @@ -97,12 +148,12 @@ TON Labs SDK Binaries Store.

Platform | Major | Download links
-------- | ----- | --------------
Win32 | 0 | [`tonclient.lib`](http://sdkbinaries-ws.tonlabs.io/tonclient_0_win32_lib.gz), [`tonclient.dll`](http://sdkbinaries-ws.tonlabs.io/tonclient_0_win32_dll.gz), [`tonclient.node`](http://sdkbinaries-ws.tonlabs.io/tonclient_0_nodejs_addon_win32.gz)
&nbsp; | 1 | [`tonclient.lib`](http://sdkbinaries-ws.tonlabs.io/tonclient_1_win32_lib.gz), [`tonclient.dll`](http://sdkbinaries-ws.tonlabs.io/tonclient_1_win32_dll.gz), [`tonclient.node`](http://sdkbinaries-ws.tonlabs.io/tonclient_1_nodejs_addon_win32.gz)
macOS | 0 | [`libtonclient.dylib`](http://sdkbinaries-ws.tonlabs.io/tonclient_0_darwin.gz), [`tonclient.node`](http://sdkbinaries-ws.tonlabs.io/tonclient_0_nodejs_addon_darwin.gz), [`libtonclientnodejs.dylib`](http://sdkbinaries-ws.tonlabs.io/tonclient_0_nodejs_dylib_darwin.gz)
&nbsp; | 1 | [`libtonclient.dylib`](http://sdkbinaries-ws.tonlabs.io/tonclient_1_darwin.gz), [`tonclient.node`](http://sdkbinaries-ws.tonlabs.io/tonclient_1_nodejs_addon_darwin.gz)
Linux | 0 | [`libtonclient.so`](http://sdkbinaries-ws.tonlabs.io/tonclient_0_linux.gz), [`tonclient.node`](http://sdkbinaries-ws.tonlabs.io/tonclient_0_nodejs_addon_linux.gz)
&nbsp; | 1 | [`libtonclient.so`](http://sdkbinaries-ws.tonlabs.io/tonclient_1_linux.gz), [`tonclient.node`](http://sdkbinaries-ws.tonlabs.io/tonclient_1_nodejs_addon_linux.gz)
Win32 | 0 | [`ton_client.lib`](http://sdkbinaries-ws.tonlabs.io/tonclient_0_win32_lib.gz), [`ton_client.dll`](http://sdkbinaries-ws.tonlabs.io/tonclient_0_win32_dll.gz), [`tonclient.node`](http://sdkbinaries-ws.tonlabs.io/tonclient_0_nodejs_addon_win32.gz)
&nbsp; | 1 | [`ton_client.lib`](http://sdkbinaries-ws.tonlabs.io/tonclient_1_win32_lib.gz), [`ton_client.dll`](http://sdkbinaries-ws.tonlabs.io/tonclient_1_win32_dll.gz), [`tonclient.node`](http://sdkbinaries-ws.tonlabs.io/tonclient_1_nodejs_addon_win32.gz)
macOS | 0 | [`libton_client.dylib`](http://sdkbinaries-ws.tonlabs.io/tonclient_0_darwin.gz), [`tonclient.node`](http://sdkbinaries-ws.tonlabs.io/tonclient_0_nodejs_addon_darwin.gz), [`libtonclientnodejs.dylib`](http://sdkbinaries-ws.tonlabs.io/tonclient_0_nodejs_dylib_darwin.gz)
&nbsp; | 1 | [`libton_client.dylib`](http://sdkbinaries-ws.tonlabs.io/tonclient_1_darwin.gz), [`tonclient.node`](http://sdkbinaries-ws.tonlabs.io/tonclient_1_nodejs_addon_darwin.gz)
Linux | 0 | [`libton_client.so`](http://sdkbinaries-ws.tonlabs.io/tonclient_0_linux.gz), [`tonclient.node`](http://sdkbinaries-ws.tonlabs.io/tonclient_0_nodejs_addon_linux.gz)
&nbsp; | 1 | [`libton_client.so`](http://sdkbinaries-ws.tonlabs.io/tonclient_1_linux.gz), [`tonclient.node`](http://sdkbinaries-ws.tonlabs.io/tonclient_1_nodejs_addon_linux.gz)
WASM | 0 | [`tonclient.wasm`](http://sdkbinaries-ws.tonlabs.io/tonclient_0_wasm.gz), [`tonclient.js`](http://sdkbinaries-ws.tonlabs.io/tonclient_0_wasm_js.gz)
&nbsp; | 1 | [`tonclient.wasm`](http://sdkbinaries-ws.tonlabs.io/tonclient_1_wasm.gz), [`tonclient.js`](http://sdkbinaries-ws.tonlabs.io/tonclient_1_wasm_js.gz)
iOS | 0 | [`libtonclient.a`](http://sdkbinaries-ws.tonlabs.io/tonclient_0_react_native_ios.gz)
Expand Down
12 changes: 12 additions & 0 deletions api/derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,15 @@ pub fn api_module(input: TokenStream) -> TokenStream {
pub fn api_function(attr: TokenStream, input: TokenStream) -> TokenStream {
crate::api_function::impl_api_function(attr, input)
}

#[macro_use]
extern crate quote;

#[proc_macro]
pub fn include_build_info(_input: TokenStream) -> TokenStream {
let content = match std::fs::read_to_string(std::env::current_dir().unwrap().join("ton_client/client/src/build_info.json")) {
Err(_e) => return quote!("").into(),
Ok(content) => content,
};
return quote!(#content).into();
}
99 changes: 71 additions & 28 deletions api/derive/src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use api_info;
use api_info::NumberType;
use quote::__private::TokenStream;
use quote::quote;
use syn::{
Expand All @@ -19,8 +20,13 @@ pub(crate) fn field_from(
} else {
value
};
let name = if let Some(name) = find_attr_value("serde", "rename", attrs) {
name
} else {
name.map(|x| x.to_string()).unwrap_or("".into())
};
api_info::Field {
name: name.map(|x| x.to_string()).unwrap_or("".into()),
name,
summary,
description,
value,
Expand Down Expand Up @@ -130,13 +136,33 @@ pub(crate) fn function_to_tokens(m: &api_info::Function) -> TokenStream {
}
}

fn number_type_to_tokens(number_type: &NumberType) -> TokenStream {
match number_type {
NumberType::UInt => quote! { api_info::NumberType::UInt },
NumberType::Int => quote! { api_info::NumberType::Int },
NumberType::Float => quote! { api_info::NumberType::Float },
}
}

fn type_to_tokens(t: &api_info::Type) -> TokenStream {
match t {
api_info::Type::None {} => quote! { api_info::Type::None {} },
api_info::Type::Any {} => quote! { api_info::Type::Any {} },
api_info::Type::Boolean {} => quote! { api_info::Type::Boolean {} },
api_info::Type::Number {} => quote! { api_info::Type::Number {} },
api_info::Type::BigInt {} => quote! { api_info::Type::BigInt {} },
api_info::Type::Number {
number_type,
number_size: size,
} => {
let number_type_tokens = number_type_to_tokens(number_type);
quote! { api_info::Type::Number { number_type: #number_type_tokens, number_size: #size } }
}
api_info::Type::BigInt {
number_type,
number_size: size,
} => {
let number_type_tokens = number_type_to_tokens(number_type);
quote! { api_info::Type::BigInt { number_type: #number_type_tokens, number_size: #size } }
}
api_info::Type::String {} => quote! { api_info::Type::String {} },
api_info::Type::Ref { name } => {
quote! { api_info::Type::Ref { name: #name.into() } }
Expand Down Expand Up @@ -225,10 +251,18 @@ fn resolve_type_name(name: String) -> api_info::Type {
match name.as_ref() {
"String" => api_info::Type::String {},
"bool" => api_info::Type::Boolean {},
"u8" | "u16" | "u32" | "i8" | "i16" | "i32" | "usize" | "isize" | "f32" => {
api_info::Type::Number {}
}
"u64" | "i64" | "u128" | "i128" => api_info::Type::BigInt {},
"u8" => api_info::Type::u(8),
"u16" => api_info::Type::u(16),
"u32" => api_info::Type::u(32),
"u64" => api_info::Type::u(64),
"u128" => api_info::Type::u(128),
"i8" => api_info::Type::i(8),
"i16" => api_info::Type::i(16),
"i32" => api_info::Type::i(32),
"i64" => api_info::Type::i(64),
"i128" => api_info::Type::i(128),
"f32" => api_info::Type::f(32),
"usize" | "isize" => panic!("usize and isize can't be used in API"),
_ => api_info::Type::Ref { name },
}
}
Expand Down Expand Up @@ -324,44 +358,53 @@ impl DocAttr {
}
}

pub(crate) fn find_attr_value(
fn find_attr_value_meta(
attr_name: &'static str,
value_name: &'static str,
attrs: &Vec<Attribute>,
) -> Option<String> {
) -> Option<Meta> {
for attr in attrs {
if let Ok(Meta::List(ref list)) = attr.parse_meta() {
if let Ok(Meta::List(list)) = attr.parse_meta() {
if path_is(&list.path, attr_name) {
if let Some(NestedMeta::Meta(Meta::NameValue(meta))) = list.nested.first() {
return get_value_of(value_name, &meta);
for item in list.nested {
if let NestedMeta::Meta(meta) = item {
let value_path = match &meta {
Meta::NameValue(name_value) => Some(&name_value.path),
Meta::Path(path) => Some(path),
_ => None,
};
if let Some(path) = value_path {
if path_is(path, value_name) {
return Some(meta);
}
}
}
}
}
}
}
None
}

pub(crate) fn has_attr_value(
pub(crate) fn find_attr_value(
attr_name: &'static str,
value_name: &'static str,
attrs: &Vec<Attribute>,
) -> bool {
for attr in attrs {
if let Ok(Meta::List(ref list)) = attr.parse_meta() {
if path_is(&list.path, attr_name) {
match list.nested.first() {
Some(NestedMeta::Meta(Meta::NameValue(meta))) => {
return path_is(&meta.path, value_name);
}
Some(NestedMeta::Meta(Meta::Path(path))) => {
return path_is(&path, value_name);
}
_ => {}
}
}
) -> Option<String> {
if let Some(Meta::NameValue(name_value)) = find_attr_value_meta(attr_name, value_name, attrs) {
if let Lit::Str(lit) = &name_value.lit {
return Some(lit.value());
}
}
false
None
}

pub(crate) fn has_attr_value(
attr_name: &'static str,
value_name: &'static str,
attrs: &Vec<Attribute>,
) -> bool {
find_attr_value_meta(attr_name, value_name, attrs).is_some()
}

pub(crate) fn get_value_of(name: &'static str, meta: &MetaNameValue) -> Option<String> {
Expand Down
Loading

0 comments on commit 1b00b1a

Please sign in to comment.