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/lib.rs b/src/lib.rs index 0e7c441..5e0edd2 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) @@ -94,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")] @@ -273,24 +269,25 @@ pub fn execute_local_extended( })); } - let (hash, 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); + 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 f258f14..6675915 100644 --- a/src/models.rs +++ b/src/models.rs @@ -3,7 +3,10 @@ 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, MsgAddressExt, MsgAddressInt, Serializable, + TrBouncePhase, +}; use ton_types::UInt256; use wasm_bindgen::prelude::*; use wasm_bindgen::JsCast; @@ -421,26 +424,65 @@ 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() } -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(); - 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.to_string()), + 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.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(addr) => Some(addr.external_address.as_hex_string()), + }; + 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) = &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 +504,17 @@ 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) + .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("boc", make_boc(&raw).expect("Shouldn't fail")) .set("init", init) - .set("msgType", msg_type) + .set("msgType", common.msg_type) .set("lt", lt) .build() .unchecked_into() @@ -565,8 +607,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 } @@ -575,10 +617,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) @@ -587,7 +626,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)) = @@ -756,7 +795,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() } 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())) - } } }