4 个版本

0.1.3 2023 年 10 月 22 日
0.1.2 2023 年 10 月 8 日
0.1.1 2023 年 10 月 8 日
0.1.0 2023 年 10 月 8 日

#2663 in 神奇豆

每月 23 次下载

Apache-2.0

43KB
490

Credits SDK

Crates.io License

credits 包提供了一种管理 Aleo 网络上信用交易操作的接口。使用此包,您可以轻松生成、授权和执行与信用相关的交易,如转账、抵押、解押等。

特性

  • 简单交易:轻松在两个账户之间转账信用。
  • 抵押 & 验证人:将微信用抵押给验证人,控制验证人状态,并管理未解押的信用。

用法

首先,将 credits 添加到您的 Cargo.toml 依赖项

[dependencies]
credits = "0.1.3"

然后,将其集成到您的 Rust 代码中

use credits::Credits;

注意

此存储库正在积极开发中,可能会发生变化。

特别值得注意的是,此存储库目前尚不支持以下功能

  • 私人转账
  • 私人合并/拆分
  • 在执行交易之前检查费用是否足够

示例

bond_public

use credits::Credits;
use anyhow::Result;

fn main() -> Result<()> {
    let rng = &mut rand::thread_rng();

    let transaction = Credits::bond_public(
        "APrivateKey1zkpBdGzC71T2A3D4bfyuPnz5NyJNLhSx3VQxWRMcha3JYtp", // Staker's Private Key
        "aleo1r8ak4sfzpljs65lu0cgu6x4pvvq6atsdx268auu7nf6wvsv5fgqq6v5p0a", // Validator's Address
        10_000_000, // Amount (in microcredits)
        10_000, // Priority Fee (in microcredits)
        false, // Broadcast
        rng,
    )?.execute()?;
}

unbond_public

use credits::Credits;
use anyhow::Result;

fn main() -> Result<()> {
    let rng = &mut rand::thread_rng();

    let transaction = Credits::unbond_public(
        "APrivateKey1zkpBdGzC71T2A3D4bfyuPnz5NyJNLhSx3VQxWRMcha3JYtp", // Staker's Private Key
        10_000_000, // Amount (in microcredits)
        10_000, // Priority Fee (in microcredits)
        false, // Broadcast
        rng,
    )?.execute()?;
}

unbond_delegator_as_validator

use credits::Credits;
use anyhow::Result;

fn main() -> Result<()> {
    let rng = &mut rand::thread_rng();

    let transaction = Credits::unbond_delegator_as_validator(
        "APrivateKey1zkpBdGzC71T2A3D4bfyuPnz5NyJNLhSx3VQxWRMcha3JYtp", // Validator's Private Key
        "aleo1r8ak4sfzpljs65lu0cgu6x4pvvq6atsdx268auu7nf6wvsv5fgqq6v5p0a", // Delegator's Address
        10_000, // Priority Fee (in microcredits)
        false, // Broadcast
        rng,
    )?.execute()?;
}

claim_unbond_public

use credits::Credits;
use anyhow::Result;

fn main() -> Result<()> {
    let rng = &mut rand::thread_rng();

    let transaction = Credits::claim_unbond_public(
        "APrivateKey1zkpBdGzC71T2A3D4bfyuPnz5NyJNLhSx3VQxWRMcha3JYtp", // Staker's Private Key
        10_000, // Priority Fee (in microcredits)
        false, // Broadcast
        rng,
    )?.execute()?;
}

set_validator_state

use credits::Credits;
use anyhow::Result;

fn main() -> Result<()> {
    let rng = &mut rand::thread_rng();

    let transaction = Credits::set_validator_state(
        "APrivateKey1zkpBdGzC71T2A3D4bfyuPnz5NyJNLhSx3VQxWRMcha3JYtp", // Validator's Private Key
        true, // is_open
        10_000, // Priority Fee (in microcredits)
        false, // Broadcast
        rng,
    )?.execute()?;
}

transfer_public

use credits::Credits;
use anyhow::Result;

fn main() -> Result<()> {
    let rng = &mut rand::thread_rng();

    let transaction = Credits::transfer_public(
        "APrivateKey1zkpBdGzC71T2A3D4bfyuPnz5NyJNLhSx3VQxWRMcha3JYtp", // Sender's Private Key
        "aleo1r8ak4sfzpljs65lu0cgu6x4pvvq6atsdx268auu7nf6wvsv5fgqq6v5p0a", // Recipient's Address
        10_000_000, // Amount (in microcredits)
        10_000, // Priority Fee (in microcredits)
        false, // Broadcast
        rng,
    )?.execute()?;
}

transfer_public_to_private

use credits::Credits;
use anyhow::Result;

fn main() -> Result<()> {
    let rng = &mut rand::thread_rng();
    
    let transaction = Credits::transfer_public(
        "APrivateKey1zkpBdGzC71T2A3D4bfyuPnz5NyJNLhSx3VQxWRMcha3JYtp", // Sender's Private Key
        "aleo1r8ak4sfzpljs65lu0cgu6x4pvvq6atsdx268auu7nf6wvsv5fgqq6v5p0a", // Recipient's Address
        10_000_000, // Amount (in microcredits)
        10_000, // Priority Fee (in microcredits)
        false, // Broadcast
        rng,
    )?.execute()?;
}

测试

此包为 credits 程序中的每个函数提供了一组全面的测试。

使用以下命令运行测试

cargo test

贡献

欢迎拉取请求。对于重大更改,请先打开一个问题来讨论预期的更改。

依赖项

~7–20MB
~292K SLoC