Skip to content
Closed
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
1,856 changes: 1,022 additions & 834 deletions Cargo.lock

Large diffs are not rendered by default.

234 changes: 117 additions & 117 deletions Cargo.toml

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions gcli/src/keystore/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,14 @@ impl Key {
}

/// Verify messages
pub fn verify<P>(sig: &[u8], message: &[u8], pubkey: &[u8]) -> Result<bool>
pub fn verify<'a, P>(sig: &'a [u8], message: &[u8], pubkey: &'a [u8]) -> Result<bool>
where
P: Pair,
<P as gsdk::ext::sp_core::Pair>::Signature: TryFrom<&'a [u8]>,
<P as gsdk::ext::sp_core::Pair>::Public: TryFrom<&'a [u8]>,
{
Ok(P::verify_weak(sig, message, pubkey))
let pubkey = P::Public::try_from(pubkey).map_err(|_| Error::InvalidPublic)?;
let sig = P::Signature::try_from(sig).map_err(|_| Error::InvalidSignature)?;
Ok(P::verify(&sig, message, &pubkey))
}
}
2 changes: 2 additions & 0 deletions gcli/src/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ pub enum Error {
InvalidPassword,
#[error("Invalid public key")]
InvalidPublic,
#[error("Invalid signature")]
InvalidSignature,
#[error("Invalid secret key")]
InvalidSecret,
#[error(transparent)]
Expand Down
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
11 changes: 10 additions & 1 deletion gsdk/api-gen/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,20 @@ fn metadata() -> Vec<u8> {
let path = env::var(RUNTIME_WASM).expect("Missing RUNTIME_WASM env var.");
let code = fs::read(path).expect("Failed to read runtime wasm");

let heap_pages =
sc_executor_common::wasm_runtime::HeapAllocStrategy::Static { extra_pages: 1024 };

// 2. Create wasm executor.
let executor = sc_executor::WasmExecutor::<(
gear_ri::gear_ri::HostFunctions,
sp_io::SubstrateHostFunctions,
)>::new(WasmExecutionMethod::Interpreted, Some(1024), 8, None, 2);
)>::builder()
.with_execution_method(WasmExecutionMethod::Interpreted)
.with_onchain_heap_alloc_strategy(heap_pages)
.with_offchain_heap_alloc_strategy(heap_pages)
.with_max_runtime_instances(8)
.with_runtime_cache_size(2)
.build();

// 3. Extract metadata.
executor
Expand Down
Loading