Skip to content

Commit c2ec425

Browse files
committed
Merge #364: Type alias SignRawTransaction
5b3fbcd Run the formatter (Jamil Lambert, PhD) c84e07d Use the type alias of SignRawTransaction (Jamil Lambert, PhD) e0f1311 Type alias SignRawTransaction (Jamil Lambert, PhD) Pull request description: Both `signrawtransactionwithkey` and `signrawtransactionwithwallet` use the type `SignRawTransaction` in types and model. But the policy is to have a type for all RPCs with the same name, this makes everything uniform and easier to use without having to search for the correct type. - Add aliases for these two RPC methods and a note in the docs explaining why. - Use the new aliases in the tests. - Run the formatter. Reordering reexports only. Closes #357 ACKs for top commit: tcharding: ACK 5b3fbcd Tree-SHA512: 9d8f7b29946c9fcbf91c064fc7ee0e96e2439b9c93b68b2c77b855984eead90501ae838ca61c8d10244e0cc5f580d305a5407ffc2d4f9aab91a3445cd3041d15
2 parents 3565c7f + 5b3fbcd commit c2ec425

File tree

21 files changed

+106
-43
lines changed

21 files changed

+106
-43
lines changed

client/src/client_sync/v17/raw_transactions.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ macro_rules! impl_client_v17__sign_raw_transaction_with_key {
213213
&self,
214214
tx: &bitcoin::Transaction,
215215
keys: &[bitcoin::PrivateKey],
216-
) -> Result<SignRawTransaction> {
216+
) -> Result<SignRawTransactionWithKey> {
217217
let hex = bitcoin::consensus::encode::serialize_hex(tx);
218218
let keys = keys.iter().map(|k| format!("{}", k)).collect::<Vec<String>>();
219219
self.call("signrawtransactionwithkey", &[hex.into(), into_json(keys)?])

client/src/client_sync/v17/wallet.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,7 @@ macro_rules! impl_client_v17__sign_raw_transaction_with_wallet {
660660
pub fn sign_raw_transaction_with_wallet(
661661
&self,
662662
tx: &bitcoin::Transaction,
663-
) -> Result<SignRawTransaction> {
663+
) -> Result<SignRawTransactionWithWallet> {
664664
let hex = bitcoin::consensus::encode::serialize_hex(tx);
665665
self.call("signrawtransactionwithwallet", &[into_json(hex)?])
666666
}

integration_test/tests/raw_transactions.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -399,9 +399,9 @@ fn raw_transactions__test_mempool_accept__modelled() {
399399
let tx = create_a_raw_transaction(&node);
400400

401401
// Sign (but don't broadcast).
402-
let signed: SignRawTransaction =
402+
let signed: SignRawTransactionWithWallet =
403403
node.client.sign_raw_transaction_with_wallet(&tx).expect("signrawtransactionwithwallet");
404-
let signed_model: mtype::SignRawTransaction =
404+
let signed_model: mtype::SignRawTransactionWithWallet =
405405
signed.into_model().expect("SignRawTransaction into model");
406406
let signed_tx = signed_model.tx;
407407

@@ -474,10 +474,11 @@ fn create_sign_send(node: &Node) {
474474

475475
// wallet.rs expects this call to exist, if you change it then you'll need to update the test
476476
// `wallet__sign_raw_transaction_with_wallet__modelled`.
477-
let json: SignRawTransaction =
477+
let json: SignRawTransactionWithWallet =
478478
node.client.sign_raw_transaction_with_wallet(&tx).expect("signrawtransactionwithwallet");
479479

480-
let model: Result<mtype::SignRawTransaction, SignRawTransactionError> = json.into_model();
480+
let model: Result<mtype::SignRawTransactionWithWallet, SignRawTransactionError> =
481+
json.into_model();
481482
let sign_raw_transaction = model.unwrap();
482483

483484
// The proves we did everything correctly.
@@ -533,9 +534,10 @@ fn create_sign_with_key_send(node: &Node) {
533534
let model: mtype::DumpPrivKey = json.into_model().expect("DumpPrivKey");
534535
let key = model.0;
535536

536-
let json: SignRawTransaction =
537+
let json: SignRawTransactionWithKey =
537538
node.client.sign_raw_transaction_with_key(&tx, &[key]).expect("signrawtransactionwithkey");
538-
let model: Result<mtype::SignRawTransaction, SignRawTransactionError> = json.into_model();
539+
let model: Result<mtype::SignRawTransactionWithKey, SignRawTransactionError> =
540+
json.into_model();
539541
let sign_raw_transaction = model.unwrap();
540542

541543
// The proves we did everything correctly.
@@ -580,12 +582,13 @@ fn create_fund_sign_send(node: &Node) {
580582
let funded = json.transaction().unwrap();
581583

582584
// This method is from the wallet section.
583-
let json: SignRawTransaction = node
585+
let json: SignRawTransactionWithWallet = node
584586
.client
585587
.sign_raw_transaction_with_wallet(&funded)
586588
.expect("signrawtransactionwithwallet");
587589
// This proves we did everything correctly.
588-
let model: Result<mtype::SignRawTransaction, SignRawTransactionError> = json.into_model();
590+
let model: Result<mtype::SignRawTransactionWithWallet, SignRawTransactionError> =
591+
json.into_model();
589592
let sign_raw_transaction = model.unwrap();
590593
let _ =
591594
node.client.send_raw_transaction(&sign_raw_transaction.tx).expect("createrawtransaction");

types/src/model/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ pub use self::{
4343
ConvertToPsbt, CreatePsbt, CreateRawTransaction, DecodePsbt, DecodeRawTransaction,
4444
DecodeScript, DescriptorProcessPsbt, FinalizePsbt, FundRawTransaction, GetRawTransaction,
4545
GetRawTransactionVerbose, JoinPsbts, MempoolAcceptance, MempoolAcceptanceFees,
46-
SendRawTransaction, SignFail, SignRawTransaction, SubmitPackage, SubmitPackageTxResult,
47-
SubmitPackageTxResultFees, TestMempoolAccept, UtxoUpdatePsbt,
46+
SendRawTransaction, SignFail, SignRawTransaction, SignRawTransactionWithKey, SubmitPackage,
47+
SubmitPackageTxResult, SubmitPackageTxResultFees, TestMempoolAccept, UtxoUpdatePsbt,
4848
},
4949
util::{
5050
CreateMultisig, DeriveAddresses, DeriveAddressesMultipath, EstimateSmartFee,
@@ -61,7 +61,7 @@ pub use self::{
6161
ListReceivedByLabel, ListReceivedByLabelItem, ListSinceBlock, ListTransactions,
6262
ListUnspent, ListUnspentItem, ListWallets, LoadWallet, PsbtBumpFee, RescanBlockchain,
6363
ScriptType, Send, SendAll, SendMany, SendManyVerbose, SendToAddress, SignMessage,
64-
SimulateRawTransaction, TransactionCategory, TransactionItem, UnloadWallet,
65-
WalletCreateFundedPsbt, WalletDisplayAddress, WalletProcessPsbt,
64+
SignRawTransactionWithWallet, SimulateRawTransaction, TransactionCategory, TransactionItem,
65+
UnloadWallet, WalletCreateFundedPsbt, WalletDisplayAddress, WalletProcessPsbt,
6666
},
6767
};

types/src/model/raw_transactions.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,12 @@ pub struct SignRawTransaction {
202202
pub errors: Vec<SignFail>,
203203
}
204204

205+
/// Models the result of JSON-RPC method `signrawtransactionwithkey`.
206+
///
207+
/// **Note:** This is a type alias of [`SignRawTransaction`] because the RPC response
208+
/// shape is identical, and our policy is to have a return type for every RPC method.
209+
pub type SignRawTransactionWithKey = SignRawTransaction;
210+
205211
/// A script verification error. Part of `signrawtransaction`.
206212
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
207213
#[serde(deny_unknown_fields)]

types/src/model/wallet.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ use bitcoin::{
1616
};
1717
use serde::{Deserialize, Serialize};
1818

19+
use super::SignRawTransaction;
20+
1921
/// The purpose of an address. Part of `getaddressesbylabel`.
2022
#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
2123
pub enum AddressPurpose {
@@ -828,6 +830,12 @@ pub struct SendToAddress {
828830
#[derive(Clone, Debug, PartialEq, Eq)]
829831
pub struct SignMessage(pub sign_message::MessageSignature);
830832

833+
/// Models the result of JSON-RPC method `signrawtransactionwithwallet`.
834+
///
835+
/// **Note:** This is a type alias of [`SignRawTransaction`] because the RPC response
836+
/// shape is identical, and our policy is to have a return type for every RPC method.
837+
pub type SignRawTransactionWithWallet = SignRawTransaction;
838+
831839
/// Models the result of JSON-RPC method `simulaterawtransaction`.
832840
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
833841
#[serde(deny_unknown_fields)]

types/src/v17/mod.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ pub use self::{
264264
GetRawTransaction, GetRawTransactionVerbose, GetRawTransactionVerboseError,
265265
MempoolAcceptance, PsbtInput, PsbtInputError, PsbtOutput, PsbtOutputError,
266266
SendRawTransaction, SignFail, SignFailError, SignRawTransaction, SignRawTransactionError,
267-
TestMempoolAccept,
267+
SignRawTransactionWithKey, TestMempoolAccept,
268268
},
269269
util::{
270270
CreateMultisig, CreateMultisigError, EstimateSmartFee, SignMessageWithPrivKey,
@@ -283,8 +283,9 @@ pub use self::{
283283
ListReceivedByAddressError, ListReceivedByAddressItem, ListSinceBlock, ListSinceBlockError,
284284
ListTransactions, ListUnspent, ListUnspentItem, ListUnspentItemError, ListWallets,
285285
LoadWallet, LockUnspent, RescanBlockchain, ScriptType, SendMany, SendToAddress, SetTxFee,
286-
SignMessage, TransactionCategory, TransactionItem, TransactionItemError,
287-
WalletCreateFundedPsbt, WalletCreateFundedPsbtError, WalletProcessPsbt,
286+
SignMessage, SignRawTransactionWithWallet, TransactionCategory, TransactionItem,
287+
TransactionItemError, WalletCreateFundedPsbt, WalletCreateFundedPsbtError,
288+
WalletProcessPsbt,
288289
},
289290
zmq::GetZmqNotifications,
290291
};

types/src/v17/raw_transactions/mod.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ pub struct SendRawTransaction(
396396
pub String,
397397
);
398398

399-
/// Result of JSON-RPC method `signrawtransactionwithkey` (and deprecated `signrawtransaction`).
399+
/// Result of JSON-RPC method `signrawtransaction`.
400400
///
401401
/// > signrawtransaction "hexstring" ( [{"txid":"id","vout":n,"scriptPubKey":"hex","redeemScript":"hex"},...] ["privatekey1",...] sighashtype )
402402
/// >
@@ -420,6 +420,24 @@ pub struct SignRawTransaction {
420420
pub errors: Option<Vec<SignFail>>,
421421
}
422422

423+
/// Result of JSON-RPC method `signrawtransactionwithkey`.
424+
///
425+
/// > signrawtransactionwithkey "hexstring" ["privatekey1",...] ( [{"txid":"id","vout":n,"scriptPubKey":"hex","redeemScript":"hex"},...] sighashtype )
426+
/// >
427+
/// > Sign inputs for raw transaction (serialized, hex-encoded).
428+
/// > The second argument is an array of base58-encoded private
429+
/// > keys that will be the only keys used to sign the transaction.
430+
/// > The third optional argument (may be null) is an array of previous transaction outputs that
431+
/// > this transaction depends on but may not yet be in the block chain.
432+
/// >
433+
/// > Arguments:
434+
/// > 1. "hexstring" (string, required) The transaction hex string
435+
/// > 2. "privkeys" (string, required) A json array of base58-encoded private keys for signing
436+
///
437+
/// **Note:** This is a type alias of [`SignRawTransaction`] because the RPC response
438+
/// shape is identical, and our policy is to have a return type for every RPC method.
439+
pub type SignRawTransactionWithKey = SignRawTransaction;
440+
423441
/// A script verification error. Part of `signrawtransaction`.
424442
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
425443
#[serde(deny_unknown_fields)]

types/src/v17/wallet/mod.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use serde::{Deserialize, Serialize};
1616

1717
// TODO: Remove wildcard, use explicit types.
1818
pub use self::error::*;
19+
use super::SignRawTransaction;
1920

2021
/// Result of JSON-RPC method `abortrescan`.
2122
///
@@ -961,6 +962,21 @@ pub struct SignMessage(
961962
pub String,
962963
);
963964

965+
/// Result of JSON-RPC method `signrawtransactionwithwallet`.
966+
///
967+
/// > signrawtransactionwithwallet "hexstring" ( [{"txid":"id","vout":n,"scriptPubKey":"hex","redeemScript":"hex"},...] sighashtype )
968+
/// >
969+
/// > Sign inputs for raw transaction (serialized, hex-encoded).
970+
/// > The second optional argument (may be null) is an array of previous transaction outputs that
971+
/// > this transaction depends on but may not yet be in the block chain.
972+
/// >
973+
/// > Arguments:
974+
/// > 1. "hexstring" (string, required) The transaction hex string
975+
///
976+
/// **Note:** This is a type alias of [`SignRawTransaction`] because the RPC response
977+
/// shape is identical, and our policy is to have a return type for every RPC method.
978+
pub type SignRawTransactionWithWallet = SignRawTransaction;
979+
964980
/// Result of the JSON-RPC method `walletcreatefundedpsbt`.
965981
///
966982
/// > walletcreatefundedpsbt [{"txid":"id","vout":n},...] [{"address":amount},{"data":"hex"},...] ( locktime ) ( replaceable ) ( options bip32derivs )

types/src/v18/mod.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,9 @@ pub use crate::v17::{
281281
PsbtScript, RawTransaction, RawTransactionError, RawTransactionInput, RawTransactionOutput,
282282
RescanBlockchain, ScriptType, SendMany, SendRawTransaction, SendToAddress, SetNetworkActive,
283283
SetTxFee, SignFail, SignFailError, SignMessage, SignMessageWithPrivKey, SignRawTransaction,
284-
SignRawTransactionError, Softfork, SoftforkReject, TestMempoolAccept, TransactionCategory,
285-
TransactionItem, TransactionItemError, UploadTarget, ValidateAddress, ValidateAddressError,
286-
VerifyChain, VerifyMessage, VerifyTxOutProof, WalletCreateFundedPsbt,
287-
WalletCreateFundedPsbtError, WalletProcessPsbt, WitnessUtxo,
284+
SignRawTransactionError, SignRawTransactionWithKey, SignRawTransactionWithWallet, Softfork,
285+
SoftforkReject, TestMempoolAccept, TransactionCategory, TransactionItem, TransactionItemError,
286+
UploadTarget, ValidateAddress, ValidateAddressError, VerifyChain, VerifyMessage,
287+
VerifyTxOutProof, WalletCreateFundedPsbt, WalletCreateFundedPsbtError, WalletProcessPsbt,
288+
WitnessUtxo,
288289
};

0 commit comments

Comments
 (0)