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

chore: Fix RPC document issues #467

Merged
merged 3 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ coverage: coverage-run-unittests coverage-collect-data coverage-generate-report

.PHONY: gen-rpc-doc
gen-rpc-doc:
$(if $(shell command -v fiber-rpc-gen),,cargo install fiber-rpc-gen --force)
fiber-rpc-gen ./src/rpc
$(if $(shell command -v fiber-rpc-gen),,cargo install fiber-rpc-gen --version 0.1.6 --force)
fiber-rpc-gen ./src/
if grep -q "TODO: add desc" ./src/rpc/README.md; then \
echo "Warning: There are 'TODO: add desc' in src/rpc/README.md, please add documentation comments to resolve them"; \
exit 1; \
Expand Down
1 change: 1 addition & 0 deletions src/cch/order.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use crate::{
invoice::{Currency, InvoiceBuilder},
};

/// The status of a cross-chain hub order, will update as the order progresses.
#[derive(Debug, Copy, Clone, Serialize, Deserialize, Eq, PartialEq)]
#[serde(rename_all = "snake_case")]
pub enum CchOrderStatus {
Expand Down
1 change: 1 addition & 0 deletions src/ckb/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ pub struct UdtArgInfo {
pub cell_deps: Vec<UdtCellDep>,
}

/// The UDT configurations
#[derive(Serialize, Deserialize, Clone, Debug, Default, Eq, PartialEq, Hash)]
pub struct UdtCfgInfos(pub Vec<UdtArgInfo>);

Expand Down
9 changes: 5 additions & 4 deletions src/fiber/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1126,15 +1126,16 @@ pub trait NetworkGraphStateStore {
fn get_payment_history_results(&self) -> Vec<(OutPoint, Direction, TimedResult)>;
}

/// The status of a payment, will update as the payment progresses.
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub enum PaymentSessionStatus {
// initial status, payment session is created, no HTLC is sent
/// initial status, payment session is created, no HTLC is sent
Created,
// the first hop AddTlc is sent successfully and waiting for the response
/// the first hop AddTlc is sent successfully and waiting for the response
Inflight,
// related HTLC is successfully settled
/// related HTLC is successfully settled
Success,
// related HTLC is failed
/// related HTLC is failed
Failed,
}

Expand Down
3 changes: 3 additions & 0 deletions src/fiber/hash_algorithm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@ use ckb_types::packed;
use serde::{Deserialize, Serialize};
use thiserror::Error;

/// HashAlgorithm is the hash algorithm used in the hash lock.
#[repr(u8)]
#[derive(Copy, Clone, Debug, PartialEq, Eq, Serialize, Deserialize, Default, Hash)]
#[serde(rename_all = "snake_case")]
pub enum HashAlgorithm {
/// The default hash algorithm, CkbHash
#[default]
CkbHash = 0,
/// The sha256 hash algorithm
Sha256 = 1,
}

Expand Down
2 changes: 2 additions & 0 deletions src/fiber/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ impl AsRef<[u8; 32]> for Privkey {
}
}

/// A 256-bit hash digest, used as identifier of channnel, payment, transaction hash etc.
#[serde_as]
#[derive(Copy, Clone, Serialize, Deserialize, Hash, Eq, PartialEq, Default)]
pub struct Hash256(#[serde_as(as = "SliceHex")] [u8; 32]);
Expand Down Expand Up @@ -267,6 +268,7 @@ impl Privkey {
}
}

/// The public key for a Node
#[derive(Copy, Clone, Debug, PartialOrd, Ord, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct Pubkey(pub PublicKey);

Expand Down
7 changes: 7 additions & 0 deletions src/invoice/invoice_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,11 @@ impl Display for CkbInvoiceStatus {
/// The currency of the invoice, can also used to represent the CKB network chain.
#[derive(Debug, Clone, Copy, Eq, PartialEq, Serialize, Deserialize)]
pub enum Currency {
/// The mainnet currency of CKB.
Fibb,
/// The testnet currency of the CKB network.
Fibt,
/// The devnet currency of the CKB network.
Fibd,
}

Expand Down Expand Up @@ -136,10 +139,14 @@ pub struct InvoiceData {
#[serde_as]
#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)]
pub struct CkbInvoice {
/// The currency of the invoice
pub currency: Currency,
#[serde_as(as = "Option<U128Hex>")]
/// The amount of the invoice
pub amount: Option<u128>,
/// The signature of the invoice
pub signature: Option<InvoiceSignature>,
/// The invoice data, including the payment hash, timestamp and other attributes
pub data: InvoiceData,
}

Expand Down
637 changes: 380 additions & 257 deletions src/rpc/README.md

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion src/rpc/cch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ pub(crate) struct ReceiveBTCResponse {
}

/// RPC module for cross chain hub demonstration.
/// This is the seccond line
#[rpc(server)]
trait CchRpc {
/// Send BTC to a address.
Expand Down
1 change: 1 addition & 0 deletions src/rpc/invoice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use serde_with::serde_as;
use std::time::Duration;
use tentacle::secio::SecioKeyPair;

/// The parameter struct for generating a new invoice.
#[serde_as]
#[derive(Serialize, Deserialize)]
pub(crate) struct NewInvoiceParams {
Expand Down
27 changes: 2 additions & 25 deletions src/rpc/payment.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::fiber::{
channel::ChannelActorStateStore,
graph::PaymentSessionStatus as InnerPaymentSessionStatus,
graph::PaymentSessionStatus,
network::{HopHint as NetworkHopHint, SendPaymentCommand},
serde_utils::{U128Hex, U64Hex},
types::{Hash256, Pubkey},
Expand All @@ -24,30 +24,6 @@ pub struct GetPaymentCommandParams {
pub payment_hash: Hash256,
}

/// The status of a payment, will update as the payment progresses.
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub enum PaymentSessionStatus {
/// initial status, payment session is created, no HTLC is sent
Created,
/// the first hop AddTlc is sent successfully and waiting for the response
Inflight,
/// related HTLC is successfully settled
Success,
/// related HTLC is failed
Failed,
}

impl From<InnerPaymentSessionStatus> for PaymentSessionStatus {
fn from(status: InnerPaymentSessionStatus) -> Self {
match status {
InnerPaymentSessionStatus::Created => PaymentSessionStatus::Created,
InnerPaymentSessionStatus::Inflight => PaymentSessionStatus::Inflight,
InnerPaymentSessionStatus::Success => PaymentSessionStatus::Success,
InnerPaymentSessionStatus::Failed => PaymentSessionStatus::Failed,
}
}
}

#[serde_as]
#[derive(Serialize, Deserialize, Clone)]
pub struct GetPaymentCommandResult {
Expand Down Expand Up @@ -130,6 +106,7 @@ pub(crate) struct SendPaymentCommandParams {
dry_run: Option<bool>,
}

/// A hop hint is a hint for a node to use a specific channel.
#[serde_as]
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct HopHint {
Expand Down
Loading