Skip to content

Commit

Permalink
feat(rpc): update get blockchain info rpc
Browse files Browse the repository at this point in the history
remove warnings field and add alerts field

BREAKING CHANGE: replace warnings field with alerts field in the response of get blockchain info rpc
  • Loading branch information
Keith-CY committed Jun 19, 2019
1 parent d93b4ed commit 7382458
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 5 deletions.
4 changes: 2 additions & 2 deletions packages/ckb-sdk-rpc/__tests__/formatters/fixtures.json
Original file line number Diff line number Diff line change
Expand Up @@ -451,15 +451,15 @@
"difficulty": "0x100",
"median_time": "1557287480008",
"chain": "ckb_dev",
"warnings": ""
"alerts": []
},
"target": {
"isInitialBlockDownload": false,
"epoch": "0",
"difficulty": "0x100",
"medianTime": "1557287480008",
"chain": "ckb_dev",
"warnings": ""
"alerts": []
}
}],
"toNodeInfo": [{
Expand Down
11 changes: 10 additions & 1 deletion packages/ckb-sdk-rpc/src/resultFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,21 @@ const formatter = {
...rest,
}
},
toAlertMessage: (alertMessage: CKB_RPC.AlertMessage): CKBComponents.AlertMessage => {
if (!alertMessage) return alertMessage
const { notice_until: noticeUntil, ...rest } = alertMessage
return {
noticeUntil,
...rest,
}
},
toBlockchainInfo: (info: CKB_RPC.BlockchainInfo): CKBComponents.BlockchainInfo => {
if (!info) return info
const { is_initial_block_download: isInitialBlockDownload, median_time: medianTime, ...rest } = info
const { is_initial_block_download: isInitialBlockDownload, median_time: medianTime, alerts, ...rest } = info
return {
isInitialBlockDownload,
medianTime,
alerts: alerts.map(formatter.toAlertMessage),
...rest,
}
},
Expand Down
9 changes: 8 additions & 1 deletion packages/ckb-sdk-rpc/types/CKB_RPC/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,20 @@ declare module CKB_RPC {
proposals: ProposalShortId[]
}

export interface AlertMessage {
id: string
priority: string
notice_until: Timestamp
message: string
}

export interface BlockchainInfo {
is_initial_block_download: boolean
epoch: string
difficulty: string
median_time: string
chain: string
warnings: string
alerts: AlertMessage[]
}

export interface NodeInfo {
Expand Down
9 changes: 8 additions & 1 deletion packages/ckb-types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,13 +215,20 @@ declare namespace CKBComponents {
Unknown = 'unknown',
}

export interface AlertMessage {
id: string
priority: string
noticeUntil: Timestamp
message: string
}

export interface BlockchainInfo {
isInitialBlockDownload: boolean
epoch: string
difficulty: string
medianTime: string
chain: string
warnings: string
alerts: AlertMessage[]
}

export interface NodeInfo {
Expand Down

0 comments on commit 7382458

Please sign in to comment.