Skip to content

Commit

Permalink
feat(type): OutPoint structure changes
Browse files Browse the repository at this point in the history
OutPoint only includes txHash and index

BREAKING CHANGE: OutPoint structure changes
  • Loading branch information
Keith-CY committed Aug 16, 2019
1 parent a7f3253 commit 38ba007
Show file tree
Hide file tree
Showing 6 changed files with 128 additions and 179 deletions.
120 changes: 75 additions & 45 deletions packages/ckb-sdk-rpc/__tests__/formatters/params.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@
"target": "0xe5f2d07b747f38718293987a9175764d4c03229a8a69d0bd48f7bea6c18930b1"
}
],
"toCellOutPoint": [
"toOutPoint": [
{
"source": null,
"target": null
},
{
"source": {
"txHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
Expand All @@ -26,76 +30,105 @@
"target": null
}
],
"toOutPoint": [
"toNumber": [
{
"source": "1",
"target": "1"
}
],

"toInput": [
{
"source": null,
"target": null
},
{
"source": {
"cell": {
"previousOutput": null,
"since": 0
},
"target": {
"previous_output": null,
"since": 0
}
},
{
"source": {
"previousOutput": {
"txHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"index": "4294967295"
},
"blockHash": "0x0000000000000000000000000000000000000000000000000000000000000000"
"since": "0"
},
"target": {
"cell": {
"previous_output": {
"tx_hash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"index": "4294967295"
},
"block_hash": "0x0000000000000000000000000000000000000000000000000000000000000000"
"since": "0"
}
},
}
],
"toOutput": [
{
"source": {
"cell": null,
"blockHash": "0x0000000000000000000000000000000000000000000000000000000000000000"
},
"target": {
"cell": null,
"block_hash": "0x0000000000000000000000000000000000000000000000000000000000000000"
}
"source": null,
"target": null
},
{
"source": {
"cell": null,
"blockHash": null
"capacity": "5000000000000",
"data": "0x",
"lock": {
"args": [],
"codeHash": "0x0000000000000000000000000000000000000000000000000000000000000001",
"hashType": "Data"
},
"type": null
},
"target": {
"cell": null,
"block_hash": null
"capacity": "5000000000000",
"data": "0x",
"lock": {
"args": [],
"code_hash": "0x0000000000000000000000000000000000000000000000000000000000000001",
"hash_type": "Data"
},
"type": null
}
},
{
"source": {
"blockHash": "0x0000000000000000000000000000000000000000000000000000000000000000"
"capacity": "5000000000000",
"data": "0x",
"lock": {
"args": [],
"codeHash": "0x0000000000000000000000000000000000000000000000000000000000000001",
"hashType": "Data"
}
},
"target": {
"cell": null,
"block_hash": "0x0000000000000000000000000000000000000000000000000000000000000000"
}
},
{
"source": {},
"target": {
"cell": null,
"block_hash": null
"capacity": "5000000000000",
"data": "0x",
"lock": {
"args": [],
"code_hash": "0x0000000000000000000000000000000000000000000000000000000000000001",
"hash_type": "Data"
},
"type": null
}
}
],
"toNumber": [
{
"source": "1",
"target": "1"
}
],
"toRawTransaction": [
{
"source": null,
"target": null
},
{
"source": {
"deps": [
{
"cell": {
"txHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"index": "4294967295"
},
"blockHash": "0x0000000000000000000000000000000000000000000000000000000000000000"
"txHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"index": "4294967295"
}
],
"inputs": [
Expand Down Expand Up @@ -128,11 +161,8 @@
"target": {
"deps": [
{
"cell": {
"tx_hash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"index": "4294967295"
},
"block_hash": "0x0000000000000000000000000000000000000000000000000000000000000000"
"tx_hash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"index": "4294967295"
}
],
"inputs": [
Expand Down
83 changes: 9 additions & 74 deletions packages/ckb-sdk-rpc/__tests__/formatters/result.json
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
}
}
],
"toCellOutPoint": [
"toOutPoint": [
{
"source": null,
"target": null
Expand All @@ -126,59 +126,6 @@
}
}
],
"toOutPoint": [
{
"source": null,
"target": null
},
{
"source": {
"block_hash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"cell": {
"tx_hash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"index": "4294967295"
}
},
"target": {
"blockHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"cell": {
"txHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"index": "4294967295"
}
}
},
{
"source": {
"block_hash": "0x0000000000000000000000000000000000000000000000000000000000000000"
},
"target": {
"blockHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"cell": null
}
},
{
"source": {
"cell": {
"tx_hash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"index": "4294967295"
}
},
"target": {
"blockHash": null,
"cell": {
"txHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"index": "4294967295"
}
}
},
{
"source": {},
"target": {
"blockHash": null,
"cell": null
}
}
],
"toTransaction": [
{
"source": null,
Expand Down Expand Up @@ -739,11 +686,8 @@
"type": null,
"capacity": "5000000000000",
"out_point": {
"block_hash": null,
"cell": {
"index": "0",
"tx_hash": "0xecd3917b7d9833a34d30da39b943b1811163f30771aae3165f60529955afb37f"
}
"index": "0",
"tx_hash": "0xecd3917b7d9833a34d30da39b943b1811163f30771aae3165f60529955afb37f"
}
},
"target": {
Expand All @@ -755,11 +699,8 @@
"type": null,
"capacity": "5000000000000",
"outPoint": {
"blockHash": null,
"cell": {
"index": "0",
"txHash": "0xecd3917b7d9833a34d30da39b943b1811163f30771aae3165f60529955afb37f"
}
"index": "0",
"txHash": "0xecd3917b7d9833a34d30da39b943b1811163f30771aae3165f60529955afb37f"
}
}
}
Expand Down Expand Up @@ -808,11 +749,8 @@
"type": null,
"capacity": "5000000000000",
"out_point": {
"block_hash": null,
"cell": {
"index": "0",
"tx_hash": "0xecd3917b7d9833a34d30da39b943b1811163f30771aae3165f60529955afb37f"
}
"index": "0",
"tx_hash": "0xecd3917b7d9833a34d30da39b943b1811163f30771aae3165f60529955afb37f"
}
}
],
Expand All @@ -826,11 +764,8 @@
"type": null,
"capacity": "5000000000000",
"outPoint": {
"blockHash": null,
"cell": {
"index": "0",
"txHash": "0xecd3917b7d9833a34d30da39b943b1811163f30771aae3165f60529955afb37f"
}
"index": "0",
"txHash": "0xecd3917b7d9833a34d30da39b943b1811163f30771aae3165f60529955afb37f"
}
}
]
Expand Down
60 changes: 31 additions & 29 deletions packages/ckb-sdk-rpc/src/paramsFormatter.ts
Original file line number Diff line number Diff line change
@@ -1,41 +1,43 @@
/* eslint-disable camelcase */
const formatter = {
toScript: ({ codeHash: code_hash, hashType: hash_type, ...rest }: CKBComponents.Script): CKB_RPC.Script => ({
code_hash,
hash_type,
...rest,
}),
toScript: (script: CKBComponents.Script): CKB_RPC.Script => {
const { codeHash: code_hash, hashType: hash_type, ...rest } = script
return {
code_hash,
hash_type,
...rest,
}
},
toHash: (hash: string): CKB_RPC.Hash256 => (hash.startsWith('0x') ? hash : `0x${hash}`),
toCellOutPoint: (cellOutPoint: CKBComponents.CellOutPoint | null): CKB_RPC.CellOutPoint | null => {
if (!cellOutPoint) return cellOutPoint
const { txHash: tx_hash, ...rest } = cellOutPoint
toOutPoint: (outPoint: CKBComponents.OutPoint | null): CKB_RPC.OutPoint | null => {
if (!outPoint) return outPoint
const { txHash: tx_hash, ...rest } = outPoint
return {
tx_hash,
...rest,
}
},
toOutPoint: ({ cell = null, blockHash: block_hash = null, ...rest }: CKBComponents.OutPoint): CKB_RPC.OutPoint => ({
cell: cell ? formatter.toCellOutPoint(cell) : cell,
block_hash,
...rest,
}),
toNumber: (number: CKBComponents.BlockNumber): CKB_RPC.BlockNumber => number.toString(),
toInput: ({ previousOutput, ...rest }: CKBComponents.CellInput): CKB_RPC.CellInput => ({
previous_output: previousOutput ? formatter.toCellOutPoint(previousOutput) : previousOutput,
...rest,
}),
toOutput: ({ lock, type, ...rest }: CKBComponents.CellOutput): CKB_RPC.CellOutput => ({
lock: formatter.toScript(lock),
type: type ? formatter.toScript(type) : null,
...rest,
}),
toRawTransaction: ({
version,
deps,
inputs,
outputs,
...rest
}: CKBComponents.RawTransaction): CKB_RPC.RawTransaction => {
toInput: (input: CKBComponents.CellInput): CKB_RPC.CellInput => {
if (!input) return input
const { previousOutput, ...rest } = input
return {
previous_output: formatter.toOutPoint(previousOutput),
...rest,
}
},
toOutput: (output: CKBComponents.CellOutput): CKB_RPC.CellOutput => {
if (!output) return output
const { lock, type = null, ...rest } = output
return {
lock: formatter.toScript(lock),
type: type ? formatter.toScript(type) : type,
...rest,
}
},
toRawTransaction: (transaction: CKBComponents.RawTransaction): CKB_RPC.RawTransaction => {
if (!transaction) return transaction
const { version, deps, inputs, outputs, ...rest } = transaction
const formattedInputs = inputs.map(input => formatter.toInput(input))
const formattedOutputs = outputs.map(output => formatter.toOutput(output))
const formattedDeps = deps.map(dep => formatter.toOutPoint(dep))
Expand Down
Loading

0 comments on commit 38ba007

Please sign in to comment.