From 12ea1038f12976ae5c302359412257637cbaee97 Mon Sep 17 00:00:00 2001 From: lza_menace Date: Wed, 1 Jul 2020 01:12:24 -0700 Subject: [PATCH] data types and responses from daemon json rpc interface --- src/data_types.rs | 236 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 236 insertions(+) create mode 100644 src/data_types.rs diff --git a/src/data_types.rs b/src/data_types.rs new file mode 100644 index 0000000..f455f25 --- /dev/null +++ b/src/data_types.rs @@ -0,0 +1,236 @@ +#[derive(Serialize, Deserialize, Hash, Eq, PartialEq, Debug, Clone)] +pub struct RPCPayload { + pub jsonrpc: String, + pub id: String, + pub method: Option, + pub params: Option +} + +impl Default for RPCPayload { + fn default() -> RPCPayload { + RPCPayload { + jsonrpc: "2.0".to_string(), + id: "0".to_string(), + method: None, + params: None, + } + } +} + +#[derive(Serialize, Deserialize, Hash, Eq, PartialEq, Debug, Clone)] +pub struct RPCParams { + pub hash: Option, + pub txs_hashes: Option>, + pub height: Option +} + +impl Default for RPCParams { + fn default() -> RPCParams { + RPCParams { + hash: None, + txs_hashes: None, + height: None + } + } +} + +#[derive(Serialize, Deserialize, Hash, Eq, PartialEq, Debug, Clone)] +pub struct GetInfo { + pub jsonrpc: String, + pub id: String, + pub result: GetInfoResult +} + +#[derive(Serialize, Deserialize, Hash, Eq, PartialEq, Debug, Clone)] +pub struct GetInfoResult { + pub alt_blocks_count: u32, + pub block_size_limit: u32, + pub block_size_median: u32, + pub block_weight_limit: u32, + pub block_weight_median: u64, + pub bootstrap_daemon_address: String, + pub credits: u32, + pub cumulative_difficulty: u64, + pub cumulative_difficulty_top64: u32, + pub database_size: u64, + pub difficulty: u64, + pub difficulty_top64: u32, + pub free_space: u64, + pub grey_peerlist_size: u32, + pub height: u32, + pub height_without_bootstrap: u32, + pub incoming_connections_count: u32, + pub mainnet: bool, + pub nettype: String, + pub offline: bool, + pub outgoing_connections_count: u32, + pub rpc_connections_count: u32, + pub stagenet: bool, + pub start_time: u32, + pub status: String, + pub target: u32, + pub target_height: u32, + pub testnet: bool, + pub top_block_hash: String, + pub top_hash: String, + pub tx_count: u32, + pub tx_pool_size: u32, + pub untrusted: bool, + pub update_available: bool, + pub version: String, + pub was_bootstrap_ever_used: bool, + pub white_peerlist_size: u32, + pub wide_cumulative_difficulty: String, + pub wide_difficulty: String +} + +#[derive(Serialize, Deserialize, Hash, Eq, PartialEq, Debug, Clone)] +pub struct BlockByHeaderHash { + pub id: String, + pub jsonrpc: String, + pub result: BlockByHeaderHashResult +} + +#[derive(Serialize, Deserialize, Hash, Eq, PartialEq, Debug, Clone)] +pub struct BlockByHeaderHashResult { + pub status: String, + pub untrusted: bool, + pub block_header: BlockHeader +} + +#[derive(Serialize, Deserialize, Hash, Eq, PartialEq, Debug, Clone)] +pub struct BlockHeader { + pub block_size: u32, + pub depth: u32, + pub difficulty: u64, + pub hash: String, + pub height: u32, + pub major_version: u8, + pub minor_version: u8, + pub miner_tx_hash: Option, + pub nonce: u32, + pub num_txes: u32, + pub orphan_status: bool, + pub prev_hash: String, + pub reward: u64, + pub timestamp: i64 +} + +#[derive(Serialize, Deserialize, Hash, Eq, PartialEq, Debug, Clone)] +pub struct GetTransactions { + pub txs: Vec +} + +#[derive(Serialize, Deserialize, Hash, Eq, PartialEq, Debug, Clone)] +pub struct GetTransactionsTxs { + pub block_height: Option, + pub block_timestamp: Option, + pub double_spend_seen: bool, + pub in_pool: bool, + pub output_indices: Option>, + pub as_json: String, + pub as_json_full: Option +} + +impl GetTransactionsTxs { + pub fn process(&mut self) { + self.as_json_full = Some(serde_json::from_str(&self.as_json).unwrap()) + } +} + +#[derive(Serialize, Deserialize, Hash, Eq, PartialEq, Debug, Clone)] +pub struct GetBlock { + pub id: String, + pub jsonrpc: String, + pub result: GetBlockResult +} + +#[derive(Serialize, Deserialize, Hash, Eq, PartialEq, Debug, Clone)] +pub struct GetBlockResult { + pub block_header: BlockHeader, + pub credits: u8, + pub miner_tx_hash: String, + pub tx_hashes: Option>, +} + +#[derive(Serialize, Deserialize, Hash, Eq, PartialEq, Debug, Clone)] +pub struct GetTransactionPool { + pub credits: u32, + pub spent_key_images: Option>, + pub status: String, + pub top_hash: String, + pub transactions: Option> +} + +#[derive(Serialize, Deserialize, Hash, Eq, PartialEq, Debug, Clone)] +pub struct SpentKeyImages { + pub id_hash: String, + pub txs_hashes: Vec +} + +#[derive(Serialize, Deserialize, Hash, Eq, PartialEq, Debug, Clone)] +pub struct Transactions { + pub blob_size: u32, + pub do_not_relay: bool, + pub double_spend_seen: bool, + pub fee: u64, + pub id_hash: String, + pub kept_by_block: bool, + pub last_failed_height: u32, + pub last_failed_id_hash: String, + pub last_relayed_time: i64, + pub max_used_block_height: u32, + pub max_used_block_id_hash: String, + pub receive_time: i64, + pub relayed: bool, + pub tx_blob: String, + pub tx_json: String, + pub tx_json_full: Option, + pub weight: u32 +} + +impl Transactions { + pub fn process(&mut self) { + self.tx_json_full = Some(serde_json::from_str(&self.tx_json).unwrap()) + } +} + +#[derive(Serialize, Deserialize, Hash, Eq, PartialEq, Debug, Clone)] +pub struct TransactionJSON { + pub version: u32, + pub unlock_time: u64, + pub vin: Vec, + pub vout: Vec, + pub extra: Vec, + pub rct_signatures: RingSignatures +} + +#[derive(Serialize, Deserialize, Hash, Eq, PartialEq, Debug, Clone)] +pub struct TransactionInputs { + pub key: Option +} + +#[derive(Serialize, Deserialize, Hash, Eq, PartialEq, Debug, Clone)] +pub struct PreviousTransactionKey { + pub amount: u64, + pub key_offsets: Vec, + pub k_image: String +} + +#[derive(Serialize, Deserialize, Hash, Eq, PartialEq, Debug, Clone)] +pub struct TransactionOutputs { + pub amount: u64, + pub target: OutputStealthAddress +} + +#[derive(Serialize, Deserialize, Hash, Eq, PartialEq, Debug, Clone)] +pub struct OutputStealthAddress { + pub key: String +} + +#[derive(Serialize, Deserialize, Hash, Eq, PartialEq, Debug, Clone)] +pub struct RingSignatures { + pub r#type: u32, + pub txnFee: Option, + pub outPk: Option> +}