Skip to content

Commit 18f66ba

Browse files
Seulgi Kimsgkim126
authored andcommitted
Replace chain_getTransactionResult with chain_containTransaction
1 parent f43c4c2 commit 18f66ba

File tree

16 files changed

+205
-34
lines changed

16 files changed

+205
-34
lines changed

rpc/src/v1/impls/chain.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ where
9797
Ok(self.client.transaction(&id).map(From::from))
9898
}
9999

100-
fn get_transaction_result(&self, transaction_hash: H256) -> Result<Option<bool>> {
101-
Ok(Some(self.client.error_hint(&transaction_hash).is_none()))
100+
fn contain_transaction(&self, transaction_hash: H256) -> Result<bool> {
101+
Ok(self.client.transaction_block(&transaction_hash.into()).is_some())
102102
}
103103

104104
fn get_transaction_by_tracker(&self, tracker: H256) -> Result<Option<Transaction>> {

rpc/src/v1/traits/chain.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ build_rpc_trait! {
3636
# [rpc(name = "chain_getTransaction")]
3737
fn get_transaction(&self, H256) -> Result<Option<Transaction>>;
3838

39-
/// Gets transaction result with given transaction hash.
40-
# [rpc(name = "chain_getTransactionResult")]
41-
fn get_transaction_result(&self, H256) -> Result<Option<bool>>;
39+
/// Query whether the chain has the transaction with given transaction hash.
40+
# [rpc(name = "chain_containTransaction")]
41+
fn contain_transaction(&self, H256) -> Result<bool>;
4242

4343
/// Gets transaction with given transaction tracker.
4444
# [rpc(name = "chain_getTransactionByTracker")]

spec/JSON-RPC.md

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ When `Transaction` is included in any response, there will be an additional fiel
287287
* [chain_getBlockTransactionCountByHash](#chain_getblocktransactioncountbyhash)
288288
* [chain_sendSignedTransaction](#chain_sendsignedtransaction)
289289
* [chain_getTransaction](#chain_gettransaction)
290-
* [chain_getTransactionResult](#chain_gettransactionresult)
290+
* [chain_containTransaction](#chain_containtransaction)
291291
* [chain_getTransactionByTracker](#chain_gettransactionbytracker)
292292
* [chain_getTransactionResultsByTracker](#chain_getTransactionResultsByTracker)
293293
* [chain_getAssetSchemeByTracker](#chain_getassetschemebytracker)
@@ -752,32 +752,30 @@ Errors: `Invalid Params`
752752

753753
[Back to **List of methods**](#list-of-methods)
754754

755-
## chain_getTransactionResult
756-
Gets a transaction result with the given hash.
755+
## chain_containTransaction
756+
Returns true if the transaction with the given hass is in the chain.
757757

758758
### Params
759759
1. transaction hash - `H256`
760760

761761
### Returns
762-
`null` | `boolean`
762+
`boolean`
763763

764764
Errors: `Invalid Params`
765765

766766
### Request Example
767767
```
768768
curl \
769769
-H 'Content-Type: application/json' \
770-
-d '{"jsonrpc": "2.0", "method": "chain_getTransactionResult", "params": ["0xad708d48755ac36685280a45ec213941e21c41644c781bf2f487fd6c7e4b2ebb"], "id": null}' \
770+
-d '{"jsonrpc": "2.0", "method": "chain_containTransaction", "params": ["0xad708d48755ac36685280a45ec213941e21c41644c781bf2f487fd6c7e4b2ebb"], "id": null}' \
771771
localhost:8080
772772
```
773773

774774
### Response Example
775775
```
776776
{
777777
"jsonrpc":"2.0",
778-
"result":[
779-
true
780-
],
778+
"result": true,
781779
"id":null
782780
}
783781
```

test/src/e2e.long/orders.test.ts

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ describe("orders", function() {
6969
await node.signTransactionInput(splitTx, 0);
7070

7171
const splitHash = await node.sendAssetTransaction(splitTx);
72+
expect(await node.sdk.rpc.chain.containTransaction(splitHash))
73+
.be.true;
7274
expect(await node.sdk.rpc.chain.getTransaction(splitHash)).not
7375
.null;
7476

@@ -207,6 +209,8 @@ describe("orders", function() {
207209
await node.signTransactionInput(transferTx, 1);
208210

209211
const hash = await node.sendAssetTransaction(transferTx);
212+
expect(await node.sdk.rpc.chain.containTransaction(hash)).be
213+
.true;
210214
expect(await node.sdk.rpc.chain.getTransaction(hash)).not.null;
211215
});
212216

@@ -226,6 +230,8 @@ describe("orders", function() {
226230
await node.signTransactionInput(splitTx, 0);
227231

228232
const splitHash = await node.sendAssetTransaction(splitTx);
233+
expect(await node.sdk.rpc.chain.containTransaction(splitHash))
234+
.be.true;
229235
expect(await node.sdk.rpc.chain.getTransaction(splitHash)).not
230236
.null;
231237

@@ -291,6 +297,8 @@ describe("orders", function() {
291297
);
292298

293299
const hash = await node.sendAssetTransaction(transferTx);
300+
expect(await node.sdk.rpc.chain.containTransaction(hash)).be
301+
.true;
294302
expect(await node.sdk.rpc.chain.getTransaction(hash)).not.null;
295303
}).timeout(10_000);
296304

@@ -343,6 +351,8 @@ describe("orders", function() {
343351
await node.signTransactionInput(transferTx, 1);
344352

345353
const hash = await node.sendAssetTransaction(transferTx);
354+
expect(await node.sdk.rpc.chain.containTransaction(hash)).be
355+
.true;
346356
expect(await node.sdk.rpc.chain.getTransaction(hash)).not.null;
347357
});
348358

@@ -407,6 +417,8 @@ describe("orders", function() {
407417
await node.signTransactionInput(transferTx, 1);
408418

409419
const hash = await node.sendAssetTransaction(transferTx);
420+
expect(await node.sdk.rpc.chain.containTransaction(hash)).be
421+
.true;
410422
expect(await node.sdk.rpc.chain.getTransaction(hash)).not.null;
411423
});
412424

@@ -484,6 +496,8 @@ describe("orders", function() {
484496
await node.signTransactionInput(transferTx, 1);
485497

486498
const hash = await node.sendAssetTransaction(transferTx);
499+
expect(await node.sdk.rpc.chain.containTransaction(hash)).be
500+
.true;
487501
expect(await node.sdk.rpc.chain.getTransaction(hash)).not.null;
488502
});
489503

@@ -563,6 +577,8 @@ describe("orders", function() {
563577
await node.signTransactionInput(transferTx, 1);
564578

565579
const hash = await node.sendAssetTransaction(transferTx);
580+
expect(await node.sdk.rpc.chain.containTransaction(hash)).be
581+
.true;
566582
expect(await node.sdk.rpc.chain.getTransaction(hash)).not.null;
567583
});
568584

@@ -583,6 +599,8 @@ describe("orders", function() {
583599
await node.signTransactionInput(splitTx, 0);
584600

585601
const splitHash = await node.sendAssetTransaction(splitTx);
602+
expect(await node.sdk.rpc.chain.containTransaction(splitHash))
603+
.be.true;
586604
expect(await node.sdk.rpc.chain.getTransaction(splitHash)).not
587605
.null;
588606

@@ -646,6 +664,8 @@ describe("orders", function() {
646664
await node.signTransactionInput(transferTx, 3);
647665

648666
const hash = await node.sendAssetTransaction(transferTx);
667+
expect(await node.sdk.rpc.chain.containTransaction(hash)).be
668+
.true;
649669
expect(await node.sdk.rpc.chain.getTransaction(hash)).not.null;
650670
});
651671

@@ -1382,6 +1402,8 @@ describe("orders", function() {
13821402
await node.signTransactionInput(splitTx, 0);
13831403

13841404
const splitHash = await node.sendAssetTransaction(splitTx);
1405+
expect(await node.sdk.rpc.chain.containTransaction(splitHash))
1406+
.be.true;
13851407
expect(await node.sdk.rpc.chain.getTransaction(splitHash)).not
13861408
.null;
13871409

@@ -1448,6 +1470,10 @@ describe("orders", function() {
14481470
});
14491471
await node.sdk.rpc.devel.startSealing();
14501472
await node.waitBlockNumber(blockNumber + 1);
1473+
expect(await node.sdk.rpc.chain.containTransaction(hash)).be
1474+
.false;
1475+
expect(await node.sdk.rpc.chain.containTransaction(pay.hash()))
1476+
.be.true;
14511477
expect(await node.sdk.rpc.chain.getTransaction(pay.hash())).not
14521478
.null;
14531479
expect(await node.sdk.rpc.chain.getErrorHint(hash)).not.null;
@@ -1469,6 +1495,8 @@ describe("orders", function() {
14691495
await node.signTransactionInput(splitTx, 0);
14701496

14711497
const splitHash = await node.sendAssetTransaction(splitTx);
1498+
expect(await node.sdk.rpc.chain.containTransaction(splitHash))
1499+
.be.true;
14721500
expect(await node.sdk.rpc.chain.getTransaction(splitHash)).not
14731501
.null;
14741502

@@ -1548,6 +1576,10 @@ describe("orders", function() {
15481576
});
15491577
await node.sdk.rpc.devel.startSealing();
15501578
await node.waitBlockNumber(blockNumber + 1);
1579+
expect(await node.sdk.rpc.chain.containTransaction(pay.hash()))
1580+
.be.true;
1581+
expect(await node.sdk.rpc.chain.containTransaction(hash)).be
1582+
.false;
15511583
expect(await node.sdk.rpc.chain.getTransaction(pay.hash())).not
15521584
.null;
15531585
expect(await node.sdk.rpc.chain.getErrorHint(hash)).not.null;
@@ -1569,6 +1601,8 @@ describe("orders", function() {
15691601
await node.signTransactionInput(splitTx, 0);
15701602

15711603
const splitHash = await node.sendAssetTransaction(splitTx);
1604+
expect(await node.sdk.rpc.chain.containTransaction(splitHash))
1605+
.be.true;
15721606
expect(await node.sdk.rpc.chain.getTransaction(splitHash)).not
15731607
.null;
15741608

@@ -1646,6 +1680,8 @@ describe("orders", function() {
16461680
});
16471681
await node.sdk.rpc.devel.startSealing();
16481682
await node.waitBlockNumber(blockNumber + 1);
1683+
expect(await node.sdk.rpc.chain.containTransaction(pay.hash()))
1684+
.be.true;
16491685
expect(await node.sdk.rpc.chain.getTransaction(pay.hash())).not
16501686
.null;
16511687
expect(await node.sdk.rpc.chain.getErrorHint(hash)).not.null;
@@ -1919,6 +1955,8 @@ describe("orders", function() {
19191955
await node.signTransactionInput(transferTx1, 1);
19201956

19211957
const hash1 = await node.sendAssetTransaction(transferTx1);
1958+
expect(await node.sdk.rpc.chain.containTransaction(hash1)).be
1959+
.true;
19221960
expect(await node.sdk.rpc.chain.getTransaction(hash1)).not.null;
19231961

19241962
const orderConsumed = order.consume(50);
@@ -1964,6 +2002,8 @@ describe("orders", function() {
19642002
await node.signTransactionInput(transferTx2, 1);
19652003

19662004
const hash2 = await node.sendAssetTransaction(transferTx2);
2005+
expect(await node.sdk.rpc.chain.containTransaction(hash2)).be
2006+
.true;
19672007
expect(await node.sdk.rpc.chain.getTransaction(hash2)).not.null;
19682008
}).timeout(10_000);
19692009

@@ -2040,6 +2080,8 @@ describe("orders", function() {
20402080
await node.signTransactionInput(transferTx1, 1);
20412081

20422082
const hash1 = await node.sendAssetTransaction(transferTx1);
2083+
expect(await node.sdk.rpc.chain.containTransaction(hash1)).be
2084+
.true;
20432085
expect(await node.sdk.rpc.chain.getTransaction(hash1)).not.null;
20442086

20452087
const aliceOrderConsumed = aliceOrder.consume(10);
@@ -2091,6 +2133,8 @@ describe("orders", function() {
20912133
// Sign on both inputs 0, 1 are not needed
20922134

20932135
const hash2 = await node.sendAssetTransaction(transferTx2);
2136+
expect(await node.sdk.rpc.chain.containTransaction(hash2)).be
2137+
.true;
20942138
expect(await node.sdk.rpc.chain.getTransaction(hash2)).not.null;
20952139
}).timeout(10_000);
20962140

@@ -2149,6 +2193,8 @@ describe("orders", function() {
21492193
await node.signTransactionInput(transferTx1, 1);
21502194

21512195
const hash1 = await node.sendAssetTransaction(transferTx1);
2196+
expect(await node.sdk.rpc.chain.containTransaction(hash1)).be
2197+
.true;
21522198
expect(await node.sdk.rpc.chain.getTransaction(hash1)).not.null;
21532199

21542200
const transferTx2 = node.sdk.core
@@ -2175,6 +2221,8 @@ describe("orders", function() {
21752221
await node.signTransactionInput(transferTx2, 1);
21762222

21772223
const hash2 = await node.sendAssetTransaction(transferTx2);
2224+
expect(await node.sdk.rpc.chain.containTransaction(hash2)).be
2225+
.true;
21782226
expect(await node.sdk.rpc.chain.getTransaction(hash2)).not.null;
21792227
});
21802228
}).timeout(10_000);
@@ -2242,6 +2290,8 @@ describe("orders", function() {
22422290
await node.signTransactionInput(splitTx, 0);
22432291

22442292
const splitHash = await node.sendAssetTransaction(splitTx);
2293+
expect(await node.sdk.rpc.chain.containTransaction(splitHash))
2294+
.be.true;
22452295
expect(await node.sdk.rpc.chain.getTransaction(splitHash)).not
22462296
.null;
22472297

@@ -2321,6 +2371,8 @@ describe("orders", function() {
23212371
await node.signTransactionInput(transferTx, 2);
23222372

23232373
const hash = await node.sendAssetTransaction(transferTx);
2374+
expect(await node.sdk.rpc.chain.containTransaction(hash)).be
2375+
.true;
23242376
expect(await node.sdk.rpc.chain.getTransaction(hash)).not.null;
23252377
});
23262378

@@ -2397,6 +2449,8 @@ describe("orders", function() {
23972449
await node.signTransactionInput(transferTx, 2);
23982450

23992451
const hash = await node.sendAssetTransaction(transferTx);
2452+
expect(await node.sdk.rpc.chain.containTransaction(hash)).be
2453+
.true;
24002454
expect(await node.sdk.rpc.chain.getTransaction(hash)).not.null;
24012455
});
24022456

@@ -2425,6 +2479,8 @@ describe("orders", function() {
24252479
await node.signTransactionInput(splitTx, 0);
24262480

24272481
const splitHash = await node.sendAssetTransaction(splitTx);
2482+
expect(await node.sdk.rpc.chain.containTransaction(splitHash))
2483+
.be.true;
24282484
expect(await node.sdk.rpc.chain.getTransaction(splitHash)).not
24292485
.null;
24302486

@@ -2540,6 +2596,8 @@ describe("orders", function() {
25402596
await node.signTransactionInput(transferTx, 3);
25412597

25422598
const hash = await node.sendAssetTransaction(transferTx);
2599+
expect(await node.sdk.rpc.chain.containTransaction(hash)).be
2600+
.true;
25432601
expect(await node.sdk.rpc.chain.getTransaction(hash)).not.null;
25442602
});
25452603

@@ -2568,6 +2626,8 @@ describe("orders", function() {
25682626
await node.signTransactionInput(splitTx, 0);
25692627

25702628
const splitHash = await node.sendAssetTransaction(splitTx);
2629+
expect(await node.sdk.rpc.chain.containTransaction(splitHash))
2630+
.be.true;
25712631
expect(await node.sdk.rpc.chain.getTransaction(splitHash)).not
25722632
.null;
25732633

@@ -2689,6 +2749,8 @@ describe("orders", function() {
26892749
await node.signTransactionInput(transferTx, 3);
26902750

26912751
const hash = await node.sendAssetTransaction(transferTx);
2752+
expect(await node.sdk.rpc.chain.containTransaction(hash)).be
2753+
.true;
26922754
expect(await node.sdk.rpc.chain.getTransaction(hash)).not.null;
26932755
});
26942756

@@ -2777,6 +2839,10 @@ describe("orders", function() {
27772839
});
27782840
await node.sdk.rpc.devel.startSealing();
27792841
await node.waitBlockNumber(blockNumber + 1);
2842+
expect(await node.sdk.rpc.chain.containTransaction(pay.hash()))
2843+
.be.true;
2844+
expect(await node.sdk.rpc.chain.containTransaction(hash)).be
2845+
.false;
27802846
expect(await node.sdk.rpc.chain.getTransaction(pay.hash())).not
27812847
.null;
27822848
expect(await node.sdk.rpc.chain.getErrorHint(hash)).not.null;
@@ -2849,6 +2915,8 @@ describe("orders", function() {
28492915
);
28502916

28512917
const hash = await node.sendAssetTransaction(transferTx);
2918+
expect(await node.sdk.rpc.chain.containTransaction(hash)).be
2919+
.true;
28522920
expect(await node.sdk.rpc.chain.getTransaction(hash)).not.null;
28532921
}).timeout(10_000);
28542922
});

0 commit comments

Comments
 (0)