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

feat: custom pool #131

Draft
wants to merge 12 commits into
base: main
Choose a base branch
from
569 changes: 208 additions & 361 deletions Cargo.lock

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ void main() {
wallet.address,
'0:ecfb1d0edbcbe0409763fa8ad8ad7f2727749f6cf29e0e6bcba9fdc752d3ae01',
);
expect(wallet.contractState.balance, Fixed.parse('100000000'));
expect(wallet.contractState.balance, Fixed.parse('61294235'));
expect(wallet.symbol.decimals, 9);
expect(wallet.symbol.rootTokenContract, stEverRootContract);
expect(wallet.symbol.name, 'STEVER');
Expand Down
2 changes: 1 addition & 1 deletion packages/flutter_nekoton_bridge/example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: ef19549a9bc3046e7bb7d2fab4d021637c0c58a3

COCOAPODS: 1.12.0
COCOAPODS: 1.12.1
3 changes: 3 additions & 0 deletions packages/flutter_nekoton_bridge/ios/Classes/frb.h
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,8 @@ void wire_init_logger(int64_t port_, int32_t level, bool mobile_logger);

void wire_create_log_stream(int64_t port_);

void wire_init_runtime(int64_t port_);

void wire_init_caller(int64_t port_);

WireSyncReturn wire_call_send_result(struct wire_uint_8_list *id, struct wire_DynamicValue *value);
Expand Down Expand Up @@ -1082,6 +1084,7 @@ static int64_t dummy_method_to_enforce_bundling(void) {
dummy_var ^= ((int64_t) (void*) wire_test_caller_call_test1_async);
dummy_var ^= ((int64_t) (void*) wire_init_logger);
dummy_var ^= ((int64_t) (void*) wire_create_log_stream);
dummy_var ^= ((int64_t) (void*) wire_init_runtime);
dummy_var ^= ((int64_t) (void*) wire_init_caller);
dummy_var ^= ((int64_t) (void*) wire_call_send_result);
dummy_var ^= ((int64_t) (void*) wire_simple_log);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ Stream<DartCallStubRegistred>? _caller;
Future<void> registerRustToDartCaller(RustToDartCaller rustToDartCaller) async {
final lib = createLib();

await lib.initRuntime();

if (_caller != null) {
final logEntry = LogEntryCreate.create(
level: LogLevel.Warn,
Expand Down
24 changes: 21 additions & 3 deletions packages/nekoton_bridge/lib/src/bridge_generated.dart
Original file line number Diff line number Diff line change
Expand Up @@ -294,9 +294,6 @@ abstract class NekotonBridge {

FlutterRustBridgeTaskConstMeta get kTestCallerCallTest1AsyncConstMeta;

///----------------------------
/// CONTENT OF src/utils/api.rs
///----------------------------
/// Init utils
Future<void> initLogger(
{required LogLevel level, required bool mobileLogger, dynamic hint});
Expand All @@ -308,6 +305,11 @@ abstract class NekotonBridge {

FlutterRustBridgeTaskConstMeta get kCreateLogStreamConstMeta;

/// Init tokio runtime
Future<void> initRuntime({dynamic hint});

FlutterRustBridgeTaskConstMeta get kInitRuntimeConstMeta;

/// Init caller
Stream<DartCallStubRegistred> initCaller({dynamic hint});

Expand Down Expand Up @@ -4031,6 +4033,22 @@ class NekotonBridgeImpl implements NekotonBridge {
argNames: [],
);

Future<void> initRuntime({dynamic hint}) {
return _platform.executeNormal(FlutterRustBridgeTask(
callFfi: (port_) => _platform.inner.wire_init_runtime(port_),
parseSuccessData: _wire2api_unit,
constMeta: kInitRuntimeConstMeta,
argValues: [],
hint: hint,
));
}

FlutterRustBridgeTaskConstMeta get kInitRuntimeConstMeta =>
const FlutterRustBridgeTaskConstMeta(
debugName: "init_runtime",
argNames: [],
);

Stream<DartCallStubRegistred> initCaller({dynamic hint}) {
return _platform.executeStream(FlutterRustBridgeTask(
callFfi: (port_) => _platform.inner.wire_init_caller(port_),
Expand Down
14 changes: 14 additions & 0 deletions packages/nekoton_bridge/lib/src/bridge_generated.io.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1753,6 +1753,20 @@ class NekotonBridgeWire implements FlutterRustBridgeWireBase {
late final _wire_create_log_stream =
_wire_create_log_streamPtr.asFunction<void Function(int)>();

void wire_init_runtime(
int port_,
) {
return _wire_init_runtime(
port_,
);
}

late final _wire_init_runtimePtr =
_lookup<ffi.NativeFunction<ffi.Void Function(ffi.Int64)>>(
'wire_init_runtime');
late final _wire_init_runtime =
_wire_init_runtimePtr.asFunction<void Function(int)>();

void wire_init_caller(
int port_,
) {
Expand Down
5 changes: 5 additions & 0 deletions packages/nekoton_bridge/lib/src/bridge_generated.web.dart
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,8 @@ class NekotonBridgeWasmModule implements WasmModule {

external dynamic /* void */ wire_create_log_stream(NativePortType port_);

external dynamic /* void */ wire_init_runtime(NativePortType port_);

external dynamic /* void */ wire_init_caller(NativePortType port_);

external dynamic /* void */ wire_call_send_result(
Expand Down Expand Up @@ -1371,6 +1373,9 @@ class NekotonBridgeWire
void wire_create_log_stream(NativePortType port_) =>
wasmModule.wire_create_log_stream(port_);

void wire_init_runtime(NativePortType port_) =>
wasmModule.wire_init_runtime(port_);

void wire_init_caller(NativePortType port_) =>
wasmModule.wire_init_caller(port_);

Expand Down
14 changes: 7 additions & 7 deletions packages/nekoton_bridge/native/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@ rerun_except = "1.0.0"
flutter_rust_bridge = "1.78.*"
lazy_static = "1.4.0"
anyhow = "1.0.54"
thiserror="1.0.39"
thiserror = "1.0.39"
async-trait = "0.1.52"
hex = "0.4.3"
parking_lot = "0.12.1"
simplelog = "0.12.0"
log = { version = "0.4.17", features = ["kv_unstable"] }
log-panics = { version = "2.1.0", features = ["with-backtrace"] }
nekoton = { git = "https://github.com/broxus/nekoton.git", tag = "v0.12.0", features = [
nekoton = { git = "https://github.com/broxus/nekoton.git", features = [
"gql_transport",
"jrpc_transport",
] }
nekoton-abi = { git = "https://github.com/broxus/nekoton.git", tag = "v0.12.0" }
nekoton-utils = { git = "https://github.com/broxus/nekoton.git", tag = "v0.12.0" }
], rev = "2adcf367ac8d2c6ab04ad35a8bc345b1f9c0d634" }
nekoton-abi = { git = "https://github.com/broxus/nekoton.git", rev = "2adcf367ac8d2c6ab04ad35a8bc345b1f9c0d634" }
nekoton-utils = { git = "https://github.com/broxus/nekoton.git", rev = "2adcf367ac8d2c6ab04ad35a8bc345b1f9c0d634" }
ton_abi = { git = "https://github.com/broxus/ton-labs-abi" }
ton_block = { git = "https://github.com/broxus/ton-labs-block.git" }
ton_types = { git = "https://github.com/broxus/ton-labs-types.git" }
Expand All @@ -44,8 +44,8 @@ tokio = { version = "1.26.0", features = ["full"] }
[dependencies.uuid]
version = "1.3.0"
features = [
"v4", # Lets you generate random UUIDs
"fast-rng", # Use a faster (but still sufficiently random) RNG
"v4", # Lets you generate random UUIDs
"fast-rng", # Use a faster (but still sufficiently random) RNG
"macro-diagnostics", # Enable better diagnostics for compile-time UUIDs
]

Expand Down
12 changes: 7 additions & 5 deletions packages/nekoton_bridge/native/build.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use std::env;
use std::fs;
use lib_flutter_rust_bridge_codegen::{
config_parse, frb_codegen, get_symbols_if_no_duplicates, RawOpts,
};
use rerun_except::rerun_except;
use std::env;
use std::fs;

const RUST_INPUT: &str = "src/merged.rs";
const DART_OUTPUT: &str = "../lib/src/bridge_generated.dart";
Expand All @@ -16,7 +16,6 @@ fn main() {
// env::set_var("RUST_LOG", "debug");
// env_logger::init();


// Tell Cargo that if the input Rust code changes, rerun this build script
rerun_except(&["**/*_api.rs"]).unwrap();

Expand Down Expand Up @@ -49,8 +48,11 @@ fn main() {
fs::copy(IOS_C_OUTPUT, MACOS_C_OUTPUT).expect("Can't copy frb.h from ios to macos build dir");

// Format the generated Dart code
_ = std::process::Command::new("flutter")
std::process::Command::new("dart")
.arg("format")
.arg("../lib")
.spawn();
.spawn()
.unwrap()
.wait()
.unwrap();
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ impl ToSerializable<SignedMessage> for crypto::SignedMessage {
.write_to_new_cell()
.handle_error()
.unwrap()
.into();
.into_cell()
.expect("failed to create cell from builder");

let hash = cell.repr_hash();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use std::borrow::Cow;
use std::collections::HashMap;
use std::time::{SystemTime, UNIX_EPOCH};
use ton_block::{Deserializable, Serializable};
use ton_types::SliceData;

/// Check if public key is correct.
/// If no - throws error, if ok - return true
Expand Down Expand Up @@ -98,9 +99,14 @@ pub fn get_expected_address(

state_init.data = if let Some(data) = state_init.data.take() {
Some(
insert_state_init_data(&contract_abi, data.into(), &public_key, init_data)
.handle_error()?
.into_cell(),
insert_state_init_data(
&contract_abi,
SliceData::load_cell(data).expect("Can't load cell"),
&public_key,
init_data,
)
.handle_error()?
.into_cell(),
)
} else {
None
Expand Down Expand Up @@ -189,7 +195,7 @@ pub fn create_external_message_without_signature(
message.set_state_init(state_init);
}

message.set_body(body.into());
message.set_body(SliceData::load_builder(body)?);

let signed_message = SignedMessage {
message,
Expand Down Expand Up @@ -354,7 +360,7 @@ pub fn decode_transaction(
let internal = transaction.in_msg.src.is_some();

let in_msg_body = match transaction.in_msg.body {
Some(body) => body.data.into(),
Some(body) => SliceData::load_cell(body.data)?,
None => return Ok(serde_json::Value::Null.to_string()),
};

Expand All @@ -377,7 +383,7 @@ pub fn decode_transaction(
};

Some(match e.body.to_owned() {
Some(body) => Ok(body.data.into()),
Some(body) => Ok(SliceData::load_cell(body.data).ok()?),
None => Err("Expected message body").handle_error(),
})
})
Expand Down Expand Up @@ -412,7 +418,7 @@ pub fn decode_transaction_events(
};

Some(match e.body.to_owned() {
Some(body) => Ok(body.data.into()),
Some(body) => Ok(SliceData::load_cell(body.data).ok()?),
None => Err("Expected message body").handle_error(),
})
})
Expand Down Expand Up @@ -478,9 +484,9 @@ pub fn unpack_from_cell(
let cell = ton_types::deserialize_tree_of_cells(&mut body.as_slice()).handle_error()?;
let version = ton_abi::contract::AbiVersion { major: 2, minor: 2 };

let tokens = nekoton_abi::unpack_from_cell(&params, cell.into(), allow_partial, version)
.handle_error()
.and_then(|e| nekoton_abi::make_abi_tokens(&e).handle_error())?;
let tokens =
nekoton_abi::unpack_from_cell(&params, SliceData::load_cell(cell)?, allow_partial, version)
.and_then(|e| nekoton_abi::make_abi_tokens(&e))?;

serde_json::to_string(&tokens).handle_error()
}
Expand Down
21 changes: 11 additions & 10 deletions packages/nekoton_bridge/native/src/nekoton_wrapper/helpers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::nekoton_wrapper::HandleError;
use nekoton_abi::MethodName;
use std::str::FromStr;
use ton_block::{Deserializable, MaybeDeserialize};
use ton_types::SliceData;

pub mod abi_api;
pub mod models;
Expand All @@ -24,16 +25,16 @@ pub fn parse_account_stuff(boc: String) -> anyhow::Result<ton_block::AccountStuf
let bytes = base64::decode(boc).handle_error()?;
ton_types::deserialize_tree_of_cells(&mut bytes.as_slice())
.and_then(|cell| {
let slice = &mut cell.into();
let mut slice = SliceData::load_cell(cell)?;
Ok(ton_block::AccountStuff {
addr: Deserializable::construct_from(slice)?,
storage_stat: Deserializable::construct_from(slice)?,
addr: Deserializable::construct_from(&mut slice)?,
storage_stat: Deserializable::construct_from(&mut slice)?,
storage: ton_block::AccountStorage {
last_trans_lt: Deserializable::construct_from(slice)?,
balance: Deserializable::construct_from(slice)?,
state: Deserializable::construct_from(slice)?,
last_trans_lt: Deserializable::construct_from(&mut slice)?,
balance: Deserializable::construct_from(&mut slice)?,
state: Deserializable::construct_from(&mut slice)?,
init_code_hash: if slice.remaining_bits() > 0 {
ton_types::UInt256::read_maybe_from(slice)?
ton_types::UInt256::read_maybe_from(&mut slice)?
} else {
None
},
Expand Down Expand Up @@ -77,9 +78,9 @@ pub fn parse_method_name(value: Option<String>) -> anyhow::Result<MethodName> {

/// Parse boc to slice and return its instance or throws error
pub fn parse_slice(boc: String) -> anyhow::Result<ton_types::SliceData> {
let body = base64::decode(boc).handle_error()?;
let cell = ton_types::deserialize_tree_of_cells(&mut body.as_slice()).handle_error()?;
Ok(cell.into())
let body = base64::decode(boc)?;
let cell = ton_types::deserialize_tree_of_cells(&mut body.as_slice())?;
SliceData::load_cell(cell)
}

/// Parse params list and returns vector of these instances or throws error
Expand Down
Loading