Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
41 changes: 19 additions & 22 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,19 +84,15 @@ pub fn make_full_account_boc(account_stuff_boc: Option<String>) -> Result<String

#[wasm_bindgen(js_name = "parseMessageBase64")]
pub fn parse_message_base64(message: &str) -> Result<Message, JsValue> {
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)
}

#[wasm_bindgen(js_name = "parseMessageBase64Extended")]
pub fn parse_message_base64_extended(message: &str) -> Result<JsRawMessage, JsValue> {
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")]
Expand Down Expand Up @@ -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::<ton_executor::ExecutorError>() {
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::<ton_executor::ExecutorError>() {
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<Vec<_>, _> = trace_js.iter().map(make_engine_trace).collect();
Expand Down
97 changes: 68 additions & 29 deletions src/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<MsgAddressInt>,
pub dst: Option<String>,
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)
Expand All @@ -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()
Expand Down Expand Up @@ -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
}
Expand All @@ -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)
Expand All @@ -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::<js_sys::Array>();

let desc = if let Some(ton_block::TransactionDescr::Ordinary(desc)) =
Expand Down Expand Up @@ -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()
}
Expand Down
1 change: 0 additions & 1 deletion src/transport/proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()))

}
}
}
Expand Down