use BlockHash;
use TransactionId;
use ScriptPubKey;
use std::time::SystemTime;
use types::arguments::address::Address;
#[derive(Deserialize, Serialize, Debug)]
pub struct SerializedRawTransaction(pub String);
impl SerializedRawTransaction {
pub fn set_locktime(&mut self) {
let current_time = SystemTime::now().duration_since(SystemTime::UNIX_EPOCH).unwrap();
let hex_time = format!("{:x}", current_time.as_secs() - 120);
let mut rev_hexified_time = String::new();
for i in (0..8).rev().step_by(2) {
rev_hexified_time.push_str(hex_time.get(i-1..i+1).unwrap());
}
let hex = self.0.clone();
let payload = &hex[0..hex.len() - 38];
let expiry = &hex[hex.len() - 30..hex.len() - 24];
let mut result = String::new();
result.push_str(payload);
result.push_str(rev_hexified_time.as_str());
result.push_str(expiry);
result.push_str("000000000000000000000000");
self.0 = result;
}
pub fn from_hex(hex: String) -> Self {
SerializedRawTransaction(hex.clone())
}
}
#[derive(Deserialize, Serialize, Debug)]
pub struct Transaction {
pub amount: f64,
pub confirmations: u32,
pub blockhash: Option<BlockHash>,
pub blockindex: Option<u64>,
pub blocktime: Option<u64>,
pub walletconflicts: Vec<TransactionId>,
pub expiryheight: u32,
pub txid: TransactionId,
pub time: u64,
pub timereceived: u64,
pub vjoinsplit: Vec<VJoinsplit>,
pub details: Vec<Detail>,
pub hex: String,
}
#[derive(Deserialize, Serialize, Debug)]
pub struct Detail {
pub account: String,
pub address: String,
pub category: String,
pub amount: f64,
pub fee: Option<f64>,
pub vout: u32,
#[serde(rename = "involvesWatchonly")]
pub involves_watchonly: Option<bool>,
pub abandoned: Option<bool>,
pub size: u32,
}
#[derive(Deserialize, Serialize, Debug)]
pub struct RawTransaction {
pub hex: Option<String>,
pub overwintered: Option<bool>,
pub txid: String,
pub size: Option<u32>,
pub versiongroupid: Option<String>,
pub version: u32,
pub locktime: u64,
pub expiryheight: Option<u32>,
pub vin: Vec<Vin>,
pub vout: Vec<Vout>,
pub vjoinsplit: Vec<VJoinsplit>,
pub blockhash: Option<BlockHash>,
pub confirmations: Option<u32>,
pub time: Option<u64>,
pub blocktime: Option<u64>
}
#[derive(Deserialize, Serialize, Debug)]
pub struct Vin {
pub txid: TransactionId,
pub vout: u32,
#[serde(rename = "scriptSig")]
pub script_sig: ScriptSig,
pub sequence: u64,
}
#[derive(Deserialize, Serialize, Debug)]
pub struct ScriptSig {
pub asm: String,
pub hex: String
}
#[derive(Deserialize, Serialize, Debug)]
pub struct Vout {
pub value: f64,
pub interest: Option<f64>,
pub n: u32,
#[serde(rename = "scriptPubKey")]
pub script_pubkey: ScriptPubKey,
}
#[derive(Deserialize, Serialize, Debug)]
pub struct VJoinsplit {
pub vpub_old: f64,
pub vpub_new: f64,
pub anchor: String,
pub nullifiers: Vec<String>,
pub commitments: Vec<String>,
#[serde(rename = "onetimePubKey")]
pub onetime_pubkey: String,
#[serde(rename = "randomSeed")]
pub random_seed: String,
pub macs: Vec<String>,
pub proof: String,
pub ciphertexts: Vec<String>,
}
#[derive(Deserialize, Serialize, Debug)]
pub struct SignedRawTransaction {
pub hex: String,
pub complete: bool,
pub errors: Option<Vec<SignRawTransactionError>>,
}
impl SignedRawTransaction {
pub fn to_string(&self) -> String {
self.hex.clone()
}
}
#[derive(Deserialize, Serialize, Debug)]
pub struct SignRawTransactionError {
pub txid: String,
pub vout: u16,
#[serde(rename = "scriptSig")]
pub script_sig: String,
pub sequence: u64,
pub error: String,
}
#[derive(Deserialize, Serialize, Debug)]
pub struct TransactionOutputDetail {
pub txid: TransactionId,
pub vout: u32,
#[serde(rename = "scriptPubKey")]
pub script_pub_key: String,
#[serde(rename = "redeemScript")]
pub redeem_script: Option<String>,
pub amount: f64,
}
#[derive(Deserialize, Serialize, Debug)]
pub enum SigHashType {
#[serde(rename = "ALL")]
All,
#[serde(rename = "NONE")]
None,
#[serde(rename = "SINGLE")]
Single,
#[serde(rename = "ALL|ANYONECANPAY")]
AllAnyoneCanPay,
#[serde(rename = "NONE|ANYONECANPAY")]
NoneAnyoneCanPay,
#[serde(rename = "SINGLE|ANYONECANPAY")]
SingleAnyoneCanPay,
}
#[derive(Deserialize, Debug)]
pub struct Unspent {
pub txid: TransactionId,
pub vout: u8,
pub generated: bool,
pub address: Address,
pub account: Option<String>,
pub amount: f64,
pub interest: Option<f64>,
#[serde(rename = "scriptPubKey")]
pub script_pub_key: String,
pub rawconfirmations: u64,
pub confirmations: u64,
pub spendable: bool,
}
#[derive(Deserialize, Serialize, Debug)]
pub struct LockedUnspent {
pub txid: TransactionId,
pub vout: u8
}
#[derive(Deserialize, Serialize, Debug)]
pub struct ReceivedByAddress {
pub address: Address,
pub account: Option<String>,
pub amount: f64,
pub rawconfirmations: u64,
pub confirmations: u64,
pub txids: Vec<TransactionId>,
}
#[derive(Deserialize, Serialize, Debug)]
pub struct TxListSinceBlock {
pub transactions: Vec<ListTransaction>,
pub lastblock: String,
}
#[derive(Deserialize, Serialize, Debug)]
pub struct ListTransaction {
pub account: String,
pub address: Address,
pub category: TxCategory,
pub amount: f64,
pub vout: u32,
pub fee: Option<f64>,
pub rawconfirmations: u64,
pub confirmations: u64,
pub blockhash: String,
pub blockindex: u64,
pub blocktime: u64,
pub expiryheight: u64,
pub txid: TransactionId,
pub walletconflicts: Vec<Option<String>>,
pub time: u64,
pub timereceived: u64,
pub vjoinsplit: Vec<Option<VJoinsplit>>,
pub size: u32,
pub comment: Option<String>,
pub to: Option<String>,
}
#[derive(Deserialize, Serialize, Debug)]
pub enum TxCategory {
#[serde(rename = "send")]
Send,
#[serde(rename = "receive")]
Receive,
#[serde(rename = "move")]
Move
}
#[derive(Deserialize, Serialize, Debug)]
pub struct ListTransactions(Vec<ListTransaction>);
#[derive(Deserialize, Serialize, Debug)]
pub struct ResentWalletTransactions(Vec<TransactionId>);
#[derive(Deserialize, Serialize, Debug)]
pub struct SetPubkey {
pub pubkey: String,
pub ismine: bool,
pub address: Address,
}