-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
87 additions
and
465 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
scripts/bind.cycles_wallet.sh → scripts/bind.cycles_depositor.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
didc bind --target rs --config didc.toml .dfx/local/canisters/cycles_wallet/cycles_wallet.did | ||
didc bind --target rs --config didc.toml .dfx/local/canisters/cycles_depositor/cycles_depositor.did |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
src/example/paid_service/tests/it/util/cycles_depositor.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#![allow(dead_code, unused_imports)] | ||
use std::sync::Arc; | ||
|
||
use candid::{self, CandidType, Deserialize, Principal}; | ||
use ic_cdk::api::call::CallResult as Result; | ||
use pocket_ic::PocketIc; | ||
|
||
use super::pic_canister::{PicCanister, PicCanisterTrait}; | ||
|
||
#[derive(CandidType, Deserialize, Debug)] | ||
pub(crate) struct InitArg { pub(crate) ledger_id: Principal } | ||
#[derive(CandidType, Deserialize, Debug)] | ||
pub(crate) struct Account { | ||
pub(crate) owner: Principal, | ||
pub(crate) subaccount: Option<serde_bytes::ByteBuf>, | ||
} | ||
#[derive(CandidType, Deserialize, Debug)] | ||
pub(crate) struct DepositArg { | ||
pub(crate) to: Account, | ||
pub(crate) memo: Option<serde_bytes::ByteBuf>, | ||
pub(crate) cycles: candid::Nat, | ||
} | ||
#[derive(CandidType, Deserialize, Debug)] | ||
pub(crate) struct DepositResult { | ||
pub(crate) balance: candid::Nat, | ||
pub(crate) block_index: candid::Nat, | ||
} | ||
|
||
pub struct Service(pub Principal); | ||
impl Service { | ||
pub async fn deposit(&self, arg0: &DepositArg) -> Result<(DepositResult,)> { | ||
ic_cdk::call(self.0, "deposit", (arg0,)).await | ||
} | ||
} | ||
|
||
pub struct CyclesDepositorPic { | ||
pub pic: Arc<PocketIc>, | ||
pub canister_id: Principal, | ||
} | ||
|
||
impl From<PicCanister> for CyclesDepositorPic { | ||
fn from(pic: PicCanister) -> Self { | ||
Self { | ||
pic: pic.pic(), | ||
canister_id: pic.canister_id(), | ||
} | ||
} | ||
} | ||
|
||
impl PicCanisterTrait for CyclesDepositorPic { | ||
/// The shared PocketIc instance. | ||
fn pic(&self) -> Arc<PocketIc> { | ||
self.pic.clone() | ||
} | ||
/// The ID of this canister. | ||
fn canister_id(&self) -> Principal { | ||
self.canister_id.clone() | ||
} | ||
} | ||
|
||
impl CyclesDepositorPic { | ||
pub fn deposit(&self, caller: Principal, arg0: &DepositArg) -> std::result::Result<DepositResult, String> { | ||
self.update(self.canister_id, "deposit", (arg0,)) | ||
} | ||
} | ||
|
Oops, something went wrong.