1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
use super::hash::H256;
use super::transaction::TransactionOutputScript;
#[derive(Debug, Serialize, Deserialize, PartialEq)]
pub struct GetTxOutResponse {
pub bestblock: H256,
pub confirmations: u32,
pub value: f64,
#[serde(rename = "scriptPubKey")]
pub script: TransactionOutputScript,
pub version: i32,
pub coinbase: bool,
}
#[cfg(test)]
mod tests {
use serde_json;
use super::super::bytes::Bytes;
use super::super::hash::H256;
use super::super::script::ScriptType;
use super::super::transaction::TransactionOutputScript;
use super::*;
#[test]
fn tx_out_response_serialize() {
let txout = GetTxOutResponse {
bestblock: H256::from(0x56),
confirmations: 777,
value: 100000.56,
script: TransactionOutputScript {
asm: "Hello, world!!!".to_owned(),
hex: Bytes::new(vec![1, 2, 3, 4]),
req_sigs: 777,
script_type: ScriptType::Multisig,
addresses: vec!["1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa".into(), "1H5m1XzvHsjWX3wwU781ubctznEpNACrNC".into()],
},
version: 33,
coinbase: false,
};
assert_eq!(serde_json::to_string(&txout).unwrap(), r#"{"bestblock":"5600000000000000000000000000000000000000000000000000000000000000","confirmations":777,"value":100000.56,"scriptPubKey":{"asm":"Hello, world!!!","hex":"01020304","reqSigs":777,"type":"multisig","addresses":["1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa","1H5m1XzvHsjWX3wwU781ubctznEpNACrNC"]},"version":33,"coinbase":false}"#);
}
#[test]
fn tx_out_response_deserialize() {
let txout = GetTxOutResponse {
bestblock: H256::from(0x56),
confirmations: 777,
value: 100000.56,
script: TransactionOutputScript {
asm: "Hello, world!!!".to_owned(),
hex: Bytes::new(vec![1, 2, 3, 4]),
req_sigs: 777,
script_type: ScriptType::Multisig,
addresses: vec!["1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa".into(), "1H5m1XzvHsjWX3wwU781ubctznEpNACrNC".into()],
},
version: 33,
coinbase: false,
};
assert_eq!(
serde_json::from_str::<GetTxOutResponse>(r#"{"bestblock":"5600000000000000000000000000000000000000000000000000000000000000","confirmations":777,"value":100000.56,"scriptPubKey":{"asm":"Hello, world!!!","hex":"01020304","reqSigs":777,"type":"multisig","addresses":["1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa","1H5m1XzvHsjWX3wwU781ubctznEpNACrNC"]},"version":33,"coinbase":false}"#).unwrap(),
txout);
}
}