Skip to content

Commit

Permalink
dapp_id -> optional (#40)
Browse files Browse the repository at this point in the history
* dapp_id -> optional

* update changelog
  • Loading branch information
SeHor05 authored Oct 11, 2024
1 parent ce9206d commit 4680831
Show file tree
Hide file tree
Showing 14 changed files with 70 additions and 73 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

All notable changes to this project will be documented in this file.

## [2.2.11] – 2024-10-08

### Fixed
- Update Dapp_id field in AccountStuff into Option.

## [2.2.10] – 2024-10-08

### Fixed
Expand Down
40 changes: 20 additions & 20 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ members = [
"tvm_vm",
]
[workspace.package]
version = "2.2.10"
version = "2.2.11"
rust-version = "1.76.0"

authors = ["TVM Labs <hello@tvmlabs.io>"]
Expand Down
30 changes: 15 additions & 15 deletions tvm_block/src/accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ impl fmt::Display for AccountState {
#[derive(Debug, Clone, Default)]
pub struct AccountStuff {
addr: MsgAddressInt,
dapp_id: UInt256,
dapp_id: Option<UInt256>,
storage_stat: StorageInfo,
storage: AccountStorage,
}
Expand Down Expand Up @@ -578,7 +578,7 @@ impl Serializable for AccountStuff {
fn write_to(&self, builder: &mut BuilderData) -> Result<()> {
let mut builder_stuff = BuilderData::new();
self.addr.write_to(&mut builder_stuff)?;
self.dapp_id.write_to(&mut builder_stuff)?;
self.dapp_id.write_maybe_to(&mut builder_stuff)?;
let mut builder_stuff2 = BuilderData::new();
self.storage_stat.write_to(&mut builder_stuff2)?;
self.storage.write_to(&mut builder_stuff2)?;
Expand Down Expand Up @@ -626,7 +626,7 @@ impl Account {

pub fn active_by_init_code_hash(
addr: MsgAddressInt,
dapp_id: UInt256,
dapp_id: Option<UInt256>,
balance: CurrencyCollection,
last_paid: u32,
state_init: StateInit,
Expand All @@ -650,7 +650,7 @@ impl Account {
/// create unintialized account, only with address and balance
pub fn with_address_and_ballance(
addr: &MsgAddressInt,
dapp_id: UInt256,
dapp_id: Option<UInt256>,
balance: &CurrencyCollection,
) -> Self {
Account::with_stuff(AccountStuff {
Expand All @@ -662,7 +662,7 @@ impl Account {
}

/// Create unintialize account with zero balance
pub const fn with_address(addr: MsgAddressInt, dapp_id: UInt256) -> Self {
pub const fn with_address(addr: MsgAddressInt, dapp_id: Option<UInt256>) -> Self {
Account::with_stuff(AccountStuff {
addr,
dapp_id,
Expand All @@ -675,7 +675,7 @@ impl Account {
pub fn from_message_by_init_code_hash(
msg: &Message,
init_code_hash: bool,
dapp_id: UInt256,
dapp_id: Option<UInt256>,
) -> Option<Self> {
let hdr = msg.int_header()?;
if hdr.value().grams.is_zero() {
Expand Down Expand Up @@ -730,7 +730,7 @@ impl Account {
/// create frozen account - for test purposes
pub fn frozen(
addr: MsgAddressInt,
dapp_id: UInt256,
dapp_id: Option<UInt256>,
last_trans_lt: u64,
last_paid: u32,
state_hash: UInt256,
Expand All @@ -747,7 +747,6 @@ impl Account {
/// create uninit account - for test purposes
pub fn uninit(
addr: MsgAddressInt,
dapp_id: UInt256,
last_trans_lt: u64,
last_paid: u32,
balance: CurrencyCollection,
Expand All @@ -764,14 +763,15 @@ impl Account {
last_paid,
due_payment: None,
};
let dapp_id = None;
let stuff = AccountStuff { addr, dapp_id, storage_stat, storage };
Account::with_stuff(stuff)
}

// constructor only same tests
pub fn with_storage(
addr: &MsgAddressInt,
dapp_id: UInt256,
dapp_id: Option<UInt256>,
storage_stat: &StorageInfo,
storage: &AccountStorage,
) -> Self {
Expand Down Expand Up @@ -847,7 +847,7 @@ impl Account {
self.stuff().map(|s| &s.addr)
}

pub fn get_dapp_id(&self) -> Option<&UInt256> {
pub fn get_dapp_id(&self) -> Option<&Option<UInt256>> {
self.stuff().map(|s| &s.dapp_id)
}

Expand Down Expand Up @@ -1125,7 +1125,7 @@ impl Account {
let mut builder_stuff = BuilderData::new();
builder.append_bit_one()?;
stuff.addr.write_to(&mut builder_stuff)?;
stuff.dapp_id.write_to(&mut builder_stuff)?;
stuff.dapp_id.write_maybe_to(&mut builder_stuff)?;
builder.checked_append_reference(builder_stuff.into_cell().unwrap()).unwrap();
let mut builder_stuff2 = BuilderData::new();
stuff.storage_stat.write_to(&mut builder_stuff2)?;
Expand All @@ -1143,7 +1143,7 @@ impl Account {
let builder = slice.reference(0).unwrap();
let mut slice_builder = SliceData::load_cell(builder).unwrap();
let addr = Deserializable::construct_from(&mut slice_builder)?;
let dapp_id = UInt256::construct_from(&mut slice_builder)?;
let dapp_id = UInt256::read_maybe_from(&mut slice_builder)?;
let builder2 = slice.reference(1).unwrap();
slice_builder = SliceData::load_cell(builder2).unwrap();
let storage_stat = Deserializable::construct_from(&mut slice_builder)?;
Expand All @@ -1158,7 +1158,7 @@ impl Account {
let builder = slice.reference(0).unwrap();
let mut slice_builder = SliceData::load_cell(builder).unwrap();
let addr = Deserializable::construct_from(&mut slice_builder)?;
let dapp_id = UInt256::construct_from(&mut slice_builder)?;
let dapp_id = UInt256::read_maybe_from(&mut slice_builder)?;
let builder2 = slice.reference(1).unwrap();
slice_builder = SliceData::load_cell(builder2).unwrap();
let storage_stat = Deserializable::construct_from(&mut slice_builder)?;
Expand All @@ -1180,7 +1180,7 @@ impl Account {
}
}

pub fn set_dapp_id(&mut self, dapp_id: UInt256) {
pub fn set_dapp_id(&mut self, dapp_id: Option<UInt256>) {
if let Some(s) = self.stuff_mut() {
s.dapp_id = dapp_id;
}
Expand Down Expand Up @@ -1422,7 +1422,7 @@ pub fn generate_test_account_by_init_code_hash(init_code_hash: bool) -> Account

let acc_st = AccountStorage::active_by_init_code_hash(0, balance, stinit, init_code_hash);
let addr = MsgAddressInt::with_standart(Some(anc), 0, acc_id).unwrap();
let mut account = Account::with_storage(&addr, UInt256::new(), &st_info, &acc_st);
let mut account = Account::with_storage(&addr, None, &st_info, &acc_st);
account.update_storage_stat().unwrap();
account
}
6 changes: 5 additions & 1 deletion tvm_block_json/src/serialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2080,7 +2080,11 @@ pub fn db_serialize_account_ex(
serialize_field(&mut map, "workchain_id", addr.get_workchain_id());
}
if let Some(dapp_id) = set.account.get_dapp_id() {
serialize_field(&mut map, "dapp_id", dapp_id.as_hex_string());
if let Some(dapp_id_in) = dapp_id {
serialize_field(&mut map, "dapp_id", dapp_id_in.as_hex_string());
} else {
serialize_field(&mut map, "dapp_id", "None".to_string());
}
}
serialize_field(&mut map, "boc", base64_encode(&set.boc));
if let Some(boc1) = set.boc1.as_ref() {
Expand Down
5 changes: 4 additions & 1 deletion tvm_cli/src/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,10 @@ pub async fn get_account(
.map_err(|e| format!("failed to load account from the boc: {}", e))?;
let dapp_id = account
.get_dapp_id()
.map(|id| id.to_hex_string())
.map(|id| match id {
Some(data) => data.to_hex_string(),
None => "None".to_string(),
})
.unwrap_or("None".to_string());
let ecc_balance = account
.balance()
Expand Down
9 changes: 3 additions & 6 deletions tvm_cli/src/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ use tvm_client::tvm::run_executor;
use tvm_client::tvm::AccountForExecutor;
use tvm_client::tvm::ParamsOfRunExecutor;
use tvm_types::base64_encode;
use tvm_types::UInt256;

use crate::config::Config;
use crate::convert;
Expand Down Expand Up @@ -135,11 +134,9 @@ pub async fn emulate_locally(
let addr = tvm_block::MsgAddressInt::from_str(addr)
.map_err(|e| format!("couldn't decode address: {}", e))?;
state = base64_encode(
&tvm_types::write_boc(
&Account::with_address(addr, UInt256::new()).serialize().map_err(|e| {
format!("couldn't create dummy account for deploy emulation: {}", e)
})?,
)
&tvm_types::write_boc(&Account::with_address(addr, None).serialize().map_err(
|e| format!("couldn't create dummy account for deploy emulation: {}", e),
)?)
.map_err(|e| format!("failed to serialize account cell: {}", e))?,
);
} else {
Expand Down
2 changes: 1 addition & 1 deletion tvm_cli/src/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -974,7 +974,7 @@ async fn debug_deploy_command(matches: &ArgMatches<'_>, config: &Config) -> Resu
let addr =
MsgAddressInt::with_standart(None, wc as i8, address).map_err(|e| format!("{}", e))?;
let balance = CurrencyCollection::with_grams(initial_balance);
Account::with_address_and_ballance(&addr, UInt256::new(), &balance)
Account::with_address_and_ballance(&addr, None, &balance)
} else {
let account = query_account_field(ton_client.clone(), &address, "boc").await?;
Account::construct_from_base64(&account)
Expand Down
Loading

0 comments on commit 4680831

Please sign in to comment.