Skip to content

Commit

Permalink
chore(gsdk): update transfer
Browse files Browse the repository at this point in the history
  • Loading branch information
ukint-vs committed Apr 17, 2024
1 parent 1aaa313 commit e229668
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 12 deletions.
2 changes: 1 addition & 1 deletion gcli/src/cmd/transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl Transfer {
println!("Value: {}", self.value);

let addr: [u8; 32] = AccountId32::from_ss58check(&self.destination)?.into();
signer.transfer(addr.into(), self.value).await?;
signer.transfer_allow_death(addr.into(), self.value).await?;

Ok(())
}
Expand Down
8 changes: 6 additions & 2 deletions gclient/src/api/calls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,14 @@ impl GearApi {
/// extrinsic.
///
/// This function returns a hash of the block with the transfer transaction.
pub async fn transfer(&self, destination: ProgramId, value: u128) -> Result<H256> {
pub async fn transfer_allow_death(&self, destination: ProgramId, value: u128) -> Result<H256> {
let destination: [u8; 32] = destination.into();

let tx = self.0.calls.transfer(destination, value).await?;
let tx = self
.0
.calls
.transfer_allow_death(destination, value)
.await?;

for event in tx.wait_for_success().await?.iter() {
if let Event::Balances(BalancesEvent::Transfer { .. }) =
Expand Down
2 changes: 1 addition & 1 deletion gclient/tests/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ async fn program_migrated_to_another_node() {

// Transfer some funds to the source program
src_node_api
.transfer(src_program_id, PROGRAM_FUNDS)
.transfer_allow_death(src_program_id, PROGRAM_FUNDS)
.await
.expect("Unable to transfer funds to source program");

Expand Down
2 changes: 1 addition & 1 deletion gsdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ async fn main() {
let signer = Api::new(None).signer("//Alice", None);

// Transaction with block details.
let tx = signer.transfer("//Bob", 42).await.expect("Transfer value failed.");
let tx = signer.transfer_allow_death("//Bob", 42).await.expect("Transfer value failed.");

// Fetch all of the events associated with this transaction.
for events in tx.fetch_events().await {
Expand Down
10 changes: 7 additions & 3 deletions gsdk/src/signer/calls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,15 @@ pub struct SignerCalls(pub(crate) Arc<Inner>);

// pallet-balances
impl SignerCalls {
/// `pallet_balances::transfer`
pub async fn transfer(&self, dest: impl Into<AccountId32>, value: u128) -> Result<TxInBlock> {
/// `pallet_balances::transfer_allow_death`
pub async fn transfer_allow_death(
&self,
dest: impl Into<AccountId32>,
value: u128,
) -> Result<TxInBlock> {
self.0
.run_tx(
BalancesCall::Transfer,
BalancesCall::TransferAllowDeath,
vec![
Value::unnamed_variant("Id", [Value::from_bytes(dest.into())]),
Value::u128(value),
Expand Down
4 changes: 2 additions & 2 deletions gsdk/src/signer/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,13 +177,13 @@ impl Inner {
/// Value::unnamed_variant("Id", [Value::from_bytes(dest.into())]),
/// Value::u128(value),
/// ];
/// let in_block = signer.run_tx(BalancesCall::Transfer, args).await?;
/// let in_block = signer.run_tx(BalancesCall::TransferAllowDeath, args).await?;
/// }
///
/// // The code above euqals to:
///
/// {
/// let in_block = signer.calls.transfer(dest, value).await?;
/// let in_block = signer.calls.transfer_allow_death(dest, value).await?;
/// }
///
/// // ...
Expand Down
2 changes: 1 addition & 1 deletion gsdk/tests/backtrace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ async fn transfer_backtrace() -> Result<()> {
let signer = Signer::new(api, "//Alice", None)?;
let alice: [u8; 32] = *alice_account_id().as_ref();

let tx = signer.calls.transfer(alice, 42).await?;
let tx = signer.calls.transfer_allow_death(alice, 42).await?;
let backtrace = signer
.backtrace()
.get(tx.extrinsic_hash())
Expand Down
2 changes: 1 addition & 1 deletion utils/node-loader/src/batch_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ async fn create_renew_balance_task(
e
})?;
root_api
.transfer(ProgramId::from(user_address.as_ref()), user_balance_demand)
.transfer_allow_death(ProgramId::from(user_address.as_ref()), user_balance_demand)
.await
.map_err(|e| {
tracing::debug!("Failed to transfer to user address: {e}");
Expand Down

0 comments on commit e229668

Please sign in to comment.