Skip to content

Commit

Permalink
Update dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
Rexagon committed Jun 4, 2023
1 parent 9691d79 commit 0434c08
Show file tree
Hide file tree
Showing 8 changed files with 376 additions and 289 deletions.
552 changes: 312 additions & 240 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ nekoton-transport = { git = "https://github.com/broxus/nekoton.git", features =
nekoton-utils = { git = "https://github.com/broxus/nekoton.git" }
nekoton-abi = { git = "https://github.com/broxus/nekoton.git" }

ton_block = { git = "https://github.com/broxus/ton-labs-block.git" }
ton_block = { git = "https://github.com/broxus/ton-labs-block.git", features = ["venom"] }
ton_types = { git = "https://github.com/broxus/ton-labs-types.git" }
ton_abi = { git = "https://github.com/broxus/ton-labs-abi.git" }
33 changes: 17 additions & 16 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use nekoton_utils::{SimpleClock, TrustMe};
use serde::Deserialize;
use tokio::sync::oneshot;
use ton_block::{ConfigParamEnum, Serializable};
use ton_types::IBitstring;
use ton_types::{BuilderData, Cell, IBitstring, SliceData};

use crate::models::*;

Expand Down Expand Up @@ -48,8 +48,8 @@ pub async fn set_elector_code(
url: String,
config: &ton_block::MsgAddressInt,
secret: &ed25519::SecretKey,
code: ton_types::Cell,
params: Option<ton_types::SliceData>,
code: Cell,
params: Option<SliceData>,
) -> Result<()> {
ConfigContract::subscribe(url, config)
.await?
Expand Down Expand Up @@ -252,12 +252,13 @@ impl ConfigContract {
RawContractState::NotExists => return Err(ConfigError::ConfigNotExists.into()),
};

let mut data: ton_types::SliceData = match config_state.storage.state {
let mut data: SliceData = match config_state.storage.state {
ton_block::AccountState::AccountActive { state_init, .. } => state_init.data,
_ => None,
}
.ok_or(ConfigError::InvalidState)?
.into();
.map(SliceData::load_cell)
.transpose()?
.ok_or(ConfigError::InvalidState)?;

let seqno = data.get_next_u32().context("Failed to get seqno")?;
if let Some(required_public) = required_public {
Expand Down Expand Up @@ -313,7 +314,7 @@ pub fn create_message(
.as_secs() as u32;
let expire_at = now + timeout;

let mut builder = ton_types::BuilderData::new();
let mut builder = BuilderData::new();
builder
.append_u32(action)? // action
.append_u32(seqno)? // msg_seqno
Expand All @@ -340,7 +341,7 @@ pub fn create_message(
dst: address.clone(),
..Default::default()
});
message.set_body(builder.into());
message.set_body(SliceData::load_builder(builder)?);

Ok((message, expire_at))
}
Expand Down Expand Up @@ -370,22 +371,22 @@ pub enum Action {

/// Config contract code
#[allow(unused)]
UpdateConfigCode(ton_types::Cell),
UpdateConfigCode(Cell),

/// New config public key
UpdateMasterKey(ed25519::PublicKey),

/// First ref is elector code.
/// Remaining data is passed to `after_code_upgrade`
UpdateElectorCode {
code: ton_types::Cell,
params: Option<ton_types::SliceData>,
code: Cell,
params: Option<SliceData>,
},
}

impl Action {
fn build(self) -> Result<(u32, ton_types::BuilderData)> {
let mut data = ton_types::BuilderData::new();
fn build(self) -> Result<(u32, BuilderData)> {
let mut data = BuilderData::new();

Ok(match self {
Self::SubmitParam(param) => {
Expand All @@ -394,17 +395,17 @@ impl Action {
(0x43665021, data)
}
Self::UpdateConfigCode(code) => {
data.append_reference_cell(code);
data.checked_append_reference(code)?;
(0x4e436f64, data)
}
Self::UpdateMasterKey(key) => {
data.append_raw(key.as_bytes(), 256).trust_me();
(0x50624b21, data)
}
Self::UpdateElectorCode { code, params } => {
data.append_reference_cell(code);
data.checked_append_reference(code)?;
if let Some(params) = params {
data.append_builder(&ton_types::BuilderData::from_slice(&params))?;
data.append_builder(&BuilderData::from_slice(&params))?;
}
(0x4e43ef05, data)
}
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ async fn run(app: App) -> Result<()> {
let params = match args.params {
Some(params) => {
let cell = parse_cell(&params).context("Invalid params")?;
Some(cell.into())
Some(ton_types::SliceData::load_cell(cell)?)
}
None => None,
};
Expand Down
18 changes: 13 additions & 5 deletions src/mine/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use nekoton_abi::BuildTokenValue;
use nekoton_utils::TrustMe;
use rand::distributions::Distribution;
use ton_block::{Deserializable, Serializable};
use ton_types::SliceData;

pub fn mine(
tvc: impl AsRef<Path>,
Expand Down Expand Up @@ -65,7 +66,10 @@ pub fn mine(

let original_data = abi
.update_data(
tvc.data.clone().context("TVC doesn't have data")?.into(),
tvc.data
.clone()
.context("TVC doesn't have data")
.and_then(SliceData::load_cell)?,
&init_data,
)
.context("Failed to update init data")?;
Expand All @@ -86,7 +90,8 @@ pub fn mine(
for _ in 0..thread_count {
let mut tvc = tvc.clone();

let nonce_key: ton_types::SliceData = field.key.serialize()?.into();
let nonce_key: ton_types::SliceData =
field.key.serialize().and_then(SliceData::load_cell)?;
let mut original_data =
ton_types::HashmapE::with_hashmap(64, original_data.reference_opt(0));

Expand Down Expand Up @@ -221,16 +226,19 @@ impl TokenState {
.pack_into_chain(&ton_abi::contract::ABI_VERSION_2_2)
.trust_me();

data.set_builder(1u64.serialize().trust_me().into(), &builder)
.trust_me();
data.set_builder(
1u64.serialize().and_then(SliceData::load_cell).trust_me(),
&builder,
)
.trust_me();

Self { state, data }
}

fn compute_address(&mut self, address: ton_types::UInt256) -> ton_types::UInt256 {
self.data
.set_builder(
2u64.serialize().trust_me().into(),
2u64.serialize().and_then(SliceData::load_cell).trust_me(),
&ton_abi::TokenValue::Address(ton_block::MsgAddress::AddrStd(
ton_block::MsgAddrStd {
workchain_id: 0,
Expand Down
19 changes: 10 additions & 9 deletions src/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use anyhow::{Context, Result};
use nekoton_utils::*;
use num_bigint::BigInt;
use serde::Deserialize;
use ton_types::SliceData;

#[derive(Deserialize)]
pub struct ZerostateConfig {
Expand Down Expand Up @@ -104,7 +105,7 @@ impl TransactionTreeLimits {
self.max_depth.write_to(&mut model)?;
self.max_cumulative_width.write_to(&mut model)?;
self.width_multiplier.write_to(&mut model)?;
let model = model.into_cell()?.into();
let model = model.into_cell().and_then(SliceData::load_cell)?;

Ok(ton_block::ConfigParamEnum::ConfigParamAny(50, model))
}
Expand All @@ -119,7 +120,7 @@ pub struct BannedAccountsByAddress(
impl BannedAccountsByAddress {
pub fn build(&self) -> Result<ton_block::ConfigParamEnum> {
use ton_block::{Deserializable, Serializable};
use ton_types::{BuilderData, Cell, HashmapE, HashmapType, IBitstring, SliceData};
use ton_types::{BuilderData, Cell, HashmapE, HashmapType, IBitstring};

#[derive(Clone, Debug, Eq, PartialEq, Default)]
pub struct SuspendedAddressesKey {
Expand Down Expand Up @@ -166,7 +167,7 @@ impl BannedAccountsByAddress {
let addr = ton_types::UInt256::construct_from(&mut addr.address())?;
addresses.add_suspended_address(wc, addr)?;
}
let addresses = addresses.serialize()?.into();
let addresses = addresses.serialize().and_then(SliceData::load_cell)?;

Ok(ton_block::ConfigParamEnum::ConfigParamAny(44, addresses))
}
Expand Down Expand Up @@ -339,17 +340,17 @@ impl ElectorParams {
#[derive(Deserialize)]
#[serde(deny_unknown_fields)]
pub struct ValidatorCount {
pub min_validators: u32,
pub max_validators: u32,
pub max_main_validators: u32,
pub min_validators: u16,
pub max_validators: u16,
pub max_main_validators: u16,
}

impl ValidatorCount {
pub fn build(&self) -> ton_block::ConfigParam16 {
ton_block::ConfigParam16 {
max_validators: ton_block::Number16(self.max_validators),
max_main_validators: ton_block::Number16(self.max_main_validators),
min_validators: ton_block::Number16(self.min_validators),
max_validators: ton_block::Number16::from(self.max_validators),
max_main_validators: ton_block::Number16::from(self.max_main_validators),
min_validators: ton_block::Number16::from(self.min_validators),
}
}
}
Expand Down
29 changes: 16 additions & 13 deletions src/system_accounts/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::str::FromStr;

use anyhow::{Context, Result};
use ton_block::{Deserializable, GetRepresentationHash, Serializable};
use ton_types::IBitstring;
use ton_types::{IBitstring, SliceData};

use crate::ed25519::*;

Expand Down Expand Up @@ -37,7 +37,7 @@ pub fn build_config_state(
ton_types::deserialize_tree_of_cells(&mut code).context("Failed to read config code")?;

let mut data = ton_types::BuilderData::new();
data.append_reference(ton_types::BuilderData::default());
data.checked_append_reference(ton_types::Cell::default())?;
data.append_u32(0)?;
data.append_raw(pubkey.as_bytes(), 256)?;
data.append_bits(0, 1)?;
Expand Down Expand Up @@ -122,7 +122,7 @@ pub fn build_giver(

let state_init = account.state_init_mut().expect("Shouldn't fail");
if let Some(data) = state_init.data.take() {
let mut data: ton_types::SliceData = data.into();
let mut data = SliceData::load_cell(data)?;
data.move_by(256).expect("invalid giver state");

let mut new_data = ton_types::BuilderData::new();
Expand All @@ -138,9 +138,9 @@ pub fn build_giver(
.hash()
.context("Failed to serialize state init")?;

account.set_balance(ton_block::CurrencyCollection::from_grams(ton_block::Grams(
balance,
)));
account.set_balance(ton_block::CurrencyCollection::from_grams(
ton_block::Grams::new(balance)?,
));

account
.update_storage_stat()
Expand Down Expand Up @@ -239,15 +239,18 @@ impl MultisigBuilder {
// Compute address
let mut init_params = ton_types::HashmapE::with_bit_len(64);
init_params.set(
0u64.serialize()?.into(),
0u64.serialize().and_then(SliceData::load_cell)?,
&ton_types::SliceData::from_raw(self.pubkey.as_bytes().to_vec(), 256),
)?;

if self.ty != MultisigType::Multisig2 {
init_params.set(8u64.serialize()?.into(), &{
let key = 8u64.serialize().and_then(SliceData::load_cell)?;

init_params.set(key, &{
let key = 0u64.serialize().and_then(SliceData::load_cell)?;
let mut map = ton_types::HashmapE::with_bit_len(64);
map.set(0u64.serialize()?.into(), &Default::default())?;
map.serialize()?.into()
map.set(key, &Default::default())?;
map.serialize().and_then(SliceData::load_cell)?
})?;
}

Expand Down Expand Up @@ -305,7 +308,7 @@ impl MultisigBuilder {

let mut updates = ton_types::BuilderData::new();
updates.append_bit_zero()?; // empty m_updateRequests
data.append_reference_cell(updates.into_cell()?); // sub reference
data.checked_append_reference(updates.into_cell()?)?; // sub reference

data.append_u8(default_required_confirmations)?; // m_defaultRequiredConfirmations
data.append_bit_zero()?; // empty m_transactions
Expand Down Expand Up @@ -334,7 +337,7 @@ impl MultisigBuilder {
storage_stat: Default::default(),
storage: ton_block::AccountStorage {
last_trans_lt: 0,
balance: ton_block::CurrencyCollection::from_grams(ton_block::Grams(balance)),
balance: ton_block::CurrencyCollection::from_grams(ton_block::Grams::new(balance)?),
state: ton_block::AccountState::AccountActive { state_init },
init_code_hash: None,
},
Expand Down Expand Up @@ -370,7 +373,7 @@ pub fn build_ever_wallet(
storage_stat: Default::default(),
storage: ton_block::AccountStorage {
last_trans_lt: 0,
balance: ton_block::CurrencyCollection::from_grams(ton_block::Grams(balance)),
balance: ton_block::CurrencyCollection::from_grams(ton_block::Grams::new(balance)?),
state: ton_block::AccountState::AccountActive { state_init },
init_code_hash: None,
},
Expand Down
10 changes: 6 additions & 4 deletions src/zerostate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::path::Path;

use anyhow::{Context, Result};
use ton_block::{AddSub, Serializable};
use ton_types::SliceData;

use crate::ed25519::*;
use crate::models::*;
Expand Down Expand Up @@ -49,9 +50,10 @@ pub fn prepare_zerostates<P: AsRef<Path>>(path: P, config: &str) -> Result<Strin
Ok(true)
})?;

ex.config
.config_params
.setref(12u32.serialize()?.into(), &workchains.serialize()?)?;
ex.config.config_params.setref(
12u32.serialize().and_then(SliceData::load_cell)?,
&workchains.serialize()?,
)?;

let catchain_config = ex
.config
Expand All @@ -68,7 +70,7 @@ pub fn prepare_zerostates<P: AsRef<Path>>(path: P, config: &str) -> Result<Strin
ton_block::SHARD_FULL,
ton_block::MASTERCHAIN_ID,
0,
ton_block::UnixTime32(now),
ton_block::UnixTime32::from(now),
)
.context("Failed to compute validator subset")?
.1;
Expand Down

0 comments on commit 0434c08

Please sign in to comment.