@@ -40,13 +40,14 @@ use crate::{
40
40
json_rpc:: Subscriptions ,
41
41
messages:: {
42
42
AddCandidates , AddPeers , AddTransaction , AuthorizeStake , BuildDrt , BuildStake ,
43
- BuildStakeParams , BuildStakeResponse , BuildVtt , ClearPeers , DropAllPeers ,
44
- EstimatePriority , GetBalance , GetBalanceTarget , GetBlocksEpochRange ,
45
- GetConsolidatedPeers , GetDataRequestInfo , GetEpoch , GetHighestCheckpointBeacon ,
46
- GetItemBlock , GetItemSuperblock , GetItemTransaction , GetKnownPeers ,
47
- GetMemoryTransaction , GetMempool , GetNodeStats , GetReputation , GetSignalingInfo ,
48
- GetState , GetSupplyInfo , GetUtxoInfo , InitializePeers , IsConfirmedBlock , QueryStake ,
49
- QueryStakesParams , Rewind , SnapshotExport , SnapshotImport , StakeAuthorization ,
43
+ BuildStakeParams , BuildStakeResponse , BuildUnstake , BuildUnstakeParams , BuildVtt ,
44
+ ClearPeers , DropAllPeers , EstimatePriority , GetBalance , GetBalanceTarget ,
45
+ GetBlocksEpochRange , GetConsolidatedPeers , GetDataRequestInfo , GetEpoch ,
46
+ GetHighestCheckpointBeacon , GetItemBlock , GetItemSuperblock , GetItemTransaction ,
47
+ GetKnownPeers , GetMemoryTransaction , GetMempool , GetNodeStats , GetReputation ,
48
+ GetSignalingInfo , GetState , GetSupplyInfo , GetUtxoInfo , InitializePeers ,
49
+ IsConfirmedBlock , QueryStake , QueryStakesParams , Rewind , SnapshotExport ,
50
+ SnapshotImport , StakeAuthorization ,
50
51
} ,
51
52
peers_manager:: PeersManager ,
52
53
sessions_manager:: SessionsManager ,
@@ -289,6 +290,15 @@ pub fn attach_sensitive_methods<H>(
289
290
|params| authorize_stake ( params. parse ( ) ) ,
290
291
) )
291
292
} ) ;
293
+
294
+ server. add_actix_method ( system, "unstake" , move |params| {
295
+ Box :: pin ( if_authorized (
296
+ enable_sensitive_methods,
297
+ "unstake" ,
298
+ params,
299
+ |params| unstake ( params. parse ( ) ) ,
300
+ ) )
301
+ } ) ;
292
302
}
293
303
294
304
fn extract_topic_and_params ( params : Params ) -> Result < ( String , Value ) , Error > {
@@ -2028,6 +2038,39 @@ pub async fn stake(params: Result<BuildStakeParams, Error>) -> JsonRpcResult {
2028
2038
. await
2029
2039
}
2030
2040
2041
+ /// Build an unstake transaction
2042
+ pub async fn unstake ( params : Result < BuildUnstakeParams , Error > ) -> JsonRpcResult {
2043
+ // Short-circuit if parameters are wrong
2044
+ let params = params?;
2045
+
2046
+ let operator = params
2047
+ . operator
2048
+ . try_do_magic ( |hex_str| PublicKeyHash :: from_bech32 ( get_environment ( ) , & hex_str) )
2049
+ . map_err ( internal_error) ?;
2050
+
2051
+ // Construct a BuildUnstake message that we can relay to the ChainManager for creation of the Unstake transaction
2052
+ let build_unstake = BuildUnstake {
2053
+ operator,
2054
+ value : params. value ,
2055
+ dry_run : params. dry_run ,
2056
+ } ;
2057
+
2058
+ ChainManager :: from_registry ( )
2059
+ . send ( build_unstake)
2060
+ . map ( |res| match res {
2061
+ Ok ( Ok ( transaction) ) => serde_json:: to_value ( transaction) . map_err ( internal_error) ,
2062
+ Ok ( Err ( e) ) => {
2063
+ let err = internal_error_s ( e) ;
2064
+ Err ( err)
2065
+ }
2066
+ Err ( e) => {
2067
+ let err = internal_error_s ( e) ;
2068
+ Err ( err)
2069
+ }
2070
+ } )
2071
+ . await
2072
+ }
2073
+
2031
2074
/// Create a stake authorization for the given address.
2032
2075
///
2033
2076
/// The output of this method is a required argument to call the Stake method.
0 commit comments