Skip to content

Commit

Permalink
Merge pull request #1106 from jjyr/rpc-doc-add-alert
Browse files Browse the repository at this point in the history
doc: add alerts example in RPC doc
  • Loading branch information
jjyr authored Jun 25, 2019
2 parents aa23f2e + 596d6c7 commit 79c37bf
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 5 deletions.
9 changes: 8 additions & 1 deletion rpc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1253,7 +1253,14 @@ http://localhost:8114
"id": 2,
"jsonrpc": "2.0",
"result": {
"alerts": [],
"alerts": [
{
"id": "42",
"message": "An example alert message!",
"notice_until": "2524579200000",
"priority": "1"
}
],
"chain": "main",
"difficulty": "0x3e8",
"epoch": "0",
Expand Down
9 changes: 8 additions & 1 deletion rpc/json/rpc.json
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,14 @@
"module": "stats",
"params": [],
"result": {
"alerts": [],
"alerts": [
{
"id": "42",
"message": "An example alert message!",
"notice_until": "2524579200000",
"priority": "1"
}
],
"chain": "main",
"difficulty": "0x3e8",
"epoch": "0",
Expand Down
21 changes: 18 additions & 3 deletions rpc/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use ckb_core::block::BlockBuilder;
use ckb_core::header::HeaderBuilder;
use ckb_core::script::Script;
use ckb_core::transaction::{CellInput, CellOutput, OutPoint, Transaction, TransactionBuilder};
use ckb_core::{capacity_bytes, BlockNumber, Bytes, Capacity};
use ckb_core::{alert::AlertBuilder, capacity_bytes, BlockNumber, Bytes, Capacity};
use ckb_db::DBConfig;
use ckb_db::MemoryKeyValueDB;
use ckb_indexer::{DefaultIndexerStore, IndexerStore};
Expand All @@ -34,6 +34,7 @@ use std::path::PathBuf;
use std::sync::Arc;

const GENESIS_TIMESTAMP: u64 = 1_557_310_743;
const ALERT_UNTIL_TIMESTAMP: u64 = 2_524_579_200;

#[derive(Debug, Deserialize, Clone)]
pub struct JsonResponse {
Expand Down Expand Up @@ -180,9 +181,23 @@ fn setup_node(
}
.to_delegate(),
);
let alert_relayer = AlertRelayer::new("0".to_string(), AlertConfig::default());
let alert_relayer = AlertRelayer::new("0.1".to_string(), AlertConfig::default());

let alert_notifier = Arc::clone(alert_relayer.notifier());
let alert_notifier = {
let alert_notifier = alert_relayer.notifier();
let alert = Arc::new(
AlertBuilder::default()
.id(42)
.min_version(Some("0.0.1".into()))
.max_version(Some("1.0.0".into()))
.priority(1)
.notice_until(ALERT_UNTIL_TIMESTAMP * 1000)
.message("An example alert message!".into())
.build(),
);
alert_notifier.lock().add(alert);
Arc::clone(alert_notifier)
};
io.extend_with(
StatsRpcImpl {
shared: shared.clone(),
Expand Down

0 comments on commit 79c37bf

Please sign in to comment.