diff --git a/Cargo.lock b/Cargo.lock index 3e1fdfb..da77697 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -656,6 +656,14 @@ dependencies = [ "sha2", ] +[[package]] +name = "ic-papi" +version = "0.1.0" +dependencies = [ + "ic-papi-api", + "ic-papi-guard", +] + [[package]] name = "ic-papi-api" version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml index 9565c42..300b88c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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] diff --git a/USAGE.md b/USAGE.md new file mode 100644 index 0000000..3bc69b4 --- /dev/null +++ b/USAGE.md @@ -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. \ No newline at end of file diff --git a/src/example/paid_service/src/lib.rs b/src/example/paid_service/src/lib.rs index 178e9ab..3678f56 100644 --- a/src/example/paid_service/src/lib.rs +++ b/src/example/paid_service/src/lib.rs @@ -40,7 +40,7 @@ async fn cost_1b_icrc2_from_caller() -> Result { 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 { let fee = 1_000_000_000; diff --git a/src/papi/Cargo.toml b/src/papi/Cargo.toml new file mode 100644 index 0000000..4f5e7bf --- /dev/null +++ b/src/papi/Cargo.toml @@ -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 } diff --git a/src/papi/src/lib.rs b/src/papi/src/lib.rs new file mode 100644 index 0000000..ec79b84 --- /dev/null +++ b/src/papi/src/lib.rs @@ -0,0 +1,2 @@ +pub use ic_papi_api as api; +pub use ic_papi_guard as guard;