Skip to content

Commit

Permalink
fix RPC document issue
Browse files Browse the repository at this point in the history
  • Loading branch information
chenyukang committed Jan 11, 2025
1 parent 5e41a5e commit c9a4268
Show file tree
Hide file tree
Showing 9 changed files with 390 additions and 307 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ 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)
/Users/yukang/code/rpc-doc-gen/target/debug/fiber-rpc-gen ./src/
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
646 changes: 369 additions & 277 deletions src/rpc/README.md

Large diffs are not rendered by default.

26 changes: 1 addition & 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

0 comments on commit c9a4268

Please sign in to comment.