Skip to content

Commit

Permalink
feat(type): CellOutput and Epoch structures change
Browse files Browse the repository at this point in the history
Remove the data field from CellOutput and remove the epochReward field from Epoch

BREAKING CHANGE: CellOutput and Epoch structures change
  • Loading branch information
Keith-CY committed Aug 19, 2019
1 parent c1ac58f commit 8346ae4
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 75 deletions.
43 changes: 14 additions & 29 deletions packages/ckb-sdk-core/__tests__/successFixtures.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,15 @@
"emptyInfo": {
"codeHash": "",
"outPoint": {
"blockHash": "",
"cell": {
"txHash": "",
"index": "0"
}
"txHash": "",
"index": "0"
}
},
"target": {
"codeHash": "54811ce986d5c3e57eaafab22cdd080e32209e39590e204a99b32935f835a13c",
"outPoint": {
"blockHash": "0efcf4221871200e064e5c48969909ccfb04686395db5f733b0da15361c5ac04",
"cell": {
"txHash": "d0608a90cc3fd5bec9807263d3c7c93fad48a1afa0e44b38a664fbe79d4a1400",
"index": "1"
}
"txHash": "d0608a90cc3fd5bec9807263d3c7c93fad48a1afa0e44b38a664fbe79d4a1400",
"index": "1"
}
}
},
Expand All @@ -44,31 +38,24 @@
"signTransaction": {
"privateKey": "0xe79f3207ea4980b7fed79956d5934249ceac4751a4fae01a0f7c4a96884bc4e3",
"transaction": {
"deps": [
"cellDeps": [
{
"cell": {
"txHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"index": "4294967295"
},
"blockHash": "0x0000000000000000000000000000000000000000000000000000000000000000"
"txHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"index": "4294967295"
}
],
"inputs": [
{
"previousOutput": {
"cell": {
"txHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"index": "4294967295"
},
"blockHash": "0x0000000000000000000000000000000000000000000000000000000000000000"
"txHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"index": "4294967295"
},
"since": "0"
}
],
"outputs": [
{
"capacity": "5000000000000",
"data": "0x",
"lock": {
"args": [],
"codeHash": "0x0000000000000000000000000000000000000000000000000000000000000001",
Expand All @@ -77,11 +64,12 @@
"type": null
}
],
"outputData": ["0x"],
"version": "0",
"witnesses": [{ "data": [] }]
},
"target": {
"deps": [
"cellDeps": [
{
"cell": {
"txHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
Expand All @@ -93,19 +81,15 @@
"inputs": [
{
"previousOutput": {
"cell": {
"txHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"index": "4294967295"
},
"blockHash": "0x0000000000000000000000000000000000000000000000000000000000000000"
"txHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"index": "4294967295"
},
"since": "0"
}
],
"outputs": [
{
"capacity": "5000000000000",
"data": "0x",
"lock": {
"args": [],
"codeHash": "0x0000000000000000000000000000000000000000000000000000000000000001",
Expand All @@ -114,6 +98,7 @@
"type": null
}
],
"outputsData": ["0x"],
"version": "0",
"witnesses": [
{
Expand Down
11 changes: 3 additions & 8 deletions packages/ckb-sdk-core/examples/sendTransaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ const bootstrap = async () => {
codeHash: SYSTEM_ENCRYPTION_CODE_HASH,
args: [targetIdentifier],
},
data: '0x',
}

/**
Expand All @@ -154,7 +153,6 @@ const bootstrap = async () => {
codeHash: SYSTEM_ENCRYPTION_CODE_HASH,
args: [`0x${myAddressObj.identifier}`],
},
data: '0x',
}

const unspentCells = await loadCells()
Expand Down Expand Up @@ -199,8 +197,8 @@ const bootstrap = async () => {
...targetOutput,
capacity: targetOutput.capacity.toString(),
}, ]
const outputsData = outputs.map(output => output.data)

const outputsData = outputs.map(output => "0x")

const tx = {
version: '0',
Expand All @@ -210,10 +208,7 @@ const bootstrap = async () => {
}, ],
headerDeps: [],
inputs,
outputs: outputs.map(output => ({
data,
...rest
}) => rest),
outputs,
witnesses: [{
data: [],
}, ],
Expand Down
5 changes: 2 additions & 3 deletions packages/ckb-sdk-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,10 @@ class Core {
if (!block) throw new Error('Cannot load the genesis block')
const cellTx = block.transactions[0]
if (!cellTx) throw new Error('Cannot load the transaction which has the system cell')
const cell = cellTx.outputs[1]
if (!cell) throw new Error('Cannot load the system cell')
if (!cellTx.outputsData || !cellTx.outputsData[0]) throw new Error('The code data is not found')

const s = this.utils.blake2b(32, null, null, this.utils.PERSONAL)
s.update(this.utils.hexToBytes(cell.data.replace(/^0x/, '')))
s.update(this.utils.hexToBytes(cellTx.outputsData[0].replace(/^0x/, '')))
const codeHash = s.digest('hex')
const outPoint = {
blockHash: block.header.hash.replace(/^0x/, ''),
Expand Down
4 changes: 2 additions & 2 deletions packages/ckb-sdk-rpc/__tests__/formatters/params.json
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@
}
],
"version": "0",
"outputsData": []
"outputsData": ["0x"]
},
"target": {
"cell_deps": [
Expand Down Expand Up @@ -263,7 +263,7 @@
}
],
"version": "0",
"outputs_data": []
"outputs_data": ["0x"]
}
}
],
Expand Down
40 changes: 14 additions & 26 deletions packages/ckb-sdk-rpc/__tests__/formatters/result.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@
{
"source": {
"capacity": "5000000000000",
"data": "0x",
"lock": {
"args": [],
"code_hash": "0x0000000000000000000000000000000000000000000000000000000000000001",
Expand All @@ -74,7 +73,6 @@
},
"target": {
"capacity": "5000000000000",
"data": "0x",
"lock": {
"args": [],
"codeHash": "0x0000000000000000000000000000000000000000000000000000000000000001",
Expand All @@ -90,7 +88,6 @@
{
"source": {
"capacity": "5000000000000",
"data": "0x",
"lock": {
"args": [],
"code_hash": "0x0000000000000000000000000000000000000000000000000000000000000001",
Expand All @@ -100,7 +97,6 @@
},
"target": {
"capacity": "5000000000000",
"data": "0x",
"lock": {
"args": [],
"codeHash": "0x0000000000000000000000000000000000000000000000000000000000000001",
Expand Down Expand Up @@ -198,7 +194,6 @@
"outputs": [
{
"capacity": "5000000000000",
"data": "0x",
"lock": {
"args": [],
"code_hash": "0x0000000000000000000000000000000000000000000000000000000000000001",
Expand Down Expand Up @@ -227,7 +222,7 @@
"outputs": [
{
"capacity": "5000000000000",
"data": "0x",

"lock": {
"args": [],
"codeHash": "0x0000000000000000000000000000000000000000000000000000000000000001",
Expand Down Expand Up @@ -355,7 +350,7 @@
"outputs": [
{
"capacity": "5000000000000",
"data": "0x",

"lock": {
"args": [],
"code_hash": "0x0000000000000000000000000000000000000000000000000000000000000001",
Expand All @@ -366,7 +361,7 @@
],
"version": "0",
"witnesses": [],
"outputs_data": []
"outputs_data": ["0x"]
}
],
"uncles": []
Expand Down Expand Up @@ -409,7 +404,7 @@
"outputs": [
{
"capacity": "5000000000000",
"data": "0x",

"lock": {
"args": [],
"codeHash": "0x0000000000000000000000000000000000000000000000000000000000000001",
Expand All @@ -420,7 +415,7 @@
],
"version": "0",
"witnesses": [],
"outputsData": []
"outputsData": ["0x"]
}
],
"uncles": []
Expand Down Expand Up @@ -669,7 +664,7 @@
{
"source": {
"capacity": "5000000000000",
"data": "0x",

"lock": {
"args": [],
"code_hash": "0x0000000000000000000000000000000000000000000000000000000000000001",
Expand All @@ -683,7 +678,7 @@
},
"target": {
"capacity": "5000000000000",
"data": "0x",

"lock": {
"args": [],
"codeHash": "0x0000000000000000000000000000000000000000000000000000000000000001",
Expand All @@ -706,7 +701,7 @@
"source": {
"cell": {
"capacity": "5000000000000",
"data": "0x",

"lock": {
"args": [],
"code_hash": "0x0000000000000000000000000000000000000000000000000000000000000001",
Expand All @@ -719,7 +714,7 @@
"target": {
"cell": {
"capacity": "5000000000000",
"data": "0x",

"lock": {
"args": [],
"codeHash": "0x0000000000000000000000000000000000000000000000000000000000000001",
Expand Down Expand Up @@ -774,7 +769,7 @@
"source": [
{
"capacity": "5000000000000",
"data": "0x",

"lock": {
"args": [],
"code_hash": "0x0000000000000000000000000000000000000000000000000000000000000001",
Expand All @@ -786,7 +781,7 @@
"target": [
{
"capacity": "5000000000000",
"data": "0x",

"lock": {
"args": [],
"codeHash": "0x0000000000000000000000000000000000000000000000000000000000000001",
Expand Down Expand Up @@ -904,7 +899,6 @@
"outputs": [
{
"capacity": "5000000000000",
"data": "0x",
"lock": {
"args": [],
"code_hash": "0x0000000000000000000000000000000000000000000000000000000000000001",
Expand All @@ -915,7 +909,7 @@
],
"version": "0",
"witnesses": [],
"outputs_data": []
"outputs_data": ["0x"]
},
"tx_status": {
"status": "committed",
Expand All @@ -939,7 +933,6 @@
"outputs": [
{
"capacity": "5000000000000",
"data": "0x",
"lock": {
"args": [],
"codeHash": "0x0000000000000000000000000000000000000000000000000000000000000001",
Expand All @@ -950,7 +943,7 @@
],
"version": "0",
"witnesses": [],
"outputsData": []
"outputsData": ["0x"]
},
"txStatus": {
"status": "committed",
Expand All @@ -966,14 +959,12 @@
},
{
"source": {
"epoch_reward": "125000000000000",
"difficulty": "0x100",
"length": "1000",
"number": "0",
"start_number": "0"
},
"target": {
"epochReward": "125000000000000",
"difficulty": "0x100",
"length": "1000",
"number": "0",
Expand Down Expand Up @@ -1053,7 +1044,6 @@
{
"cell_output": {
"capacity": "50000000000000",
"data": "0x",
"lock": {
"args": [],
"code_hash": "0x28e83a1277d48add8e72fadaa9248559e1b632bab2bd60b27955ebc4c03800a5"
Expand All @@ -1069,7 +1059,6 @@
{
"cell_output": {
"capacity": "50000000000000",
"data": "0x",
"lock": {
"args": [],
"code_hash": "0x28e83a1277d48add8e72fadaa9248559e1b632bab2bd60b27955ebc4c03800a5"
Expand All @@ -1087,7 +1076,6 @@
{
"cellOutput": {
"capacity": "50000000000000",
"data": "0x",
"lock": {
"args": [],
"codeHash": "0x28e83a1277d48add8e72fadaa9248559e1b632bab2bd60b27955ebc4c03800a5"
Expand All @@ -1103,7 +1091,7 @@
{
"cellOutput": {
"capacity": "50000000000000",
"data": "0x",

"lock": {
"args": [],
"codeHash": "0x28e83a1277d48add8e72fadaa9248559e1b632bab2bd60b27955ebc4c03800a5"
Expand Down
Loading

0 comments on commit 8346ae4

Please sign in to comment.