Skip to content

Commit

Permalink
feat(rpc): add one new rpc and remove two rpc
Browse files Browse the repository at this point in the history
1. remove trace related rpc
2. add dry run transaction rpc
  • Loading branch information
Keith-CY committed May 10, 2019
1 parent bab75d1 commit 21c4ac4
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 106 deletions.
25 changes: 5 additions & 20 deletions packages/ckb-sdk-rpc/__tests__/ckb-rpc.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,18 +93,6 @@ describe('ckb-rpc success', () => {
const cells = await rpc.getCellsByLockHash(lockHash, '0', '100')
expect(Array.isArray(cells)).toBeTruthy()
})

it.skip('trace a transaction', async () => {
const traceHash = await rpc.traceTransaction({
version: 0,
deps: [],
inputs: [],
outputs: [],
})
expect(typeof traceHash).toBe('string')
const traces = await rpc.getTransactionTrace(traceHash)
expect(Array.isArray(traces)).toBeTruthy()
})
})

describe('send transaction', () => {
Expand Down Expand Up @@ -135,17 +123,14 @@ describe('send transaction', () => {
codeHash: '0x0000000000000000000000000000000000000000000000000000000000000001',
},
type: null,
capacity: '100000000000',
capacity: '1',
data: '0x',
},
],
witnesses: [],
}
try {
await rpc.sendTransaction(tx)
} catch (err) {
expect(err.toString()).toBe('Error: {"code":-3,"message":"InvalidTx(OutputsSumOverflow)"}')
}
const hash = rpc.sendTransaction(tx)
expect(hash).toBeTruthy()
})
})

Expand All @@ -164,8 +149,8 @@ describe('ckb-rpc settings and helpers', () => {
expect(rpc.node).toEqual(node)
})

it('has 18 default rpc', () => {
expect(rpc.methods.length).toBe(18)
it('has 17 default rpc', () => {
expect(rpc.methods.length).toBe(17)
})

it(`set debug level to ${DebugLevel.Off}`, async () => {
Expand Down
54 changes: 0 additions & 54 deletions packages/ckb-sdk-rpc/__tests__/formatters/fixtures.json
Original file line number Diff line number Diff line change
Expand Up @@ -677,60 +677,6 @@
"witnessesRoot": "0x0000000000000000000000000000000000000000000000000000000000000000"
}
}],
"toTrace": [{
"source": [{
"action": "AddPending",
"info": "unknown tx, insert to pending queue",
"time": 1555507787683
},
{
"action": "Proposed",
"info": "ProposalShortId(0xa093b2e820f3f2202a68) proposed",
"time": 1555507857772
},
{
"action": "Staged",
"info": "tx staged",
"time": 1555507857782
},
{
"action": "Committed",
"info": "tx committed",
"time": 1555507913089
},
{
"action": "Committed",
"info": "tx committed",
"time": 1555508028264
}
],
"target": [{
"action": "AddPending",
"info": "unknown tx, insert to pending queue",
"time": 1555507787683
},
{
"action": "Proposed",
"info": "ProposalShortId(0xa093b2e820f3f2202a68) proposed",
"time": 1555507857772
},
{
"action": "Staged",
"info": "tx staged",
"time": 1555507857782
},
{
"action": "Committed",
"info": "tx committed",
"time": 1555507913089
},
{
"action": "Committed",
"info": "tx committed",
"time": 1555508028264
}
]
}],
"toTransactionWithStatus": [{
"source": {
"transaction": {
Expand Down
9 changes: 0 additions & 9 deletions packages/ckb-sdk-rpc/__tests__/formatters/result.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ describe('result formatter', () => {
})
})

it.skip('toTrace', () => {})

it('toBlockchainInfo', () => {
result.toBlockchainInfo.forEach(fixture => {
const formatted = resultFmt.toBlockchainInfo(fixture.source)
Expand Down Expand Up @@ -123,13 +121,6 @@ describe('result formatter', () => {
})
})

it('toTrace', () => {
result.toTrace.forEach(fixture => {
const formatted = resultFmt.toTrace(fixture.source)
expect(formatted).toEqual(fixture.target)
})
})

it('toHeader', () => {
result.toHeader.forEach(fixture => {
const formatted = resultFmt.toHeader(fixture.source)
Expand Down
30 changes: 8 additions & 22 deletions packages/ckb-sdk-rpc/src/defaultRPC.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,18 +85,6 @@ const defaultRPC: CKBComponents.Method[] = [
paramsFormatters: [],
resultFormatters: resultFmts.toPeersState,
},
{
name: 'traceTransaction',
method: 'trace_transaction',
paramsFormatters: [paramsFmts.toRawTransaction],
resultFormatters: resultFmts.toHash,
},
{
name: 'getTransactionTrace',
method: 'get_transaction_trace',
paramsFormatters: [paramsFmts.toHash],
resultFormatters: resultFmts.toTrace,
},
{
name: 'getCurrentEpoch',
method: 'get_current_epoch',
Expand All @@ -109,6 +97,12 @@ const defaultRPC: CKBComponents.Method[] = [
paramsFormatters: [paramsFmts.toNumber],
resultFormatters: resultFmts.toEpoch,
},
{
name: 'dryRunTransaction',
method: 'dry_run_transaction',
paramsFormatters: [paramsFmts.toRawTransaction],
resultFormatters: resultFmts.toHash,
},
]

export class DefaultRPC {
Expand Down Expand Up @@ -151,19 +145,11 @@ export class DefaultRPC {

public getPeersState!: () => Promise<CKBComponents.PeersState>

public traceTransaction!: (transaction: {
version: CKBComponents.Version
deps: CKBComponents.OutPoint[]
inputs: CKBComponents.CellInput[]
outputs: CKBComponents.CellOutput[]
witnesses: CKBComponents.Witness[]
}) => Promise<CKBComponents.Hash>

public getTransactionTrace!: (transactionHash: CKBComponents.Hash) => Promise<CKBComponents.TransactionTrace>

public getCurrentEpoch!: () => Promise<CKBComponents.Epoch>

public getEpochByNumber!: (epoch: string) => Promise<CKBComponents.Epoch>

public dryRunTransaction!: (tx: CKBComponents.RawTransaction) => Promise<CKBComponents.Hash>
}

export default DefaultRPC
1 change: 0 additions & 1 deletion packages/ckb-sdk-rpc/src/resultFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ const formatter = {
transactions: transactions.map(formatter.toTransaction),
...rest,
}),
toTrace: (trace: CKBComponents.TransactionTrace) => trace,
toBlockchainInfo: ({
is_initial_block_download: isInitialBlockDownload,
median_time: medianTime,
Expand Down

0 comments on commit 21c4ac4

Please sign in to comment.