From 820cc6776873862504bca60ce0774239f2d043d9 Mon Sep 17 00:00:00 2001 From: Maga Date: Wed, 19 Jul 2023 17:33:37 +0400 Subject: [PATCH 1/7] Fix build --- Cargo.lock | 14 +++++++------- Cargo.toml | 4 ++-- src/models.rs | 4 ++-- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b0bfcbe..e43ffc0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -519,8 +519,8 @@ checksum = "93c0d11ac30a033511ae414355d80f70d9f29a44a49140face477117a1ee90db" [[package]] name = "nekoton" -version = "0.13.0" -source = "git+https://github.com/broxus/nekoton.git?branch=feat/extend-models#5080890a11a059614e8b1ee3cc782704e327a763" +version = "0.13.1" +source = "git+https://github.com/broxus/nekoton.git?branch=master#8fed4c0ecf949d97814a4794574bd4ede9dad3bf" dependencies = [ "anyhow", "async-trait", @@ -564,7 +564,7 @@ dependencies = [ [[package]] name = "nekoton-abi" version = "0.13.0" -source = "git+https://github.com/broxus/nekoton.git?branch=feat/extend-models#5080890a11a059614e8b1ee3cc782704e327a763" +source = "git+https://github.com/broxus/nekoton.git?branch=master#8fed4c0ecf949d97814a4794574bd4ede9dad3bf" dependencies = [ "anyhow", "base64", @@ -591,7 +591,7 @@ dependencies = [ [[package]] name = "nekoton-contracts" version = "0.13.0" -source = "git+https://github.com/broxus/nekoton.git?branch=feat/extend-models#5080890a11a059614e8b1ee3cc782704e327a763" +source = "git+https://github.com/broxus/nekoton.git?branch=master#8fed4c0ecf949d97814a4794574bd4ede9dad3bf" dependencies = [ "anyhow", "nekoton-abi", @@ -605,7 +605,7 @@ dependencies = [ [[package]] name = "nekoton-derive" version = "0.13.0" -source = "git+https://github.com/broxus/nekoton.git?branch=feat/extend-models#5080890a11a059614e8b1ee3cc782704e327a763" +source = "git+https://github.com/broxus/nekoton.git?branch=master#8fed4c0ecf949d97814a4794574bd4ede9dad3bf" dependencies = [ "either", "proc-macro2", @@ -616,7 +616,7 @@ dependencies = [ [[package]] name = "nekoton-utils" version = "0.13.0" -source = "git+https://github.com/broxus/nekoton.git?branch=feat/extend-models#5080890a11a059614e8b1ee3cc782704e327a763" +source = "git+https://github.com/broxus/nekoton.git?branch=master#8fed4c0ecf949d97814a4794574bd4ede9dad3bf" dependencies = [ "anyhow", "base64", @@ -1201,7 +1201,7 @@ dependencies = [ [[package]] name = "ton_types" version = "1.10.2" -source = "git+https://github.com/broxus/ton-labs-types.git#bb5ea019fb95def471b2e35c1d6d4f15a0d8fe61" +source = "git+https://github.com/broxus/ton-labs-types.git#3324562d7ff1ebec66d996128573966c1b53862b" dependencies = [ "anyhow", "base64", diff --git a/Cargo.toml b/Cargo.toml index 7b0afd5..bda6408 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -50,8 +50,8 @@ serde-wasm-bindgen = "0.5.0" [dependencies.nt] package = "nekoton" git = "https://github.com/broxus/nekoton.git" -branch = "feat/extend-models" -features = ["web", "gql_transport", "jrpc_transport"] +branch = "master" +features = ["web", "gql_transport", "jrpc_transport", "extended_models"] [patch.crates-io] hmac-drbg = { git = "https://github.com/Rexagon/rust-hmac-drbg" } diff --git a/src/models.rs b/src/models.rs index f258f14..334322a 100644 --- a/src/models.rs +++ b/src/models.rs @@ -421,7 +421,7 @@ pub fn make_message(data: &models::Message) -> JsValue { .set("bounced", data.bounced) .set("body", body) .set("bodyHash", body_hash) - .set("boc", data.boc.to_string()) + .set("boc", make_boc(&data.raw).expect("Shouldn't fail")) .build() .unchecked_into() } @@ -756,7 +756,7 @@ pub fn make_transaction_ext( .set("totalFees", data.total_fees.to_string()) .set("inMessage", in_msg) .set("outMessages", out_msgs) - .set("boc", data.boc) + .set("boc", make_boc(&data.raw).expect("Shouldn't fail")) .build() .unchecked_into() } From 469b2bf8015a261f4432c07bf597ab577794afe9 Mon Sep 17 00:00:00 2001 From: Maga Date: Wed, 19 Jul 2023 02:30:51 +0400 Subject: [PATCH 2/7] Fixed execute local --- src/lib.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 0e7c441..3f10e3a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -273,7 +273,7 @@ pub fn execute_local_extended( })); } - let (hash, data) = + let (mut hash, mut data) = match executor.execute_with_libs_and_params(Some(&message), &mut account, params) { Ok(tx) => { let hash = tx.hash().handle_error()?; @@ -292,6 +292,10 @@ pub fn execute_local_extended( } }; + // add last tx lt + data.set_prev_trans_lt(last_trans_lt); + hash = data.hash().handle_error()?; + let trace_js = trace.lock().unwrap(); let trace_res_vec_js: Result, _> = trace_js.iter().map(make_engine_trace).collect(); let trace_vec_js = trace_res_vec_js?; From 75a68adb0e88cbd2890733509a2115b34bbd0cb9 Mon Sep 17 00:00:00 2001 From: serejkaaa512 <5125402@mail.ru> Date: Wed, 19 Jul 2023 16:57:59 +0300 Subject: [PATCH 3/7] updated deps --- src/lib.rs | 35 +++++++++------------ src/models.rs | 71 ++++++++++++++++++++++++++++++------------ src/transport/proxy.rs | 1 - 3 files changed, 66 insertions(+), 41 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 3f10e3a..6f7be64 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -84,9 +84,7 @@ pub fn make_full_account_boc(account_stuff_boc: Option) -> Result Result { - let msg = ton_block::Message::construct_from_base64(message).handle_error()?; - let nt_msg = - nt::core::models::Message::try_from((msg.hash().handle_error()?, msg)).handle_error()?; + let nt_msg = nt::core::models::Message::try_from(parse_cell(&message)?).handle_error()?; serde_wasm_bindgen::to_value(&nt_msg) .handle_error() .map(JsValue::unchecked_into) @@ -273,28 +271,25 @@ pub fn execute_local_extended( })); } - let (mut hash, mut data) = - match executor.execute_with_libs_and_params(Some(&message), &mut account, params) { - Ok(tx) => { - let hash = tx.hash().handle_error()?; - (hash, tx) - } - Err(e) => { - return match e.downcast_ref::() { - Some(ton_executor::ExecutorError::NoAcceptError(code, _)) => { - Ok(ObjectBuilder::new() - .set("exitCode", *code) - .build() - .unchecked_into()) - } - _ => Err(e).handle_error(), + let mut data = match executor.execute_with_libs_and_params(Some(&message), &mut account, params) + { + Ok(tx) => tx, + Err(e) => { + return match e.downcast_ref::() { + Some(ton_executor::ExecutorError::NoAcceptError(code, _)) => { + Ok(ObjectBuilder::new() + .set("exitCode", *code) + .build() + .unchecked_into()) } + _ => Err(e).handle_error(), } - }; + } + }; // add last tx lt data.set_prev_trans_lt(last_trans_lt); - hash = data.hash().handle_error()?; + let hash = data.hash().handle_error()?; let trace_js = trace.lock().unwrap(); let trace_res_vec_js: Result, _> = trace_js.iter().map(make_engine_trace).collect(); diff --git a/src/models.rs b/src/models.rs index 334322a..7f35fdf 100644 --- a/src/models.rs +++ b/src/models.rs @@ -3,7 +3,9 @@ use std::convert::TryFrom; use nt::core::models; use nt::core::models::TransactionError; -use ton_block::{Deserializable, GetRepresentationHash, Serializable, TrBouncePhase}; +use ton_block::{ + Deserializable, GetRepresentationHash, MsgAddressInt, Serializable, TrBouncePhase, +}; use ton_types::UInt256; use wasm_bindgen::prelude::*; use wasm_bindgen::JsCast; @@ -100,7 +102,6 @@ export type JsRawMessage = { bounced: boolean, body?: string, bodyHash?: string, - boc: string, init?: { codeHash: string }, @@ -428,19 +429,50 @@ pub fn make_message(data: &models::Message) -> JsValue { pub fn make_raw_message(data: &ton_block::Message) -> JsRawMessage { let hash = data.hash().unwrap_or_default(); - let message = models::Message::try_from((hash, data.clone())) - .handle_error() - .unwrap(); - let msg_type = match data.header() { - ton_block::CommonMsgInfo::IntMsgInfo(_header) => "IntMsg", - ton_block::CommonMsgInfo::ExtInMsgInfo(_header) => "ExtIn", - ton_block::CommonMsgInfo::ExtOutMsgInfo(_header) => "ExtOut", + + #[derive(Default)] + struct MessageCommon { + pub src: Option, + pub dst: Option, + pub value: u64, + pub bounce: bool, + pub bounced: bool, + pub msg_type: String, + } + + let common = match data.header() { + ton_block::CommonMsgInfo::IntMsgInfo(header) => MessageCommon { + src: match &header.src { + ton_block::MsgAddressIntOrNone::Some(addr) => Some(addr.clone()), + ton_block::MsgAddressIntOrNone::None => None, + }, + dst: Some(header.dst.clone()), + value: header.value.grams.as_u128() as u64, + bounce: header.bounce, + bounced: header.bounced, + msg_type: "IntMsg".to_string(), + }, + ton_block::CommonMsgInfo::ExtInMsgInfo(header) => MessageCommon { + src: None, + dst: Some(header.dst.clone()), + msg_type: "ExtIn".to_string(), + ..Default::default() + }, + ton_block::CommonMsgInfo::ExtOutMsgInfo(header) => MessageCommon { + src: match &header.src { + ton_block::MsgAddressIntOrNone::Some(addr) => Some(addr.clone()), + ton_block::MsgAddressIntOrNone::None => None, + }, + msg_type: "ExtOut".to_string(), + ..Default::default() + }, }; - let (body, body_hash) = if let Some(body) = &message.body { + let (body, body_hash) = if let Some(body) = &data.body() { + let data = body.clone().into_cell(); ( - Some(make_boc(&body.data).expect("Shouldn't fail")), - Some(body.hash.to_hex_string()), + Some(make_boc(&data).expect("Shouldn't fail")), + Some(data.repr_hash().to_hex_string()), ) } else { (None, None) @@ -462,17 +494,16 @@ pub fn make_raw_message(data: &ton_block::Message) -> JsRawMessage { let lt = data.lt(); ObjectBuilder::new() - .set("hash", message.hash.to_hex_string()) - .set("src", message.src.as_ref().map(ToString::to_string)) - .set("dst", message.dst.as_ref().map(ToString::to_string)) - .set("value", message.value.to_string()) - .set("bounce", message.bounce) - .set("bounced", message.bounced) + .set("hash", hash.to_hex_string()) + .set("src", common.src.as_ref().map(ToString::to_string)) + .set("dst", common.dst.as_ref().map(ToString::to_string)) + .set("value", common.value.to_string()) + .set("bounce", common.bounce) + .set("bounced", common.bounced) .set("body", body) .set("bodyHash", body_hash) - .set("boc", message.boc.to_string()) .set("init", init) - .set("msgType", msg_type) + .set("msgType", common.msg_type) .set("lt", lt) .build() .unchecked_into() diff --git a/src/transport/proxy.rs b/src/transport/proxy.rs index d647387..acedd58 100644 --- a/src/transport/proxy.rs +++ b/src/transport/proxy.rs @@ -63,7 +63,6 @@ impl Transport for ProxyTransport { value if value == JsValue::UNDEFINED => Ok(RawContractState::NotExists), boc => { serde_wasm_bindgen::from_value(boc).map_err(|e| anyhow::Error::msg(e.to_string())) - } } } From ff5e51cb1005d4ea0ad5a8aefdef21efb3973184 Mon Sep 17 00:00:00 2001 From: serejkaaa512 <5125402@mail.ru> Date: Wed, 19 Jul 2023 17:52:16 +0300 Subject: [PATCH 4/7] fixed raw message interface and recovered boc --- src/lib.rs | 4 +--- src/models.rs | 16 ++++++++-------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 6f7be64..5e0edd2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -92,9 +92,7 @@ pub fn parse_message_base64(message: &str) -> Result { #[wasm_bindgen(js_name = "parseMessageBase64Extended")] pub fn parse_message_base64_extended(message: &str) -> Result { - Ok(make_raw_message( - &ton_block::Message::construct_from_base64(message).handle_error()?, - )) + Ok(make_raw_message(parse_cell(message)?)) } #[wasm_bindgen(js_name = "parseFullAccountBoc")] diff --git a/src/models.rs b/src/models.rs index 7f35fdf..7f13833 100644 --- a/src/models.rs +++ b/src/models.rs @@ -102,6 +102,7 @@ export type JsRawMessage = { bounced: boolean, body?: string, bodyHash?: string, + boc: string, init?: { codeHash: string }, @@ -427,7 +428,8 @@ pub fn make_message(data: &models::Message) -> JsValue { .unchecked_into() } -pub fn make_raw_message(data: &ton_block::Message) -> JsRawMessage { +pub fn make_raw_message(raw: ton_types::Cell) -> JsRawMessage { + let data = ton_block::Message::construct_from_cell(raw.clone()).expect("Shouldn't fail"); let hash = data.hash().unwrap_or_default(); #[derive(Default)] @@ -502,6 +504,7 @@ pub fn make_raw_message(data: &ton_block::Message) -> JsRawMessage { .set("bounced", common.bounced) .set("body", body) .set("bodyHash", body_hash) + .set("boc", make_boc(&raw).expect("Shouldn't fail")) .set("init", init) .set("msgType", common.msg_type) .set("lt", lt) @@ -596,8 +599,8 @@ pub fn make_raw_transaction( let boc = base64::encode(boc); let in_msg = { - if let Some(msg) = &data.in_msg.and_then(|in_msg| in_msg.read_struct().ok()) { - Some(make_raw_message(msg)) + if let Some(msg) = &data.in_msg.map(|in_msg| in_msg.cell()) { + Some(make_raw_message(msg.clone())) } else { None } @@ -606,10 +609,7 @@ pub fn make_raw_transaction( let mut out_messages = vec![]; data.out_msgs .iterate_slices(|slice| { - if let Ok(message) = slice - .reference(0) - .and_then(ton_block::Message::construct_from_cell) - { + if let Ok(message) = slice.reference(0) { out_messages.push(message); } Ok(true) @@ -618,7 +618,7 @@ pub fn make_raw_transaction( let out_msgs = out_messages .into_iter() - .map(|msg| make_raw_message(&msg)) + .map(|msg| make_raw_message(msg)) .collect::(); let desc = if let Some(ton_block::TransactionDescr::Ordinary(desc)) = From 664aae33c0f3804432b289985bbbe77eff9527ee Mon Sep 17 00:00:00 2001 From: serejkaaa512 <5125402@mail.ru> Date: Thu, 20 Jul 2023 13:58:25 +0300 Subject: [PATCH 5/7] added dst to ext out raw message --- src/models.rs | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/src/models.rs b/src/models.rs index 7f13833..661c027 100644 --- a/src/models.rs +++ b/src/models.rs @@ -4,7 +4,8 @@ use std::convert::TryFrom; use nt::core::models; use nt::core::models::TransactionError; use ton_block::{ - Deserializable, GetRepresentationHash, MsgAddressInt, Serializable, TrBouncePhase, + Deserializable, GetRepresentationHash, MsgAddressExt, MsgAddressInt, Serializable, + TrBouncePhase, }; use ton_types::UInt256; use wasm_bindgen::prelude::*; @@ -460,14 +461,23 @@ pub fn make_raw_message(raw: ton_types::Cell) -> JsRawMessage { msg_type: "ExtIn".to_string(), ..Default::default() }, - ton_block::CommonMsgInfo::ExtOutMsgInfo(header) => MessageCommon { - src: match &header.src { - ton_block::MsgAddressIntOrNone::Some(addr) => Some(addr.clone()), - ton_block::MsgAddressIntOrNone::None => None, - }, - msg_type: "ExtOut".to_string(), - ..Default::default() - }, + ton_block::CommonMsgInfo::ExtOutMsgInfo(header) => { + let dst = match header.dst.clone() { + MsgAddressExt::AddrNone => None, + MsgAddressExt::AddrExtern(mut addr) => { + MsgAddressInt::construct_from(&mut addr.external_address).ok() + } + }; + MessageCommon { + src: match &header.src { + ton_block::MsgAddressIntOrNone::Some(addr) => Some(addr.clone()), + ton_block::MsgAddressIntOrNone::None => None, + }, + msg_type: "ExtOut".to_string(), + dst, + ..Default::default() + } + } }; let (body, body_hash) = if let Some(body) = &data.body() { From 112279af0872116ff7ee9495172aa151cc463f4d Mon Sep 17 00:00:00 2001 From: serejkaaa512 <5125402@mail.ru> Date: Thu, 20 Jul 2023 15:04:30 +0300 Subject: [PATCH 6/7] fixed dst model for raw message --- src/models.rs | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/models.rs b/src/models.rs index 661c027..e8d3af3 100644 --- a/src/models.rs +++ b/src/models.rs @@ -436,7 +436,7 @@ pub fn make_raw_message(raw: ton_types::Cell) -> JsRawMessage { #[derive(Default)] struct MessageCommon { pub src: Option, - pub dst: Option, + pub dst: Option, pub value: u64, pub bounce: bool, pub bounced: bool, @@ -449,7 +449,7 @@ pub fn make_raw_message(raw: ton_types::Cell) -> JsRawMessage { ton_block::MsgAddressIntOrNone::Some(addr) => Some(addr.clone()), ton_block::MsgAddressIntOrNone::None => None, }, - dst: Some(header.dst.clone()), + dst: Some(header.dst.to_string()), value: header.value.grams.as_u128() as u64, bounce: header.bounce, bounced: header.bounced, @@ -457,16 +457,19 @@ pub fn make_raw_message(raw: ton_types::Cell) -> JsRawMessage { }, ton_block::CommonMsgInfo::ExtInMsgInfo(header) => MessageCommon { src: None, - dst: Some(header.dst.clone()), + dst: Some(header.dst.to_string()), msg_type: "ExtIn".to_string(), ..Default::default() }, ton_block::CommonMsgInfo::ExtOutMsgInfo(header) => { let dst = match header.dst.clone() { MsgAddressExt::AddrNone => None, - MsgAddressExt::AddrExtern(mut addr) => { - MsgAddressInt::construct_from(&mut addr.external_address).ok() - } + MsgAddressExt::AddrExtern(addr) => Some( + addr.external_address + .as_hex_string() + .drain(..addr.len.as_u32() as usize) + .collect(), + ), }; MessageCommon { src: match &header.src { @@ -508,7 +511,7 @@ pub fn make_raw_message(raw: ton_types::Cell) -> JsRawMessage { ObjectBuilder::new() .set("hash", hash.to_hex_string()) .set("src", common.src.as_ref().map(ToString::to_string)) - .set("dst", common.dst.as_ref().map(ToString::to_string)) + .set("dst", common.dst) .set("value", common.value.to_string()) .set("bounce", common.bounce) .set("bounced", common.bounced) From 92b4e6e83957800e66e41a9fb578d825f3051de2 Mon Sep 17 00:00:00 2001 From: serejkaaa512 <5125402@mail.ru> Date: Thu, 20 Jul 2023 15:33:40 +0300 Subject: [PATCH 7/7] fixed dst model for raw message --- src/models.rs | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/models.rs b/src/models.rs index e8d3af3..6675915 100644 --- a/src/models.rs +++ b/src/models.rs @@ -464,12 +464,7 @@ pub fn make_raw_message(raw: ton_types::Cell) -> JsRawMessage { ton_block::CommonMsgInfo::ExtOutMsgInfo(header) => { let dst = match header.dst.clone() { MsgAddressExt::AddrNone => None, - MsgAddressExt::AddrExtern(addr) => Some( - addr.external_address - .as_hex_string() - .drain(..addr.len.as_u32() as usize) - .collect(), - ), + MsgAddressExt::AddrExtern(addr) => Some(addr.external_address.as_hex_string()), }; MessageCommon { src: match &header.src {