@@ -22,7 +22,7 @@ use serde_json;
22
22
use crate :: bitcoin:: hashes:: hex:: { FromHex , ToHex } ;
23
23
use crate :: bitcoin:: secp256k1:: ecdsa:: Signature ;
24
24
use crate :: bitcoin:: {
25
- Address , Amount , Block , BlockHeader , OutPoint , PrivateKey , PublicKey , Script , Transaction ,
25
+ Address , Amount , Block , BlockHeader , OutPoint , PrivateKey , PublicKey , Script , Transaction , Txid ,
26
26
} ;
27
27
use log:: Level :: { Debug , Trace , Warn } ;
28
28
@@ -186,6 +186,13 @@ impl RawTx for String {
186
186
}
187
187
}
188
188
189
+ /// The different authentication methods for the client.
190
+ #[ derive( Clone , Debug , Hash , Eq , PartialEq , Ord , PartialOrd ) ]
191
+ pub enum MineableTx {
192
+ RawTx ( Transaction ) ,
193
+ Txid ( Txid ) ,
194
+ }
195
+
189
196
/// The different authentication methods for the client.
190
197
#[ derive( Clone , Debug , Hash , Eq , PartialEq , Ord , PartialOrd ) ]
191
198
pub enum Auth {
@@ -866,6 +873,23 @@ pub trait RpcApi: Sized {
866
873
self . call ( "generate" , & [ block_num. into ( ) , opt_into_json ( maxtries) ?] )
867
874
}
868
875
876
+ /// Mine a set of ordered transactions to a specified address
877
+ /// and return the block hash.
878
+ fn generate_block (
879
+ & self ,
880
+ address : & Address ,
881
+ txs : & [ MineableTx ] ,
882
+ ) -> Result < json:: GenerateBlockResult > {
883
+ let tx_strs: Vec < _ > = txs
884
+ . iter ( )
885
+ . map ( |t| match t. to_owned ( ) {
886
+ MineableTx :: RawTx ( tx) => tx. raw_hex ( ) ,
887
+ MineableTx :: Txid ( txid) => txid. to_hex ( ) ,
888
+ } )
889
+ . collect ( ) ;
890
+ self . call ( "generateblock" , & [ address. to_string ( ) . into ( ) , tx_strs. into ( ) ] )
891
+ }
892
+
869
893
/// Mark a block as invalid by `block_hash`
870
894
fn invalidate_block ( & self , block_hash : & bitcoin:: BlockHash ) -> Result < ( ) > {
871
895
self . call ( "invalidateblock" , & [ into_json ( block_hash) ?] )
0 commit comments