-
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.
refactor(api): Move code out of lib.rs (#12)
# Motivation The api lib.rs is going to become one large unmanageable mess very quickly if all the code is in one file. # Changes - Move api definitions into smaller files. # Tests See CI
- Loading branch information
Showing
7 changed files
with
98 additions
and
72 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
//! Types used primarily by the caller of the payment API. | ||
use candid::{CandidType, Deserialize, Principal}; | ||
pub use cycles_ledger_client::Account; | ||
|
||
/// How a caller states that they will pay. | ||
#[derive(Debug, CandidType, Deserialize, Copy, Clone, Eq, PartialEq)] | ||
#[non_exhaustive] | ||
pub enum PaymentType { | ||
/// The caller is paying with cycles attached to the call. | ||
/// | ||
/// Note: This is not available for ingress messages. | ||
/// | ||
/// Note: The API does not require additional arguments to support this payment type. | ||
AttachedCycles, | ||
/// The caller is paying with cycles from their main account on the cycles ledger. | ||
CallerIcrc2Cycles, | ||
/// A patron is paying, on behalf of the caller, from their main account on the cycles ledger. | ||
PatronIcrc2Cycles(Principal), | ||
} |
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,21 @@ | ||
//! Payment API error types. | ||
use candid::{CandidType, Deserialize, Principal}; | ||
pub use cycles_ledger_client::Account; | ||
use cycles_ledger_client::WithdrawFromError; | ||
|
||
#[derive(Debug, CandidType, Deserialize, Clone, Eq, PartialEq)] | ||
#[non_exhaustive] | ||
pub enum PaymentError { | ||
UnsupportedPaymentType, | ||
LedgerUnreachable { | ||
ledger: Principal, | ||
}, | ||
LedgerError { | ||
ledger: Principal, | ||
error: WithdrawFromError, | ||
}, | ||
InsufficientFunds { | ||
needed: u64, | ||
available: u64, | ||
}, | ||
} |
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
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,20 @@ | ||
//! Types used primartily by the vendor of the payment API. | ||
use candid::{CandidType, Deserialize, Principal}; | ||
pub use cycles_ledger_client::Account; | ||
|
||
/// User's payment details for an ICRC2 payment. | ||
#[derive(Debug, CandidType, Deserialize, Clone, Eq, PartialEq)] | ||
pub struct Icrc2Payer { | ||
/// The customer's principal and (optionally) subaccount. | ||
/// | ||
/// By default, the caller's main account is used. | ||
pub account: Option<Account>, | ||
/// The spender, if different from the payer. | ||
pub spender_subaccount: Option<serde_bytes::ByteBuf>, | ||
/// The ledger canister ID. | ||
/// | ||
/// Note: This is included in order to improve error messages if the caller tries to use the wrong ledger. | ||
pub ledger_canister_id: Option<Principal>, | ||
/// Corresponds to the `created_at_time` field in ICRC2. | ||
pub created_at_time: Option<u64>, | ||
} |
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
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
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