Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(papi): Add a container crate #16

Merged
merged 45 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
ab9df56
rename
bitdivine Sep 18, 2024
5081985
comment
bitdivine Sep 18, 2024
2937dd6
Add vendor payment types
bitdivine Sep 18, 2024
4635bf0
comment
bitdivine Sep 18, 2024
795c5ee
Get cycles ledger canister ID at compile time
bitdivine Sep 18, 2024
fff3182
Get the cycles ledger canisyer ID at compile time
bitdivine Sep 18, 2024
d9fab77
++
bitdivine Sep 18, 2024
699ae18
++
bitdivine Sep 18, 2024
5c25f0a
++
bitdivine Sep 18, 2024
d257a45
++
bitdivine Sep 18, 2024
8b4d19b
++
bitdivine Sep 18, 2024
a180b92
++
bitdivine Sep 18, 2024
c0de934
++
bitdivine Sep 18, 2024
50f9317
++
bitdivine Sep 18, 2024
4173bde
++
bitdivine Sep 19, 2024
71b58cd
++
bitdivine Sep 19, 2024
0eae0c9
++
bitdivine Sep 19, 2024
8676e93
++
bitdivine Sep 19, 2024
ef32966
++
bitdivine Sep 19, 2024
0467889
++
bitdivine Sep 19, 2024
a8da054
++
bitdivine Sep 19, 2024
f24250b
++
bitdivine Sep 19, 2024
2c501ce
++
bitdivine Sep 19, 2024
988922a
++
bitdivine Sep 19, 2024
657cb30
Add option of paying with a specified ledger
bitdivine Sep 19, 2024
28e56f8
++
bitdivine Sep 19, 2024
08b29b8
++
bitdivine Sep 19, 2024
eddd550
++
bitdivine Sep 19, 2024
df6d814
++
bitdivine Sep 19, 2024
9803d61
++
bitdivine Sep 19, 2024
15e263d
++
bitdivine Sep 19, 2024
2812503
++
bitdivine Sep 19, 2024
7e3ea44
++
bitdivine Sep 19, 2024
7af63e4
++
bitdivine Sep 19, 2024
3406149
++
bitdivine Sep 19, 2024
d88022c
++
bitdivine Sep 19, 2024
0c12941
Quieter
bitdivine Sep 19, 2024
d21f5c4
Proper account encoding
bitdivine Sep 19, 2024
cb99505
++
bitdivine Sep 19, 2024
e2eb334
fmt
bitdivine Sep 19, 2024
49e4e17
++
bitdivine Sep 19, 2024
9568f3f
clippy
bitdivine Sep 19, 2024
a08261a
Document usage
bitdivine Sep 19, 2024
91f5ddc
Add container crate
bitdivine Sep 19, 2024
671970e
++
bitdivine Sep 19, 2024
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
8 changes: 8 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[workspace]
members = ["src/api", "src/declarations/cycles_ledger", "src/example/app_backend", "src/example/paid_service", "src/example/paid_service_api", "src/guard"]
members = ["src/api", "src/declarations/cycles_ledger", "src/example/app_backend", "src/example/paid_service", "src/example/paid_service_api", "src/guard", "src/papi"]
resolver = "2"

[workspace.dependencies]
Expand Down
7 changes: 7 additions & 0 deletions USAGE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Usage

## Creating a paid API

### Accept many payment types
- In your canister, you need to decide which payment types you wish to accept. In [this example](./src/example/paid_service/src/state.rs) a `PAYMENT_GUARD` is defined that accepts a variety of payment options.
- In the API methods, you need to [deduct payment](./src/example/paid_service/src/lib.rs) before doing work.
2 changes: 1 addition & 1 deletion src/example/paid_service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ async fn cost_1b_icrc2_from_caller() -> Result<String, PaymentError> {
Ok("Yes, you paid 1 billion cycles!".to_string())
}

/// An API method that requires 1 billion cycles.
/// An API method that requires 1 billion cycles, paid in whatever way the client chooses.
#[update()]
async fn cost_1b(payment: PaymentType) -> Result<String, PaymentError> {
let fee = 1_000_000_000;
Expand Down
9 changes: 9 additions & 0 deletions src/papi/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "ic-papi"
version = "0.1.0"
edition = "2021"
description = "Library for implementing Paid APIs on the Internet Computer"

[dependencies]
ic-papi-api = { workspace = true }
ic-papi-guard = { workspace = true }
2 changes: 2 additions & 0 deletions src/papi/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub use ic_papi_api as api;
pub use ic_papi_guard as guard;