From 58c055c4b25fbd1f7abf78c334ca27e6c2566623 Mon Sep 17 00:00:00 2001 From: Keith Date: Mon, 30 Aug 2021 15:57:06 +0800 Subject: [PATCH] feat(rpc): rename 'uncles_hash' to 'extra_hash' in block header The field 'uncles_hash' in block header is renamed to 'extra_hash' BREAKING CHANGE: The field 'uncles_hash' in block header is renamed to 'extra_hash' ref: https://github.com/nervosnetwork/rfcs/pull/224 --- .../__mocks__/data/genesisBlock.json | 2 +- .../ckb-sdk-rpc/__tests__/ckb-rpc.test.js | 24 +++++++++---------- .../__tests__/formatters/result.fixtures.json | 16 ++++++------- packages/ckb-sdk-rpc/src/resultFormatter.ts | 19 ++++++++++----- packages/ckb-sdk-rpc/types/rpc/index.d.ts | 2 +- packages/ckb-types/index.d.ts | 4 ++-- 6 files changed, 37 insertions(+), 30 deletions(-) diff --git a/packages/ckb-sdk-core/__mocks__/data/genesisBlock.json b/packages/ckb-sdk-core/__mocks__/data/genesisBlock.json index 8d8aedd3..313ed072 100644 --- a/packages/ckb-sdk-core/__mocks__/data/genesisBlock.json +++ b/packages/ckb-sdk-core/__mocks__/data/genesisBlock.json @@ -4,7 +4,7 @@ "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000", "transactionsRoot": "0x0d31bf4fe7d0274d8331c76b320dbb0c9557a21fdf599e9f56d8c369529f8961", "proposalsHash": "0x0000000000000000000000000000000000000000000000000000000000000000", - "unclesHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "extraHash": "0x0000000000000000000000000000000000000000000000000000000000000000", "dao": "0x0469b82c6c1ea12e0000c16ff286230066cbed490e00000000b2b49f02fbfe06", "epoch": "0x0", "hash": "0x184ac4658ed0c04a126551257990db132366cac22ab6270bbbc1f8c3220f302d", diff --git a/packages/ckb-sdk-rpc/__tests__/ckb-rpc.test.js b/packages/ckb-sdk-rpc/__tests__/ckb-rpc.test.js index 34c0d154..ba448a66 100644 --- a/packages/ckb-sdk-rpc/__tests__/ckb-rpc.test.js +++ b/packages/ckb-sdk-rpc/__tests__/ckb-rpc.test.js @@ -46,7 +46,7 @@ describe('Test with mock', () => { proposals_hash: '0x0000000000000000000000000000000000000000000000000000000000000000', timestamp: '0x5cd2b117', transactions_root: '0xc47d5b78b3c4c4c853e2a32810818940d0ee403423bea9ec7b8e566d9595206c', - uncles_hash: '0x0000000000000000000000000000000000000000000000000000000000000000', + extra_hash: '0x0000000000000000000000000000000000000000000000000000000000000000', version: '0x0', }, proposals: [], @@ -105,7 +105,7 @@ describe('Test with mock', () => { proposalsHash: '0x0000000000000000000000000000000000000000000000000000000000000000', timestamp: '0x5cd2b117', transactionsRoot: '0xc47d5b78b3c4c4c853e2a32810818940d0ee403423bea9ec7b8e566d9595206c', - unclesHash: '0x0000000000000000000000000000000000000000000000000000000000000000', + extraHash: '0x0000000000000000000000000000000000000000000000000000000000000000', version: '0x0', }, proposals: [], @@ -829,7 +829,7 @@ describe('Test with mock', () => { proposals_hash: '0x0000000000000000000000000000000000000000000000000000000000000000', timestamp: '0x172a8804ad1', transactions_root: '0xcde937f363e195a97467061a45a6b5b318da02fc3fec5e76ab298e41ace0b7a1', - uncles_hash: '0x0000000000000000000000000000000000000000000000000000000000000000', + extra_hash: '0x0000000000000000000000000000000000000000000000000000000000000000', version: '0x0', }, proposals: [], @@ -890,7 +890,7 @@ describe('Test with mock', () => { proposalsHash: '0x0000000000000000000000000000000000000000000000000000000000000000', timestamp: '0x172a8804ad1', transactionsRoot: '0xcde937f363e195a97467061a45a6b5b318da02fc3fec5e76ab298e41ace0b7a1', - unclesHash: '0x0000000000000000000000000000000000000000000000000000000000000000', + extraHash: '0x0000000000000000000000000000000000000000000000000000000000000000', version: '0x0', }, proposals: [], @@ -945,7 +945,7 @@ describe('Test with mock', () => { proposals_hash: '0x0000000000000000000000000000000000000000000000000000000000000000', timestamp: '0x172a8804ad1', transactions_root: '0xcde937f363e195a97467061a45a6b5b318da02fc3fec5e76ab298e41ace0b7a1', - uncles_hash: '0x0000000000000000000000000000000000000000000000000000000000000000', + extra_hash: '0x0000000000000000000000000000000000000000000000000000000000000000', version: '0x0', }, id, @@ -969,7 +969,7 @@ describe('Test with mock', () => { proposalsHash: '0x0000000000000000000000000000000000000000000000000000000000000000', timestamp: '0x172a8804ad1', transactionsRoot: '0xcde937f363e195a97467061a45a6b5b318da02fc3fec5e76ab298e41ace0b7a1', - unclesHash: '0x0000000000000000000000000000000000000000000000000000000000000000', + extraHash: '0x0000000000000000000000000000000000000000000000000000000000000000', version: '0x0', }) }) @@ -1307,7 +1307,7 @@ describe('Test with mock', () => { proposals_hash: '0x0000000000000000000000000000000000000000000000000000000000000000', timestamp: '0x172a8804ad1', transactions_root: '0xcde937f363e195a97467061a45a6b5b318da02fc3fec5e76ab298e41ace0b7a1', - uncles_hash: '0x0000000000000000000000000000000000000000000000000000000000000000', + extra_hash: '0x0000000000000000000000000000000000000000000000000000000000000000', version: '0x0', }, id, @@ -1331,7 +1331,7 @@ describe('Test with mock', () => { proposalsHash: '0x0000000000000000000000000000000000000000000000000000000000000000', timestamp: '0x172a8804ad1', transactionsRoot: '0xcde937f363e195a97467061a45a6b5b318da02fc3fec5e76ab298e41ace0b7a1', - unclesHash: '0x0000000000000000000000000000000000000000000000000000000000000000', + extraHash: '0x0000000000000000000000000000000000000000000000000000000000000000', version: '0x0', }) }) @@ -1352,7 +1352,7 @@ describe('Test with mock', () => { proposals_hash: '0x0000000000000000000000000000000000000000000000000000000000000000', timestamp: '0x1725940cb91', transactions_root: '0xcd95e31e21734fb796de0070407c1d4f91ec00d699f840e5ad9aa293443744e6', - uncles_hash: '0x0000000000000000000000000000000000000000000000000000000000000000', + extra_hash: '0x0000000000000000000000000000000000000000000000000000000000000000', version: '0x0', }, id, @@ -1376,7 +1376,7 @@ describe('Test with mock', () => { proposalsHash: '0x0000000000000000000000000000000000000000000000000000000000000000', timestamp: '0x1725940cb91', transactionsRoot: '0xcd95e31e21734fb796de0070407c1d4f91ec00d699f840e5ad9aa293443744e6', - unclesHash: '0x0000000000000000000000000000000000000000000000000000000000000000', + extraHash: '0x0000000000000000000000000000000000000000000000000000000000000000', version: '0x0', }) }) @@ -1539,7 +1539,7 @@ describe('Test with mock', () => { proposals_hash: '0x0000000000000000000000000000000000000000000000000000000000000000', timestamp: '0x1725940cb91', transactions_root: '0xcd95e31e21734fb796de0070407c1d4f91ec00d699f840e5ad9aa293443744e6', - uncles_hash: '0x0000000000000000000000000000000000000000000000000000000000000000', + extra_hash: '0x0000000000000000000000000000000000000000000000000000000000000000', version: '0x0', }, proposals: [], @@ -1617,7 +1617,7 @@ describe('Test with mock', () => { proposalsHash: '0x0000000000000000000000000000000000000000000000000000000000000000', timestamp: '0x1725940cb91', transactionsRoot: '0xcd95e31e21734fb796de0070407c1d4f91ec00d699f840e5ad9aa293443744e6', - unclesHash: '0x0000000000000000000000000000000000000000000000000000000000000000', + extraHash: '0x0000000000000000000000000000000000000000000000000000000000000000', version: '0x0', }, proposals: [], diff --git a/packages/ckb-sdk-rpc/__tests__/formatters/result.fixtures.json b/packages/ckb-sdk-rpc/__tests__/formatters/result.fixtures.json index 54b8a28d..66452e82 100644 --- a/packages/ckb-sdk-rpc/__tests__/formatters/result.fixtures.json +++ b/packages/ckb-sdk-rpc/__tests__/formatters/result.fixtures.json @@ -281,7 +281,7 @@ "nonce": "0", "timestamp": "1557311767", "transactions_root": "0x64a872caca3c7b671b64897230e88dec8800b594347d192661908a87f7fbcb9b", - "uncles_hash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "extra_hash": "0x0000000000000000000000000000000000000000000000000000000000000000", "version": "0" }, "proposals": [] @@ -298,7 +298,7 @@ "nonce": "0", "timestamp": "1557311767", "transactionsRoot": "0x64a872caca3c7b671b64897230e88dec8800b594347d192661908a87f7fbcb9b", - "unclesHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "extraHash": "0x0000000000000000000000000000000000000000000000000000000000000000", "version": "0" }, "proposals": [] @@ -323,7 +323,7 @@ "nonce": "0", "timestamp": "1557311767", "transactions_root": "0x64a872caca3c7b671b64897230e88dec8800b594347d192661908a87f7fbcb9b", - "uncles_hash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "extra_hash": "0x0000000000000000000000000000000000000000000000000000000000000000", "version": "0" }, "proposals": [], @@ -372,7 +372,7 @@ "nonce": "0", "timestamp": "1557311767", "transactionsRoot": "0x64a872caca3c7b671b64897230e88dec8800b594347d192661908a87f7fbcb9b", - "unclesHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "extraHash": "0x0000000000000000000000000000000000000000000000000000000000000000", "version": "0" }, "proposals": [], @@ -423,7 +423,7 @@ "nonce": "0", "timestamp": "1557311767", "transactions_root": "0x64a872caca3c7b671b64897230e88dec8800b594347d192661908a87f7fbcb9b", - "uncles_hash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "extra_hash": "0x0000000000000000000000000000000000000000000000000000000000000000", "version": "0" }, "proposals": [] @@ -440,7 +440,7 @@ "nonce": "0", "timestamp": "1557311767", "transactionsRoot": "0x64a872caca3c7b671b64897230e88dec8800b594347d192661908a87f7fbcb9b", - "unclesHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "extraHash": "0x0000000000000000000000000000000000000000000000000000000000000000", "version": "0" }, "proposals": [], @@ -960,7 +960,7 @@ "proposals_hash": "0x0000000000000000000000000000000000000000000000000000000000000000", "timestamp": "0x5cd2b117", "transactions_root": "0x7fe9a50693f3e0a7418c7a99e9a298f8d0806b149bed700bb09c1f35a63100ce", - "uncles_hash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "extra_hash": "0x0000000000000000000000000000000000000000000000000000000000000000", "version": "0x0" }, "expected": { @@ -974,7 +974,7 @@ "proposalsHash": "0x0000000000000000000000000000000000000000000000000000000000000000", "timestamp": "0x5cd2b117", "transactionsRoot": "0x7fe9a50693f3e0a7418c7a99e9a298f8d0806b149bed700bb09c1f35a63100ce", - "unclesHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "extraHash": "0x0000000000000000000000000000000000000000000000000000000000000000", "version": "0x0" } } diff --git a/packages/ckb-sdk-rpc/src/resultFormatter.ts b/packages/ckb-sdk-rpc/src/resultFormatter.ts index ad5848e1..5073fd71 100644 --- a/packages/ckb-sdk-rpc/src/resultFormatter.ts +++ b/packages/ckb-sdk-rpc/src/resultFormatter.ts @@ -8,13 +8,20 @@ const formatter = { toHash: (hash: RPC.Hash256): CKBComponents.Hash256 => hash, toHeader: (header: RPC.Header): CKBComponents.BlockHeader => { if (!header) return header - const { compact_target, transactions_root, proposals_hash, uncles_hash, parent_hash, ...rest } = header + const { + compact_target: compactTarget, + transactions_root: transactionsRoot, + proposals_hash: proposalsHash, + extra_hash: extraHash, + parent_hash: parentHash, + ...rest + } = header return { - compactTarget: compact_target, - parentHash: parent_hash, - transactionsRoot: transactions_root, - proposalsHash: proposals_hash, - unclesHash: uncles_hash, + compactTarget, + parentHash, + transactionsRoot, + proposalsHash, + extraHash, ...rest, } }, diff --git a/packages/ckb-sdk-rpc/types/rpc/index.d.ts b/packages/ckb-sdk-rpc/types/rpc/index.d.ts index 9133b0ae..ec541071 100644 --- a/packages/ckb-sdk-rpc/types/rpc/index.d.ts +++ b/packages/ckb-sdk-rpc/types/rpc/index.d.ts @@ -141,7 +141,7 @@ declare module RPC { nonce: CKBComponents.Nonce timestamp: Timestamp transactions_root: Hash256 - uncles_hash: Hash256 + extra_hash: Hash256 version: Version } diff --git a/packages/ckb-types/index.d.ts b/packages/ckb-types/index.d.ts index fd627578..96209de1 100644 --- a/packages/ckb-types/index.d.ts +++ b/packages/ckb-types/index.d.ts @@ -199,7 +199,7 @@ declare namespace CKBComponents { * @property nonce * @property timestamp * @property transactionsRoot - * @property unclesHash + * @property extraHash * @property version */ export interface BlockHeader { @@ -213,7 +213,7 @@ declare namespace CKBComponents { nonce: Nonce timestamp: Timestamp transactionsRoot: Hash256 - unclesHash: Hash256 + extraHash: Hash256 version: Version }