Skip to content

Commit

Permalink
Merge pull request #513 from jjyr/public-rpc-structs
Browse files Browse the repository at this point in the history
chore: public RPC structs
  • Loading branch information
quake authored Feb 25, 2025
2 parents 5523a93 + 745736d commit 1169b85
Show file tree
Hide file tree
Showing 10 changed files with 234 additions and 234 deletions.
2 changes: 1 addition & 1 deletion src/fiber/serde_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ macro_rules! uint_as_hex {
pub $name,
$ty,
|u: &$ty| format!("0x{:x}", u),
|hex: &str| -> Result<$ty, String> {
|hex: String| -> Result<$ty, String> {
let bytes = hex.as_bytes();
if bytes.len() < 3 || &bytes[..2] != b"0x" {
return Err(format!("uint hex string does not start with 0x: {}", hex));
Expand Down
68 changes: 34 additions & 34 deletions src/rpc/cch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,103 +16,103 @@ use serde::{Deserialize, Serialize};
use serde_with::serde_as;

#[derive(Serialize, Deserialize)]
pub(crate) struct SendBtcParams {
pub struct SendBtcParams {
/// Bitcoin payment request string
btc_pay_req: String,
pub btc_pay_req: String,
/// Request currency
currency: Currency,
pub currency: Currency,
}

#[serde_as]
#[derive(Debug, Clone, Serialize, Deserialize)]
pub(crate) struct SendBTCResponse {
pub struct SendBTCResponse {
/// Seconds since epoch when the order is created
#[serde_as(as = "U64Hex")]
timestamp: u64,
pub timestamp: u64,
/// Seconds after timestamp that the order expires
#[serde_as(as = "U64Hex")]
expiry: u64,
pub expiry: u64,
/// The minimal expiry in seconds of the final TLC in the CKB network
#[serde_as(as = "U64Hex")]
ckb_final_tlc_expiry_delta: u64,
pub ckb_final_tlc_expiry_delta: u64,

/// Request currency
currency: Currency,
pub currency: Currency,
/// Wrapped BTC type script
wrapped_btc_type_script: ckb_jsonrpc_types::Script,
pub wrapped_btc_type_script: ckb_jsonrpc_types::Script,

/// Payment request for BTC
btc_pay_req: String,
pub btc_pay_req: String,
/// Payment request for CKB
ckb_pay_req: String,
pub ckb_pay_req: String,
/// Payment hash for the HTLC for both CKB and BTC.
payment_hash: String,
pub payment_hash: String,
/// Amount required to pay in Satoshis, including fee
#[serde_as(as = "U128Hex")]
amount_sats: u128,
pub amount_sats: u128,
/// Fee in Satoshis
#[serde_as(as = "U128Hex")]
fee_sats: u128,
pub fee_sats: u128,
/// Order status
status: CchOrderStatus,
pub status: CchOrderStatus,
}

#[serde_as]
#[derive(Serialize, Deserialize)]
pub(crate) struct ReceiveBtcParams {
pub struct ReceiveBtcParams {
/// Payment hash for the HTLC for both CKB and BTC.
payment_hash: String,
pub payment_hash: String,
/// Channel ID for the CKB payment.
channel_id: Hash256,
pub channel_id: Hash256,
/// How many satoshis to receive, excluding cross-chain hub fee.
#[serde_as(as = "U128Hex")]
amount_sats: u128,
pub amount_sats: u128,
/// Expiry set for the HTLC for the CKB payment to the payee.
#[serde_as(as = "U64Hex")]
final_tlc_expiry: u64,
pub final_tlc_expiry: u64,
}

#[derive(Serialize, Deserialize)]
pub(crate) struct GetReceiveBtcOrderParams {
pub struct GetReceiveBtcOrderParams {
/// Payment hash for the HTLC for both CKB and BTC.
payment_hash: String,
pub payment_hash: String,
}

#[serde_as]
#[derive(Debug, Clone, Serialize, Deserialize)]
pub(crate) struct ReceiveBTCResponse {
pub struct ReceiveBTCResponse {
/// Seconds since epoch when the order is created
#[serde_as(as = "U64Hex")]
timestamp: u64,
pub timestamp: u64,
/// Seconds after timestamp that the order expires
#[serde_as(as = "U64Hex")]
expiry: u64,
pub expiry: u64,
/// The minimal expiry in seconds of the final TLC in the CKB network
#[serde_as(as = "U64Hex")]
ckb_final_tlc_expiry_delta: u64,
pub ckb_final_tlc_expiry_delta: u64,

/// Wrapped BTC type script
wrapped_btc_type_script: ckb_jsonrpc_types::Script,
pub wrapped_btc_type_script: ckb_jsonrpc_types::Script,

/// Payment request for BTC
btc_pay_req: String,
pub btc_pay_req: String,
/// Payment hash for the HTLC for both CKB and BTC.
payment_hash: String,
pub payment_hash: String,
/// Channel ID for the CKB payment.
channel_id: Hash256,
pub channel_id: Hash256,
/// TLC ID for the CKB payment.
#[serde_as(as = "Option<U64Hex>")]
tlc_id: Option<u64>,
pub tlc_id: Option<u64>,

/// Amount will be received by the payee
#[serde_as(as = "U128Hex")]
amount_sats: u128,
pub amount_sats: u128,
/// Fee in Satoshis
#[serde_as(as = "U128Hex")]
fee_sats: u128,
pub fee_sats: u128,

/// Order status
status: CchOrderStatus,
pub status: CchOrderStatus,
}

/// RPC module for cross chain hub demonstration.
Expand Down
Loading

0 comments on commit 1169b85

Please sign in to comment.