3 个版本

0.0.3 2022 年 3 月 13 日
0.0.2 2022 年 3 月 13 日
0.0.1 2022 年 3 月 2 日

#4 in #lightning-network

自定义许可证

1.5MB
1.5K SLoC

Strike 闪电 API 接口(非官方)

Rust 对 Strike 优秀闪电网络 API 的接口。轻松地将闪电打赏或支付添加到任何应用程序中。

如果您没有 API 密钥,请在 Strike 上申请一个。在您的应用程序中使用具有现有 strike 账户的电子邮件地址,以便快速批准。

打赏示例

使用 Strike API 向某人或甚至自己打赏非常简单。

完整的打赏示例代码

Cargo.toml

[dependencies]
# For this example you must include the tipping feature
strike-api = { version = "0.0.3", features = ["tipping"] }
# Any qrcode generation library
qrcode-generator = {version = "4.1.2"}
# Any multi-threading library
tokio = {version = "1.17.0", features = ["full"]}

main.rs

use strike_api::tipping::{tipping_request};
extern crate qrcode_generator;
use qrcode_generator::{QrCodeEcc};

// Currently I only have a async version of tipping
#[tokio::main]
async fn main() {

    let api_key = "<Your API KEY>";
    //This is the account handle of the account you want to tip. Can be your own account or another account
    let account_handle = "magog";
    //This is the amount you want to tip
    let amount = 1.0;
    //The currency the amount is specified in
    let currency = "USD";
    
    //Call the strike api to get a lightning invoice
    let tipping_quote = tipping_request(
        (api_key, account_handle, amount, currency)
    ).await;

    //Check if the request was successful
    match tipping_quote {
        Ok(quote) => {
            create_qrcode(quote.ln_invoice);
        },
        Err(error) => {
            println!("{:?}", error);
        }
    }
}

fn create_qrcode(ln_invoice : String) {
    //Create a qrcode from the ln_invoice,
    match qrcode_generator::to_png_to_file(ln_invoice.clone(), QrCodeEcc::Low, 1024, "ln_qrcode.png") {
        Ok(_) => {
            println!("QR Code created successfully for invoice: {}", ln_invoice);
        },
        Err(error) => {
            println!("Error creating QR Code: {:?}", error);
        }
    }
}

这将生成一个可支付的闪电发票,并将其保存为 png 格式的二维码。

依赖项

~0–14MB
~146K SLoC