use crate::schema_helpers::*;
use crate::serde_utils::{EntityHex, Hash256, Pubkey, U128Hex, U64Hex};
use ckb_jsonrpc_types::{DepType, JsonBytes, OutPoint as OutPointWrapper, Script, ScriptHashType};
use ckb_types::packed::OutPoint;
use ckb_types::H256;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use serde_with::serde_as;
#[serde_as]
#[derive(Debug, Serialize, Deserialize, Clone, JsonSchema)]
pub struct GraphNodesParams {
#[serde_as(as = "Option<U64Hex>")]
#[schemars(schema_with = "schema_as_uint_hex_optional")]
pub limit: Option<u64>,
pub after: Option<JsonBytes>,
}
#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema)]
pub struct UdtScript {
#[schemars(schema_with = "schema_as_hex_bytes")]
pub code_hash: H256,
pub hash_type: ScriptHashType,
pub args: String,
}
#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema)]
pub struct UdtDep {
#[serde(default, skip_serializing_if = "Option::is_none")]
pub cell_dep: Option<UdtCellDep>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub type_id: Option<Script>,
}
#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema)]
pub struct UdtCellDep {
pub out_point: OutPointWrapper,
pub dep_type: DepType,
}
#[serde_as]
#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema)]
pub struct UdtArgInfo {
pub name: String,
pub script: UdtScript,
#[serde_as(as = "Option<U128Hex>")]
#[schemars(schema_with = "schema_as_uint_hex_optional")]
pub auto_accept_amount: Option<u128>,
pub cell_deps: Vec<UdtDep>,
}
#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema)]
pub struct UdtCfgInfos(
pub Vec<UdtArgInfo>,
);
#[serde_as]
#[derive(Debug, Serialize, Deserialize, Clone, JsonSchema)]
pub struct NodeInfo {
pub node_name: String,
pub version: String,
#[schemars(schema_with = "schema_as_string_array")]
pub addresses: Vec<String>,
pub features: Vec<String>,
pub pubkey: Pubkey,
#[serde_as(as = "U64Hex")]
#[schemars(schema_with = "schema_as_uint_hex")]
pub timestamp: u64,
pub chain_hash: Hash256,
#[serde_as(as = "U64Hex")]
#[schemars(schema_with = "schema_as_uint_hex")]
pub auto_accept_min_ckb_funding_amount: u64,
pub udt_cfg_infos: UdtCfgInfos,
}
#[derive(Debug, Serialize, Deserialize, Clone, JsonSchema)]
pub struct GraphNodesResult {
pub nodes: Vec<NodeInfo>,
pub last_cursor: JsonBytes,
}
#[serde_as]
#[derive(Debug, Serialize, Deserialize, Clone, JsonSchema)]
pub struct GraphChannelsParams {
#[serde_as(as = "Option<U64Hex>")]
#[schemars(schema_with = "schema_as_uint_hex_optional")]
pub limit: Option<u64>,
pub after: Option<JsonBytes>,
}
#[serde_as]
#[derive(Copy, Clone, Debug, Eq, PartialEq, Serialize, Deserialize, JsonSchema)]
pub struct ChannelUpdateInfo {
#[serde_as(as = "U64Hex")]
#[schemars(schema_with = "schema_as_uint_hex")]
pub timestamp: u64,
pub enabled: bool,
#[serde_as(as = "Option<U128Hex>")]
#[schemars(schema_with = "schema_as_uint_hex_optional")]
pub outbound_liquidity: Option<u128>,
#[serde_as(as = "U64Hex")]
#[schemars(schema_with = "schema_as_uint_hex")]
pub tlc_expiry_delta: u64,
#[serde_as(as = "U128Hex")]
#[schemars(schema_with = "schema_as_uint_hex")]
pub tlc_minimum_value: u128,
#[serde_as(as = "U64Hex")]
#[schemars(schema_with = "schema_as_uint_hex")]
pub fee_rate: u64,
}
#[serde_as]
#[derive(Debug, Serialize, Deserialize, Clone, JsonSchema)]
pub struct ChannelInfo {
#[serde_as(as = "EntityHex")]
#[schemars(schema_with = "schema_as_hex_bytes")]
pub channel_outpoint: OutPoint,
pub node1: Pubkey,
pub node2: Pubkey,
#[serde_as(as = "U64Hex")]
#[schemars(schema_with = "schema_as_uint_hex")]
pub created_timestamp: u64,
pub update_info_of_node1: Option<ChannelUpdateInfo>,
pub update_info_of_node2: Option<ChannelUpdateInfo>,
#[serde_as(as = "U128Hex")]
#[schemars(schema_with = "schema_as_uint_hex")]
pub capacity: u128,
pub chain_hash: Hash256,
pub udt_type_script: Option<Script>,
}
#[derive(Serialize, Deserialize, Clone, JsonSchema)]
pub struct GraphChannelsResult {
pub channels: Vec<ChannelInfo>,
pub last_cursor: JsonBytes,
}