@@ -11,6 +11,8 @@ use tokio::sync::mpsc::{self, error::SendError, Sender};
1111use tokio_stream:: wrappers:: ReceiverStream ;
1212use tonic:: { transport:: Channel as TonicChannel , Streaming } ;
1313
14+ static EXTRA_DATA : & str = concat ! ( env!( "CARGO_PKG_VERSION" ) ) ;
15+
1416#[ allow( dead_code) ]
1517pub struct KaspadHandler {
1618 client : RpcClient < TonicChannel > ,
@@ -32,7 +34,12 @@ impl KaspadHandler {
3234 let mut client = RpcClient :: connect ( address) . await ?;
3335 let ( send_channel, recv) = mpsc:: channel ( 3 ) ;
3436 send_channel. send ( GetInfoRequestMessage { } . into ( ) ) . await ?;
35- send_channel. send ( GetBlockTemplateRequestMessage { pay_address : miner_address. clone ( ) } . into ( ) ) . await ?;
37+ send_channel
38+ . send (
39+ GetBlockTemplateRequestMessage { pay_address : miner_address. clone ( ) , extra_data : EXTRA_DATA . into ( ) }
40+ . into ( ) ,
41+ )
42+ . await ?;
3643 let stream = client. message_stream ( ReceiverStream :: new ( recv) ) . await ?. into_inner ( ) ;
3744 Ok ( Self {
3845 client,
@@ -63,7 +70,7 @@ impl KaspadHandler {
6370 _ => self . miner_address . clone ( ) ,
6471 } ;
6572 self . block_template_ctr += 1 ;
66- self . client_send ( GetBlockTemplateRequestMessage { pay_address } ) . await
73+ self . client_send ( GetBlockTemplateRequestMessage { pay_address, extra_data : EXTRA_DATA . into ( ) } ) . await
6774 }
6875
6976 pub async fn listen ( & mut self , miner : & mut MinerManager , shutdown : ShutdownHandler ) -> Result < ( ) , Error > {
@@ -81,7 +88,7 @@ impl KaspadHandler {
8188
8289 async fn handle_message ( & mut self , msg : Payload , miner : & mut MinerManager ) -> Result < ( ) , Error > {
8390 match msg {
84- Payload :: BlockAddedNotification ( _) => self . client_get_block_template ( ) . await ?,
91+ Payload :: NewBlockTemplateNotification ( _) => self . client_get_block_template ( ) . await ?,
8592 Payload :: GetBlockTemplateResponse ( template) => match ( template. block , template. is_synced , template. error ) {
8693 ( Some ( b) , true , None ) => miner. process_block ( Some ( b) ) ?,
8794 ( Some ( b) , false , None ) if self . mine_when_not_synced => miner. process_block ( Some ( b) ) ?,
@@ -100,9 +107,9 @@ impl KaspadHandler {
100107 info ! ( "Get block response: {:?}" , msg) ;
101108 }
102109 Payload :: GetInfoResponse ( info) => info ! ( "Kaspad version: {}" , info. server_version) ,
103- Payload :: NotifyBlockAddedResponse ( res) => match res. error {
104- None => info ! ( "Registered for block notifications" ) ,
105- Some ( e) => error ! ( "Failed registering for block notifications: {:?}" , e) ,
110+ Payload :: NotifyNewBlockTemplateResponse ( res) => match res. error {
111+ None => info ! ( "Registered for new template notifications" ) ,
112+ Some ( e) => error ! ( "Failed registering for new template notifications: {:?}" , e) ,
106113 } ,
107114 msg => info ! ( "Got unknown msg: {:?}" , msg) ,
108115 }
0 commit comments