Skip to content

Commit

Permalink
feat(type): Transaction structure changes
Browse files Browse the repository at this point in the history
A new field named header_deps is added into the transaction structure

BREAKING CHANGE: Transaction structure chagnes
  • Loading branch information
Keith-CY committed Aug 19, 2019
1 parent 71625fa commit 30c84bb
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ After that you can use the `core` object to generate addresses, send requests, e

# RPC

Please see [Default RPC](https://github.com/nervosnetwork/ckb-sdk-js/blob/develop/packages/ckb-sdk-rpc/src/defaultRPC.ts#L136)
Please see [Default RPC](https://github.com/nervosnetwork/ckb-sdk-js/blob/develop/packages/ckb-sdk-rpc/src/defaultRPC.ts#L165)

# Errors

Expand Down
2 changes: 2 additions & 0 deletions packages/ckb-sdk-rpc/__tests__/formatters/params.json
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@
"isDepGroup": false
}
],
"headerDeps": [],
"inputs": [
{
"previousOutput": null,
Expand Down Expand Up @@ -222,6 +223,7 @@
"is_dep_group": false
}
],
"header_deps": [],
"inputs": [
{
"previous_output": null,
Expand Down
7 changes: 7 additions & 0 deletions packages/ckb-sdk-rpc/__tests__/formatters/result.json
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@
{
"source": {
"cell_deps": [],
"header_deps": [],
"hash": "0x8027376875e45318ed469bed6314408e8f1986de246cbd03a786b69073c948b8",
"inputs": [
{
Expand Down Expand Up @@ -212,6 +213,7 @@
},
"target": {
"cellDeps": [],
"headerDeps": [],
"hash": "0x8027376875e45318ed469bed6314408e8f1986de246cbd03a786b69073c948b8",
"inputs": [
{
Expand Down Expand Up @@ -247,6 +249,7 @@
},
"target": {
"cellDeps": [],
"headerDeps": [],
"hash": "0x8027376875e45318ed469bed6314408e8f1986de246cbd03a786b69073c948b8",
"inputs": [],
"outputs": [],
Expand Down Expand Up @@ -338,6 +341,7 @@
"transactions": [
{
"cell_deps": [],
"header_deps": [],
"hash": "0x8027376875e45318ed469bed6314408e8f1986de246cbd03a786b69073c948b8",
"inputs": [
{
Expand Down Expand Up @@ -391,6 +395,7 @@
"transactions": [
{
"cellDeps": [],
"headerDeps": [],
"hash": "0x8027376875e45318ed469bed6314408e8f1986de246cbd03a786b69073c948b8",
"inputs": [
{
Expand Down Expand Up @@ -881,6 +886,7 @@
"source": {
"transaction": {
"cell_deps": [],
"header_deps": [],
"hash": "0x8027376875e45318ed469bed6314408e8f1986de246cbd03a786b69073c948b8",
"inputs": [
{
Expand Down Expand Up @@ -915,6 +921,7 @@
"target": {
"transaction": {
"cellDeps": [],
"headerDeps": [],
"hash": "0x8027376875e45318ed469bed6314408e8f1986de246cbd03a786b69073c948b8",
"inputs": [
{
Expand Down
11 changes: 10 additions & 1 deletion packages/ckb-sdk-rpc/src/paramsFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,15 @@ const formatter = {
},
toRawTransaction: (transaction: CKBComponents.RawTransaction): CKB_RPC.RawTransaction => {
if (!transaction) return transaction
const { version, cellDeps = [], inputs = [], outputs = [], outputsData: outputs_data = [], ...rest } = transaction
const {
version,
cellDeps = [],
inputs = [],
outputs = [],
outputsData: outputs_data = [],
headerDeps: header_deps = [],
...rest
} = transaction
const formattedInputs = inputs.map(input => formatter.toInput(input))
const formattedOutputs = outputs.map(output => formatter.toOutput(output))
const formattedCellDeps = cellDeps.map(cellDep => formatter.toCellDep(cellDep))
Expand All @@ -56,6 +64,7 @@ const formatter = {
inputs: formattedInputs,
outputs: formattedOutputs,
outputs_data,
header_deps,
...rest,
}
return tx
Expand Down
10 changes: 9 additions & 1 deletion packages/ckb-sdk-rpc/src/resultFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,20 @@ const formatter = {
},
toTransaction: (tx: CKB_RPC.Transaction): CKBComponents.Transaction => {
if (!tx) return tx
const { cell_deps: cellDeps = [], inputs = [], outputs = [], outputs_data: outputsData = [], ...rest } = tx
const {
cell_deps: cellDeps = [],
inputs = [],
outputs = [],
outputs_data: outputsData = [],
header_deps: headerDeps = [],
...rest
} = tx
return {
cellDeps: cellDeps.map(formatter.toCellDep),
inputs: inputs.map(formatter.toInput),
outputs: outputs.map(formatter.toOutput),
outputsData,
headerDeps,
...rest,
}
},
Expand Down
1 change: 1 addition & 0 deletions packages/ckb-sdk-rpc/types/CKB_RPC/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ declare module CKB_RPC {
export interface RawTransaction {
version: Version
cell_deps: CellDep[]
header_deps: Hash256[]
inputs: CellInput[]
outputs: CellOutput[]
witnesses: Witness[]
Expand Down
2 changes: 2 additions & 0 deletions packages/ckb-types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ declare namespace CKBComponents {
* @typedef RawTransaction, raw transaction object
* @property version, transaction version
* @property cellDeps, cell deps used in the transaction
* @property headerDeps, header deps referenced to a specific block used in the transaction
* @property inputs, cell inputs in the transaction
* @property outputs, cell outputs in the transaction
* @property witnesses, segrated witnesses
Expand All @@ -127,6 +128,7 @@ declare namespace CKBComponents {
export interface RawTransaction {
version: Version
cellDeps: CellDep[]
headerDeps: Hash256[]
inputs: CellInput[]
outputs: CellOutput[]
witnesses: Witness[]
Expand Down

0 comments on commit 30c84bb

Please sign in to comment.