Skip to content

Commit

Permalink
update gclient
Browse files Browse the repository at this point in the history
  • Loading branch information
ukint-vs committed Aug 26, 2023
1 parent f4224ab commit c9523f6
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 47 deletions.
73 changes: 29 additions & 44 deletions gclient/src/api/calls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ use gsdk::{
event::{CodeChangeKind, MessageEntry},
ActiveProgram,
},
pallet_balances::{pallet::Call as BalancesCall, AccountData},
pallet_balances::{pallet::Call as BalancesCall, types::AccountData},
pallet_gear::pallet::Call as GearCall,
pallet_gear_bank::pallet::BankAccount,
sp_weights::weight_v2::Weight,
Expand Down Expand Up @@ -288,8 +288,8 @@ impl GearApi {
Ok(AccountData {
free: 0u128,
reserved: 0,
misc_frozen: 0,
fee_frozen: 0,
frozen: 0,
flags: gsdk::metadata::runtime_types::pallet_balances::types::ExtraFlags(0),
})
} else {
Err(e)
Expand All @@ -315,8 +315,8 @@ impl GearApi {
Ok(AccountData {
free: 0u128,
reserved: 0,
misc_frozen: 0,
fee_frozen: 0,
frozen: 0,
flags: gsdk::metadata::runtime_types::pallet_balances::types::ExtraFlags(0),
})
} else {
Err(e)
Expand Down Expand Up @@ -377,19 +377,14 @@ impl GearApi {

// Apply data to the target program
dest_node_api
.set_balance(
.force_set_balance(
dest_program_id.into_account_id(),
src_program_account_data.free,
src_program_account_data.reserved,
)
.await?;

dest_node_api
.set_balance(
crate::bank_address(),
src_bank_account_data.free,
src_bank_account_data.reserved,
)
.force_set_balance(crate::bank_address(), src_bank_account_data.free)
.await?;

dest_node_api
Expand Down Expand Up @@ -420,9 +415,6 @@ impl GearApi {
.await?;

for account_with_reserved_funds in accounts_with_reserved_funds {
let src_account_data = self
.account_data_at(account_with_reserved_funds, src_block_hash)
.await?;
let src_account_bank_data = self
.bank_data_at(account_with_reserved_funds, src_block_hash)
.await
Expand All @@ -441,9 +433,9 @@ impl GearApi {
if let Error::GearSDK(GsdkError::StorageNotFound) = e {
Ok(AccountData {
free: 0u128,
reserved: 0,
misc_frozen: 0,
fee_frozen: 0,
reserved: 0,
frozen: 0,
flags: gsdk::metadata::runtime_types::pallet_balances::types::ExtraFlags(0),
})
} else {
Err(e)
Expand All @@ -461,12 +453,9 @@ impl GearApi {
})?;

dest_node_api
.set_balance(
.force_set_balance(
account_with_reserved_funds.into_account_id(),
dest_account_data.free,
dest_account_data
.reserved
.saturating_add(src_account_data.reserved),
)
.await?;

Expand Down Expand Up @@ -556,21 +545,20 @@ impl GearApi {
})
.collect();

let program_account_data =
self.account_data_at(program_id, block_hash)
.await
.or_else(|e| {
if let Error::GearSDK(GsdkError::StorageNotFound) = e {
Ok(AccountData {
free: 0u128,
reserved: 0,
misc_frozen: 0,
fee_frozen: 0,
})
} else {
Err(e)
}
})?;
let program_account_data = self.account_data_at(program_id, block_hash).await.or_else(
|e| {
if let Error::GearSDK(GsdkError::StorageNotFound) = e {
Ok(AccountData {
free: 0u128,
reserved: 0,
frozen: 0,
flags: gsdk::metadata::runtime_types::pallet_balances::types::ExtraFlags(0),
})
} else {
Err(e)
}
},
)?;

ProgramMemoryDump {
pages: program_pages,
Expand All @@ -596,10 +584,9 @@ impl GearApi {
.map(|(page_number, page_data)| (page_number.raw(), page_data.encode()))
.collect::<HashMap<_, _>>();

self.set_balance(
self.force_set_balance(
MultiAddress::Id(program_id.into_account_id()),
memory_dump.balance,
memory_dump.reserved_balance,
)
.await?;

Expand Down Expand Up @@ -1306,23 +1293,21 @@ impl GearApi {
self.set_code_without_checks(code).await
}

/// Set the free and reserved balance of the `to` account to `new_free` and
/// Set the free balance of the `to` account to `new_free` and
/// `new_reserved` respectively.
///
/// Sends the [`pallet_balances::set_balance`](https://crates.parity.io/pallet_balances/pallet/struct.Pallet.html#method.set_balance) extrinsic.
pub async fn set_balance(
pub async fn force_set_balance(
&self,
to: impl Into<MultiAddress<AccountId32, ()>>,
new_free: u128,
new_reserved: u128,
) -> Result<H256> {
let events = self
.0
.sudo_unchecked_weight(
RuntimeCall::Balances(BalancesCall::set_balance {
RuntimeCall::Balances(BalancesCall::force_set_balance {
who: to.into().convert(),
new_free,
new_reserved,
}),
Weight {
ref_time: 0,
Expand Down
2 changes: 1 addition & 1 deletion gclient/src/api/storage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use gsdk::{
ext::sp_core::{crypto::Ss58Codec, H256},
metadata::runtime_types::{
gear_common::storage::primitives::Interval, gear_core::message::user,
pallet_balances::AccountData, pallet_gear_bank::pallet::BankAccount,
pallet_balances::types::AccountData, pallet_gear_bank::pallet::BankAccount,
},
};

Expand Down
3 changes: 1 addition & 2 deletions utils/node-loader/src/batch_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -409,10 +409,9 @@ async fn create_renew_balance_task(
// Reserved balance mustn't be changed as it can cause runtime panics within reserving
// or unreserving funds logic.
root_api
.set_balance(
.force_set_balance(
root_address.clone(),
root_target_balance + user_balance_demand,
0,
)
.await
.map_err(|e| {
Expand Down

0 comments on commit c9523f6

Please sign in to comment.