Skip to content

Commit

Permalink
add a stop rpc method
Browse files Browse the repository at this point in the history
  • Loading branch information
oxarbitrage committed Sep 4, 2024
1 parent e9bbb97 commit 99e29a3
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 26 deletions.
85 changes: 59 additions & 26 deletions openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ paths:
default: getinfo
id:
type: string
default: VuJXrxLSw8
default: xdJzf6byF1
params:
type: array
items: {}
Expand Down Expand Up @@ -61,7 +61,7 @@ paths:
default: getblockchaininfo
id:
type: string
default: HDVqYXM9m6
default: PEais4MsWY
params:
type: array
items: {}
Expand Down Expand Up @@ -99,7 +99,7 @@ paths:
default: getaddressbalance
id:
type: string
default: Xw5TDBKXGl
default: NLOmcpD6Nm
params:
type: array
items: {}
Expand Down Expand Up @@ -147,7 +147,7 @@ paths:
default: sendrawtransaction
id:
type: string
default: QaJv2bXyZu
default: Zti5LiDQYq
params:
type: array
items: {}
Expand Down Expand Up @@ -196,7 +196,7 @@ paths:
default: getblock
id:
type: string
default: k0DACJrgZs
default: AelqAjCcp9
params:
type: array
items: {}
Expand Down Expand Up @@ -239,7 +239,7 @@ paths:
default: getbestblockhash
id:
type: string
default: rIFaLhZwHF
default: ms56ZPkyjR
params:
type: array
items: {}
Expand Down Expand Up @@ -272,7 +272,7 @@ paths:
default: getbestblockheightandhash
id:
type: string
default: oxrhh1swvh
default: zsIwVP8EHt
params:
type: array
items: {}
Expand Down Expand Up @@ -305,7 +305,7 @@ paths:
default: getrawmempool
id:
type: string
default: E7oUD34jk2
default: ss8TKV14Lt
params:
type: array
items: {}
Expand Down Expand Up @@ -343,7 +343,7 @@ paths:
default: z_gettreestate
id:
type: string
default: Hp22XK728i
default: l6ut9Yhuf1
params:
type: array
items: {}
Expand Down Expand Up @@ -393,7 +393,7 @@ paths:
default: z_getsubtreesbyindex
id:
type: string
default: Cs69hg68pl
default: DPcSduiZ4v
params:
type: array
items: {}
Expand Down Expand Up @@ -432,7 +432,7 @@ paths:
default: getrawtransaction
id:
type: string
default: iu395PEErc
default: G4pJjLRhM8
params:
type: array
items: {}
Expand Down Expand Up @@ -480,7 +480,7 @@ paths:
default: getaddresstxids
id:
type: string
default: z3lOKfsQdp
default: zUs7PC4saa
params:
type: array
items: {}
Expand Down Expand Up @@ -528,7 +528,7 @@ paths:
default: getaddressutxos
id:
type: string
default: '7U4Q4dSxej'
default: d0dK9Rxodt
params:
type: array
items: {}
Expand All @@ -554,6 +554,39 @@ paths:
error:
type: string
default: Invalid parameters
/stop:
post:
tags:
- control
description: Stop the running zebrad process.
requestBody:
required: true
content:
application/json:
schema:
type: object
properties:
method:
type: string
default: stop
id:
type: string
default: Ne2SAdiHQ6
params:
type: array
items: {}
default: '[]'
responses:
'200':
description: OK
content:
application/json:
schema:
type: object
properties:
result:
type: object
default: 'null'
/getblockcount:
post:
tags:
Expand All @@ -571,7 +604,7 @@ paths:
default: getblockcount
id:
type: string
default: '8yw3EX7Cwi'
default: fOj7zlU2nH
params:
type: array
items: {}
Expand Down Expand Up @@ -609,7 +642,7 @@ paths:
default: getblockhash
id:
type: string
default: ndDYksCl9E
default: sGn1AKxoSI
params:
type: array
items: {}
Expand Down Expand Up @@ -657,7 +690,7 @@ paths:
default: getblocktemplate
id:
type: string
default: lJi2hfxty1
default: myNPJd0sfe
params:
type: array
items: {}
Expand Down Expand Up @@ -695,7 +728,7 @@ paths:
default: submitblock
id:
type: string
default: '9fEFOdTQle'
default: Lz3WKNvW5m
params:
type: array
items: {}
Expand Down Expand Up @@ -728,7 +761,7 @@ paths:
default: getmininginfo
id:
type: string
default: Dytpq4f3lF
default: Va3AezTnpd
params:
type: array
items: {}
Expand Down Expand Up @@ -761,7 +794,7 @@ paths:
default: getnetworksolps
id:
type: string
default: yX3woRnOaN
default: ElLrKdyP3K
params:
type: array
items: {}
Expand Down Expand Up @@ -794,7 +827,7 @@ paths:
default: getnetworkhashps
id:
type: string
default: AyAZMtbezv
default: '4K77iPcVNQ'
params:
type: array
items: {}
Expand Down Expand Up @@ -827,7 +860,7 @@ paths:
default: getpeerinfo
id:
type: string
default: nNcrsu3ZAR
default: cKwQK7ecPf
params:
type: array
items: {}
Expand Down Expand Up @@ -865,7 +898,7 @@ paths:
default: validateaddress
id:
type: string
default: LGyfO7zTjW
default: HocrQHBT4d
params:
type: array
items: {}
Expand Down Expand Up @@ -903,7 +936,7 @@ paths:
default: z_validateaddress
id:
type: string
default: '2Q09a2Nh4N'
default: KK7aGnvm92
params:
type: array
items: {}
Expand Down Expand Up @@ -941,7 +974,7 @@ paths:
default: getblocksubsidy
id:
type: string
default: nv6lOWCRso
default: VqVJz06ITo
params:
type: array
items: {}
Expand Down Expand Up @@ -984,7 +1017,7 @@ paths:
default: getdifficulty
id:
type: string
default: '2O3A0PF1SS'
default: ryZBiEydIb
params:
type: array
items: {}
Expand Down Expand Up @@ -1022,7 +1055,7 @@ paths:
default: z_listunifiedreceivers
id:
type: string
default: XYgGcDIx2X
default: '3yyYW5OaGD'
params:
type: array
items: {}
Expand Down
24 changes: 24 additions & 0 deletions zebra-rpc/src/methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,18 @@ pub trait Rpc {
&self,
address_strings: AddressStrings,
) -> BoxFuture<Result<Vec<GetAddressUtxos>>>;

#[rpc(name = "stop")]
/// Stop the running zebrad process.

Check failure on line 306 in zebra-rpc/src/methods.rs

View workflow job for this annotation

GitHub Actions / Build and Deploy Zebra Internal Docs

this URL is not a hyperlink
///
/// # Notes
///
/// Only works if the network of the running zebrad process is `Regtest`.
///
/// zcashd reference: https://zcash.github.io/rpc/stop.html
/// method: post
/// tags: control
fn stop(&self) -> Result<()>;
}

/// RPC method implementations.
Expand Down Expand Up @@ -1344,6 +1356,18 @@ where
}
.boxed()
}

fn stop(&self) -> Result<()> {
if self.network.is_regtest() {
std::process::exit(0);
} else {
Err(Error {
code: ErrorCode::MethodNotFound,
message: "stop is only available on regtest networks".to_string(),
data: None,
})
}
}
}

/// Returns the best chain tip height of `latest_chain_tip`,
Expand Down
1 change: 1 addition & 0 deletions zebra-utils/src/bin/openapi-generator/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,7 @@ fn get_default_properties(method_name: &str) -> Result<IndexMap<String, Property
)?,
// control
"getinfo" => default_property(type_, items.clone(), GetInfo::default())?,
"stop" => default_property(type_, items.clone(), ())?,
// transaction
"sendrawtransaction" => {
default_property(type_, items.clone(), SentTransactionHash::default())?
Expand Down

0 comments on commit 99e29a3

Please sign in to comment.