Skip to content

Commit

Permalink
feat(type): rename is_dep_group to dep_type
Browse files Browse the repository at this point in the history
BREAKING CHANGE: rename is_dep_group to dep_type
  • Loading branch information
Keith-CY committed Aug 24, 2019
1 parent ce48faf commit 06c324a
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 28 deletions.
2 changes: 1 addition & 1 deletion packages/ckb-sdk-core/examples/sendTransaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ const bootstrap = async () => {
version: '0',
cellDeps: [{
outPoint: secp256k1Dep.outPoint,
isDepGroup: true,
depType: "depGroup",
}, ],
headerDeps: [],
inputs,
Expand Down
28 changes: 19 additions & 9 deletions packages/ckb-sdk-rpc/__tests__/formatters/params.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,28 @@
"target": null
}
],
"toDepType": [
{
"source": "code",
"target": "code"
},
{
"source": "depGroup",
"target": "dep_group"
}
],
"toCellDep": [
{
"source": null,
"target": null
},
{
"source": {
"isDepGroup": false
"depType": "depGroup"
},
"target": {
"out_point": null,
"is_dep_group": false
"dep_type": "dep_group"
}
},
{
Expand All @@ -50,17 +60,17 @@
},
"target": {
"out_point": null,
"is_dep_group": false
"dep_type": "code"
}
},
{
"source": {
"outPoint": null,
"isDepGroup": false
"depType": "depGroup"
},
"target": {
"out_point": null,
"is_dep_group": false
"dep_type": "dep_group"
}
},
{
Expand All @@ -69,14 +79,14 @@
"txHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"index": "4294967295"
},
"isDepGroup": true
"depType": "code"
},
"target": {
"out_point": {
"tx_hash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"index": "4294967295"
},
"is_dep_group": true
"dep_type": "code"
}
}
],
Expand Down Expand Up @@ -194,7 +204,7 @@
"txHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"index": "4294967295"
},
"isDepGroup": false
"depType": "code"
}
],
"headerDeps": [],
Expand Down Expand Up @@ -233,7 +243,7 @@
"tx_hash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"index": "4294967295"
},
"is_dep_group": false
"dep_type": "code"
}
],
"header_deps": [],
Expand Down
28 changes: 17 additions & 11 deletions packages/ckb-sdk-rpc/__tests__/formatters/result.json
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,11 @@
},
{
"source": {
"is_dep_group": false
"dep_type": "dep_group"
},
"target": {
"outPoint": null,
"isDepGroup": false
"depType": "depGroup"
}
},
{
Expand All @@ -142,17 +142,17 @@
},
"target": {
"outPoint": null,
"isDepGroup": false
"depType": "code"
}
},
{
"source": {
"out_point": null,
"is_dep_group": false
"dep_type": "code"
},
"target": {
"outPoint": null,
"isDepGroup": false
"depType": "code"
}
},
{
Expand All @@ -161,14 +161,14 @@
"tx_hash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"index": "4294967295"
},
"is_dep_group": true
"dep_type": "code"
},
"target": {
"outPoint": {
"txHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"index": "4294967295"
},
"isDepGroup": true
"depType": "code"
}
}
],
Expand Down Expand Up @@ -638,6 +638,16 @@
}
}
],
"toDepType": [
{
"source": "dep_group",
"target": "depGroup"
},
{
"source": "code",
"target": "code"
}
],
"toCell": [
{
"source": null,
Expand All @@ -646,7 +656,6 @@
{
"source": {
"capacity": "5000000000000",

"lock": {
"args": [],
"code_hash": "0x0000000000000000000000000000000000000000000000000000000000000001",
Expand All @@ -660,7 +669,6 @@
},
"target": {
"capacity": "5000000000000",

"lock": {
"args": [],
"codeHash": "0x0000000000000000000000000000000000000000000000000000000000000001",
Expand All @@ -683,7 +691,6 @@
"source": {
"cell": {
"capacity": "5000000000000",

"lock": {
"args": [],
"code_hash": "0x0000000000000000000000000000000000000000000000000000000000000001",
Expand All @@ -696,7 +703,6 @@
"target": {
"cell": {
"capacity": "5000000000000",

"lock": {
"args": [],
"codeHash": "0x0000000000000000000000000000000000000000000000000000000000000001",
Expand Down
10 changes: 8 additions & 2 deletions packages/ckb-sdk-rpc/src/paramsFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,18 @@ const formatter = {
...rest,
}
},
toDepType: (type: CKBComponents.DepType) => {
if (type === 'depGroup') {
return 'dep_group'
}
return type
},
toCellDep: (cellDep: CKBComponents.CellDep): CKB_RPC.CellDep => {
if (!cellDep) return cellDep
const { outPoint = null, isDepGroup: is_dep_group = false, ...rest } = cellDep
const { outPoint = null, depType = 'code', ...rest } = cellDep
return {
out_point: formatter.toOutPoint(outPoint),
is_dep_group,
dep_type: formatter.toDepType(depType),
...rest,
}
},
Expand Down
11 changes: 9 additions & 2 deletions packages/ckb-sdk-rpc/src/resultFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,19 @@ const formatter = {
...rest,
}
},
toDepType: (type: CKB_RPC.DepType) => {
if (type === 'dep_group') {
return 'depGroup'
}
return type
},

toCellDep: (cellDep: CKB_RPC.CellDep): CKBComponents.CellDep => {
if (!cellDep) return cellDep
const { out_point: outPoint = null, is_dep_group: isDepGroup = false, ...rest } = cellDep
const { out_point: outPoint = null, dep_type = 'code', ...rest } = cellDep
return {
outPoint: formatter.toOutPoint(outPoint),
isDepGroup,
depType: formatter.toDepType(dep_type),
...rest,
}
},
Expand Down
4 changes: 3 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 @@ -28,6 +28,8 @@ declare module CKB_RPC {
Type = 'Type',
}

export type DepType = 'code' | 'dep_group'

export interface Script {
args: Bytes[]
code_hash: Hash256
Expand All @@ -54,7 +56,7 @@ declare module CKB_RPC {

export interface CellDep {
out_point: OutPoint | null
is_dep_group: boolean
dep_type: DepType
}

export interface CellIncludingOutPoint {
Expand Down
6 changes: 4 additions & 2 deletions packages/ckb-types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ declare namespace CKBComponents {
Type = 'Type',
}

export type DepType = 'code' | 'depGroup'

/**
* @typedef Bytes, keep consistent with CKB
* @description Bytes will be serialized to string
Expand Down Expand Up @@ -102,11 +104,11 @@ declare namespace CKBComponents {
/**
* @typeof CellDep, cell dependencies in a transaction
* @property outPoint, the out point of the cell dependency
* @property isDepGroup, indicate if the data of the cell containing a group of dependencies
* @property depType, indicate if the data of the cell containing a group of dependencies
*/
export interface CellDep {
outPoint: OutPoint | null
isDepGroup: boolean
depType: DepType
}

export interface Witness {
Expand Down

0 comments on commit 06c324a

Please sign in to comment.