Skip to main content

fiber_json_types/
dev.rs

1//! Development/debug types for the Fiber Network JSON-RPC API.
2
3use crate::invoice::HashAlgorithm;
4use crate::schema_helpers::*;
5use crate::serde_utils::{Hash256, U128Hex, U64Hex};
6use schemars::JsonSchema;
7use serde::{Deserialize, Serialize};
8use serde_with::serde_as;
9
10/// Parameters for sending a commitment_signed message.
11#[derive(Serialize, Deserialize, Debug, JsonSchema)]
12pub struct CommitmentSignedParams {
13    /// The channel ID of the channel to send the commitment_signed message to
14    pub channel_id: Hash256,
15}
16
17/// Parameters for adding a TLC.
18#[serde_as]
19#[derive(Serialize, Deserialize, Debug, JsonSchema)]
20pub struct AddTlcParams {
21    /// The channel ID of the channel to add the TLC to
22    pub channel_id: Hash256,
23    /// The amount of the TLC
24    #[serde_as(as = "U128Hex")]
25    #[schemars(schema_with = "schema_as_uint_hex")]
26    pub amount: u128,
27    /// The payment hash of the TLC
28    pub payment_hash: Hash256,
29    /// The expiry of the TLC
30    #[serde_as(as = "U64Hex")]
31    #[schemars(schema_with = "schema_as_uint_hex")]
32    pub expiry: u64,
33    /// The hash algorithm of the TLC
34    pub hash_algorithm: Option<HashAlgorithm>,
35}
36
37/// Result of adding a TLC.
38#[serde_as]
39#[derive(Clone, Serialize, Deserialize, JsonSchema)]
40pub struct AddTlcResult {
41    /// The ID of the TLC
42    #[serde_as(as = "U64Hex")]
43    #[schemars(schema_with = "schema_as_uint_hex")]
44    pub tlc_id: u64,
45}
46
47/// Parameters for removing a TLC.
48#[serde_as]
49#[derive(Serialize, Deserialize, Debug, Clone, JsonSchema)]
50pub struct RemoveTlcParams {
51    /// The channel ID of the channel to remove the TLC from
52    pub channel_id: Hash256,
53    #[serde_as(as = "U64Hex")]
54    #[schemars(schema_with = "schema_as_uint_hex")]
55    /// The ID of the TLC to remove
56    pub tlc_id: u64,
57    /// The reason for removing the TLC, either a 32-byte hash for preimage fulfillment or an u32 error code for removal
58    pub reason: RemoveTlcReason,
59}
60
61/// The reason for removing a TLC.
62#[serde_as]
63#[derive(Serialize, Deserialize, Debug, Clone, JsonSchema)]
64#[serde(untagged)]
65pub enum RemoveTlcReason {
66    /// The reason for removing the TLC is that it was fulfilled
67    RemoveTlcFulfill { payment_preimage: Hash256 },
68    /// The reason for removing the TLC is that it failed
69    RemoveTlcFail { error_code: String },
70}
71
72/// Parameters for submitting a commitment transaction.
73#[serde_as]
74#[derive(Serialize, Deserialize, Debug, Clone, JsonSchema)]
75pub struct SubmitCommitmentTransactionParams {
76    /// Channel ID
77    pub channel_id: Hash256,
78    /// Commitment number
79    #[serde_as(as = "U64Hex")]
80    #[schemars(schema_with = "schema_as_uint_hex")]
81    pub commitment_number: u64,
82}
83
84/// Result of submitting a commitment transaction.
85#[serde_as]
86#[derive(Serialize, Deserialize, Debug, Clone, JsonSchema)]
87pub struct SubmitCommitmentTransactionResult {
88    /// Submitted commitment transaction hash
89    pub tx_hash: Hash256,
90}
91
92/// Parameters for checking channel shutdown.
93#[serde_as]
94#[derive(Serialize, Deserialize, Debug, Clone, JsonSchema)]
95pub struct CheckChannelShutdownParams {
96    /// Channel ID
97    pub channel_id: Hash256,
98}
99
100/// Parameters for signing an external funding transaction.
101#[derive(Serialize, Deserialize, Debug, Clone, JsonSchema)]
102pub struct SignExternalFundingTxParams {
103    /// The unsigned funding transaction returned from `open_channel_with_external_funding`.
104    pub unsigned_funding_tx: ckb_jsonrpc_types::Transaction,
105    /// The private key to sign the transaction, as a 0x-prefixed 32-byte hex string.
106    /// Note: This is a development-only RPC and the private key is provided directly.
107    pub private_key: String,
108}
109
110/// Result of signing an external funding transaction.
111#[derive(Clone, Serialize, Deserialize, Debug, JsonSchema)]
112pub struct SignExternalFundingTxResult {
113    /// The signed funding transaction that can be submitted via `submit_signed_funding_tx`.
114    pub signed_funding_tx: ckb_jsonrpc_types::Transaction,
115}