11use std:: num:: NonZeroU32 ;
22
33use anyhow:: { Context , Result } ;
4+ use tycho_types:: abi:: extend_signature_with_id;
45use tycho_types:: cell:: Lazy ;
56use tycho_types:: dict;
67use tycho_types:: models:: {
@@ -10,11 +11,17 @@ use tycho_types::prelude::*;
1011
1112use super :: { BlocksBatch , SignedMessage , SlasherContract } ;
1213
13- pub struct StubContract ;
14+ const PARAM_IDX : u32 = 666 ;
1415
15- impl SlasherContract for StubContract {
16- fn find_account_address ( & self , _config : & BlockchainConfigParams ) -> Result < Option < StdAddr > > {
17- Ok ( None )
16+ pub struct StubSlasherContract ;
17+
18+ impl SlasherContract for StubSlasherContract {
19+ fn find_account_address ( & self , config : & BlockchainConfigParams ) -> Result < Option < StdAddr > > {
20+ let Some ( raw) = config. get_raw_cell_ref ( PARAM_IDX ) ? else {
21+ return Ok ( None ) ;
22+ } ;
23+ let address = raw. parse :: < HashBytes > ( ) ?;
24+ Ok ( Some ( StdAddr :: new ( -1 , address) ) )
1825 }
1926
2027 fn default_batch_size ( & self ) -> NonZeroU32 {
@@ -33,16 +40,35 @@ impl SlasherContract for StubContract {
3340 . context ( "failed to serialize blocks batch" ) ?;
3441
3542 let now = tycho_util:: time:: now_millis ( ) ;
36-
3743 let expire_at = ( now / 1000 ) . saturating_add ( params. ttl . as_secs ( ) ) as u32 ;
44+ let body_to_sign = {
45+ let mut b = CellBuilder :: new ( ) ;
46+ b. store_u64 ( now) ?;
47+ b. store_u32 ( expire_at) ?;
48+ b. store_u16 ( params. validator_idx ) ?;
49+ b. store_reference ( cell) ?;
50+ b. build ( ) ?
51+ } ;
52+
53+ // TODO: Add support for signature id.
54+ let signature = params. keypair . sign_raw ( & extend_signature_with_id (
55+ body_to_sign. repr_hash ( ) . as_array ( ) ,
56+ None ,
57+ ) ) ;
58+ let body = {
59+ let mut b = CellBuilder :: new ( ) ;
60+ b. store_raw ( & signature, 512 ) ?;
61+ b. store_slice ( body_to_sign. as_slice ( ) ?) ?;
62+ b. build ( ) ?
63+ } ;
64+
3865 let message = Lazy :: new ( & OwnedMessage {
3966 info : MsgInfo :: ExtIn ( ExtInMsgInfo {
40- // Stub address.
41- dst : StdAddr :: new ( -1 , HashBytes :: ZERO ) . into ( ) ,
67+ dst : params. address . clone ( ) . into ( ) ,
4268 ..Default :: default ( )
4369 } ) ,
4470 init : None ,
45- body : cell . into ( ) ,
71+ body : body . into ( ) ,
4672 layout : None ,
4773 } ) ?;
4874
0 commit comments