diff --git a/Cargo.lock b/Cargo.lock index 8ae5e0aa99..037f7a26da 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1510,6 +1510,7 @@ version = "0.1.0" dependencies = [ "candid", "ic-cdk 0.16.0", + "ic-cycles-ledger-types", "serde", "serde_bytes", ] diff --git a/src/cycles_ledger/client/src/lib.rs b/src/cycles_ledger/client/src/lib.rs index ccaa2ce459..3ea5960228 100644 --- a/src/cycles_ledger/client/src/lib.rs +++ b/src/cycles_ledger/client/src/lib.rs @@ -4,421 +4,7 @@ use candid::{self, CandidType, Deserialize, Principal}; use ic_cdk::api::call::CallResult as Result; -#[derive(CandidType, Deserialize, Debug, Clone)] -pub enum ChangeIndexId { - SetTo(Principal), - Unset, -} -#[derive(CandidType, Deserialize, Debug, Clone)] -pub struct UpgradeArgs { - pub change_index_id: Option, - pub max_blocks_per_request: Option, -} -#[derive(CandidType, Deserialize, Debug, Clone)] -pub struct InitArgs { - pub index_id: Option, - pub max_blocks_per_request: u64, -} -#[derive(CandidType, Deserialize, Debug, Clone)] -pub enum LedgerArgs { - Upgrade(Option), - Init(InitArgs), -} -#[derive(CandidType, Deserialize, Debug, Clone)] -pub struct SubnetFilter { - pub subnet_type: Option, -} -#[derive(CandidType, Deserialize, Debug, Clone)] -pub enum SubnetSelection { - Filter(SubnetFilter), - Subnet { subnet: Principal }, -} -#[derive(CandidType, Deserialize, Debug, Clone)] -pub struct CanisterSettings { - pub freezing_threshold: Option, - pub controllers: Option>, - pub reserved_cycles_limit: Option, - pub memory_allocation: Option, - pub compute_allocation: Option, -} -#[derive(CandidType, Deserialize, Debug, Clone)] -pub struct CmcCreateCanisterArgs { - pub subnet_selection: Option, - pub settings: Option, -} -#[derive(CandidType, Deserialize, Debug, Clone)] -pub struct CreateCanisterArgs { - pub from_subaccount: Option, - pub created_at_time: Option, - pub amount: candid::Nat, - pub creation_args: Option, -} -pub type BlockIndex = candid::Nat; -#[derive(CandidType, Deserialize, Debug, Clone)] -pub struct CreateCanisterSuccess { - pub block_id: BlockIndex, - pub canister_id: Principal, -} -#[derive(CandidType, Deserialize, Debug, Clone)] -pub enum CreateCanisterError { - GenericError { - message: String, - error_code: candid::Nat, - }, - TemporarilyUnavailable, - Duplicate { - duplicate_of: candid::Nat, - canister_id: Option, - }, - CreatedInFuture { - ledger_time: u64, - }, - FailedToCreate { - error: String, - refund_block: Option, - fee_block: Option, - }, - TooOld, - InsufficientFunds { - balance: candid::Nat, - }, -} -#[derive(CandidType, Deserialize, Debug, Clone, Eq, PartialEq)] -pub struct Account { - pub owner: Principal, - pub subaccount: Option, -} -#[derive(CandidType, Deserialize, Debug, Clone)] -pub struct CreateCanisterFromArgs { - pub spender_subaccount: Option, - pub from: Account, - pub created_at_time: Option, - pub amount: candid::Nat, - pub creation_args: Option, -} -#[derive(CandidType, Deserialize, Debug, Clone, Eq, PartialEq)] -pub enum RejectionCode { - NoError, - CanisterError, - SysTransient, - DestinationInvalid, - Unknown, - SysFatal, - CanisterReject, -} -#[derive(CandidType, Deserialize, Debug, Clone)] -pub enum CreateCanisterFromError { - FailedToCreateFrom { - create_from_block: Option, - rejection_code: RejectionCode, - refund_block: Option, - approval_refund_block: Option, - rejection_reason: String, - }, - GenericError { - message: String, - error_code: candid::Nat, - }, - TemporarilyUnavailable, - InsufficientAllowance { - allowance: candid::Nat, - }, - Duplicate { - duplicate_of: candid::Nat, - canister_id: Option, - }, - CreatedInFuture { - ledger_time: u64, - }, - TooOld, - InsufficientFunds { - balance: candid::Nat, - }, -} -#[derive(CandidType, Deserialize, Debug, Clone)] -pub struct DepositArgs { - pub to: Account, - pub memo: Option, -} -#[derive(CandidType, Deserialize, Debug, Clone)] -pub struct DepositResult { - pub balance: candid::Nat, - pub block_index: BlockIndex, -} -#[derive(CandidType, Deserialize, Debug, Clone)] -pub struct HttpRequest { - pub url: String, - pub method: String, - pub body: serde_bytes::ByteBuf, - pub headers: Vec<(String, String)>, -} -#[derive(CandidType, Deserialize, Debug, Clone)] -pub struct HttpResponse { - pub body: serde_bytes::ByteBuf, - pub headers: Vec<(String, String)>, - pub status_code: u16, -} -#[derive(CandidType, Deserialize, Debug, Clone)] -pub enum MetadataValue { - Int(candid::Int), - Nat(candid::Nat), - Blob(serde_bytes::ByteBuf), - Text(String), -} -#[derive(CandidType, Deserialize, Debug, Clone)] -pub struct SupportedStandard { - pub url: String, - pub name: String, -} -#[derive(CandidType, Deserialize, Debug, Clone)] -pub struct TransferArgs { - pub to: Account, - pub fee: Option, - pub memo: Option, - pub from_subaccount: Option, - pub created_at_time: Option, - pub amount: candid::Nat, -} -#[derive(CandidType, Deserialize, Debug, Clone)] -pub enum TransferError { - GenericError { - message: String, - error_code: candid::Nat, - }, - TemporarilyUnavailable, - BadBurn { - min_burn_amount: candid::Nat, - }, - Duplicate { - duplicate_of: candid::Nat, - }, - BadFee { - expected_fee: candid::Nat, - }, - CreatedInFuture { - ledger_time: u64, - }, - TooOld, - InsufficientFunds { - balance: candid::Nat, - }, -} -#[derive(CandidType, Deserialize, Debug, Clone)] -pub struct AllowanceArgs { - pub account: Account, - pub spender: Account, -} -#[derive(CandidType, Deserialize, Debug, Clone)] -pub struct Allowance { - pub allowance: candid::Nat, - pub expires_at: Option, -} -#[derive(CandidType, Deserialize, Debug, Clone)] -pub struct ApproveArgs { - pub fee: Option, - pub memo: Option, - pub from_subaccount: Option, - pub created_at_time: Option, - pub amount: candid::Nat, - pub expected_allowance: Option, - pub expires_at: Option, - pub spender: Account, -} -#[derive(CandidType, Deserialize, Debug, Clone, Eq, PartialEq)] -pub enum ApproveError { - GenericError { - message: String, - error_code: candid::Nat, - }, - TemporarilyUnavailable, - Duplicate { - duplicate_of: candid::Nat, - }, - BadFee { - expected_fee: candid::Nat, - }, - AllowanceChanged { - current_allowance: candid::Nat, - }, - CreatedInFuture { - ledger_time: u64, - }, - TooOld, - Expired { - ledger_time: u64, - }, - InsufficientFunds { - balance: candid::Nat, - }, -} -#[derive(CandidType, Deserialize, Debug, Clone)] -pub struct TransferFromArgs { - pub to: Account, - pub fee: Option, - pub spender_subaccount: Option, - pub from: Account, - pub memo: Option, - pub created_at_time: Option, - pub amount: candid::Nat, -} -#[derive(CandidType, Deserialize, Debug, Clone)] -pub enum TransferFromError { - GenericError { - message: String, - error_code: candid::Nat, - }, - TemporarilyUnavailable, - InsufficientAllowance { - allowance: candid::Nat, - }, - BadBurn { - min_burn_amount: candid::Nat, - }, - Duplicate { - duplicate_of: candid::Nat, - }, - BadFee { - expected_fee: candid::Nat, - }, - CreatedInFuture { - ledger_time: u64, - }, - TooOld, - InsufficientFunds { - balance: candid::Nat, - }, -} -#[derive(CandidType, Deserialize, Debug, Clone)] -pub struct GetArchivesArgs { - pub from: Option, -} -#[derive(CandidType, Deserialize, Debug, Clone)] -pub struct GetArchivesResultItem { - pub end: candid::Nat, - pub canister_id: Principal, - pub start: candid::Nat, -} -pub type GetArchivesResult = Vec; -#[derive(CandidType, Deserialize, Debug, Clone)] -pub struct GetBlocksArgsItem { - pub start: candid::Nat, - pub length: candid::Nat, -} -pub type GetBlocksArgs = Vec; -#[derive(CandidType, Deserialize, Debug, Clone)] -pub enum Value { - Int(candid::Int), - Map(Vec<(String, Box)>), - Nat(candid::Nat), - Nat64(u64), - Blob(serde_bytes::ByteBuf), - Text(String), - Array(Vec>), -} -#[derive(CandidType, Deserialize, Debug, Clone)] -pub struct GetBlocksResultBlocksItem { - pub id: candid::Nat, - pub block: Box, -} -candid::define_function!(pub GetBlocksResultArchivedBlocksItemCallback : ( - GetBlocksArgs, - ) -> (GetBlocksResult) query); -#[derive(CandidType, Deserialize, Debug, Clone)] -pub struct GetBlocksResultArchivedBlocksItem { - pub args: GetBlocksArgs, - pub callback: GetBlocksResultArchivedBlocksItemCallback, -} -#[derive(CandidType, Deserialize, Debug, Clone)] -pub struct GetBlocksResult { - pub log_length: candid::Nat, - pub blocks: Vec, - pub archived_blocks: Vec, -} -#[derive(CandidType, Deserialize, Debug, Clone)] -pub struct DataCertificate { - pub certificate: serde_bytes::ByteBuf, - pub hash_tree: serde_bytes::ByteBuf, -} -#[derive(CandidType, Deserialize, Debug, Clone)] -pub struct SupportedBlockType { - pub url: String, - pub block_type: String, -} -#[derive(CandidType, Deserialize, Debug, Clone)] -pub struct WithdrawArgs { - pub to: Principal, - pub from_subaccount: Option, - pub created_at_time: Option, - pub amount: candid::Nat, -} -#[derive(CandidType, Deserialize, Debug, Clone)] -pub enum WithdrawError { - FailedToWithdraw { - rejection_code: RejectionCode, - fee_block: Option, - rejection_reason: String, - }, - GenericError { - message: String, - error_code: candid::Nat, - }, - TemporarilyUnavailable, - Duplicate { - duplicate_of: candid::Nat, - }, - BadFee { - expected_fee: candid::Nat, - }, - InvalidReceiver { - receiver: Principal, - }, - CreatedInFuture { - ledger_time: u64, - }, - TooOld, - InsufficientFunds { - balance: candid::Nat, - }, -} -#[derive(CandidType, Deserialize, Debug, Clone)] -pub struct WithdrawFromArgs { - pub to: Principal, - pub spender_subaccount: Option, - pub from: Account, - pub created_at_time: Option, - pub amount: candid::Nat, -} -#[derive(CandidType, Deserialize, Debug, Clone, Eq, PartialEq)] -pub enum WithdrawFromError { - GenericError { - message: String, - error_code: candid::Nat, - }, - TemporarilyUnavailable, - InsufficientAllowance { - allowance: candid::Nat, - }, - Duplicate { - duplicate_of: BlockIndex, - }, - InvalidReceiver { - receiver: Principal, - }, - CreatedInFuture { - ledger_time: u64, - }, - TooOld, - FailedToWithdrawFrom { - withdraw_from_block: Option, - rejection_code: RejectionCode, - refund_block: Option, - approval_refund_block: Option, - rejection_reason: String, - }, - InsufficientFunds { - balance: candid::Nat, - }, -} +pub use ic_cycles_ledger_types::*; pub struct CyclesLedgerService(pub Principal); impl CyclesLedgerService {