Skip to content

Commit 0bf9d55

Browse files
committedJun 10, 2024·
rpc_api: Reorganize code.
1 parent af6fc08 commit 0bf9d55

File tree

1 file changed

+52
-52
lines changed

1 file changed

+52
-52
lines changed
 

‎src/client/rpc_api.rs

+52-52
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,28 @@ impl RpcApi for Client {
4545
) -> bitcoincore_rpc::Result<bitcoin::Transaction> {
4646
Ok(self.ledger.get_transaction(*txid))
4747
}
48-
48+
fn get_raw_transaction_info(
49+
&self,
50+
txid: &bitcoin::Txid,
51+
_block_hash: Option<&bitcoin::BlockHash>,
52+
) -> bitcoincore_rpc::Result<json::GetRawTransactionResult> {
53+
Ok(GetRawTransactionResult {
54+
in_active_chain: None,
55+
hex: vec![],
56+
txid: *txid,
57+
hash: Wtxid::hash(&[0]),
58+
size: 0,
59+
vsize: 0,
60+
version: 0,
61+
locktime: 0,
62+
vin: vec![],
63+
vout: vec![],
64+
blockhash: None,
65+
confirmations: Some(10),
66+
time: None,
67+
blocktime: None,
68+
})
69+
}
4970
fn send_raw_transaction<R: bitcoincore_rpc::RawTx>(
5071
&self,
5172
tx: R,
@@ -57,34 +78,6 @@ impl RpcApi for Client {
5778
Ok(tx.compute_txid())
5879
}
5980

60-
fn send_to_address(
61-
&self,
62-
address: &Address<NetworkChecked>,
63-
amount: Amount,
64-
_comment: Option<&str>,
65-
_comment_to: Option<&str>,
66-
_subtract_fee: Option<bool>,
67-
_replaceable: Option<bool>,
68-
_confirmation_target: Option<u32>,
69-
_estimate_mode: Option<json::EstimateMode>,
70-
) -> bitcoincore_rpc::Result<bitcoin::Txid> {
71-
let txin = TxIn::default();
72-
let txout = TxOut {
73-
value: amount,
74-
script_pubkey: address.script_pubkey(),
75-
};
76-
let tx = bitcoin::Transaction {
77-
version: bitcoin::transaction::Version(2),
78-
lock_time: absolute::LockTime::from_consensus(0),
79-
input: vec![txin],
80-
output: vec![txout],
81-
};
82-
83-
let txid = self.send_raw_transaction(&tx)?;
84-
85-
Ok(txid)
86-
}
87-
8881
fn get_transaction(
8982
&self,
9083
txid: &bitcoin::Txid,
@@ -122,6 +115,36 @@ impl RpcApi for Client {
122115
Ok(res)
123116
}
124117

118+
fn send_to_address(
119+
&self,
120+
address: &Address<NetworkChecked>,
121+
amount: Amount,
122+
_comment: Option<&str>,
123+
_comment_to: Option<&str>,
124+
_subtract_fee: Option<bool>,
125+
_replaceable: Option<bool>,
126+
_confirmation_target: Option<u32>,
127+
_estimate_mode: Option<json::EstimateMode>,
128+
) -> bitcoincore_rpc::Result<bitcoin::Txid> {
129+
let txin = TxIn::default();
130+
let txout = TxOut {
131+
value: amount,
132+
script_pubkey: address.script_pubkey(),
133+
};
134+
let tx = bitcoin::Transaction {
135+
version: bitcoin::transaction::Version(2),
136+
lock_time: absolute::LockTime::from_consensus(0),
137+
input: vec![txin],
138+
output: vec![txout],
139+
};
140+
141+
let txid = self.send_raw_transaction(&tx)?;
142+
143+
self.ledger.add_transaction_unconditionally(tx);
144+
145+
Ok(txid)
146+
}
147+
125148
fn get_new_address(
126149
&self,
127150
_label: Option<&str>,
@@ -141,29 +164,6 @@ impl RpcApi for Client {
141164
Ok(address)
142165
}
143166

144-
fn get_raw_transaction_info(
145-
&self,
146-
txid: &bitcoin::Txid,
147-
_block_hash: Option<&bitcoin::BlockHash>,
148-
) -> bitcoincore_rpc::Result<json::GetRawTransactionResult> {
149-
Ok(GetRawTransactionResult {
150-
in_active_chain: None,
151-
hex: vec![],
152-
txid: *txid,
153-
hash: Wtxid::hash(&[0]),
154-
size: 0,
155-
vsize: 0,
156-
version: 0,
157-
locktime: 0,
158-
vin: vec![],
159-
vout: vec![],
160-
blockhash: None,
161-
confirmations: Some(10),
162-
time: None,
163-
blocktime: None,
164-
})
165-
}
166-
167167
/// Generates `block_num` amount of block rewards to user.
168168
fn generate_to_address(
169169
&self,

0 commit comments

Comments
 (0)
Please sign in to comment.