Skip to content

Commit 86edd22

Browse files
Juhyung Parkmergify[bot]
authored andcommitted
Make get_transactions_by_tracker return an array of transactions
1 parent 0648f2d commit 86edd22

File tree

9 files changed

+37
-31
lines changed

9 files changed

+37
-31
lines changed

core/src/client/client.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,8 @@ impl AssetClient for Client {
392392
Some(_) => {}
393393
}
394394

395-
let localized = self.transaction_by_tracker(&tracker).expect("There is a successful transaction");
395+
let localized =
396+
self.transactions_by_tracker(&tracker).last().cloned().expect("There is a successful transaction");
396397
let transaction = if let Some(tx) = Option::<ShardTransaction>::from(localized.action.clone()) {
397398
tx
398399
} else {
@@ -704,10 +705,10 @@ impl BlockChainClient for Client {
704705
self.transaction_address(id).and_then(|address| chain.invoice(&address))
705706
}
706707

707-
fn transaction_by_tracker(&self, tracker: &H256) -> Option<LocalizedTransaction> {
708+
fn transactions_by_tracker(&self, tracker: &H256) -> Vec<LocalizedTransaction> {
708709
let chain = self.block_chain();
709-
let address = self.transaction_addresses(tracker)?;
710-
address.into_iter().map(Into::into).map(|address| chain.transaction(&address)).next()?
710+
let address = self.transaction_addresses(tracker).unwrap_or_default();
711+
address.into_iter().map(Into::into).filter_map(|address| chain.transaction(&address)).collect()
711712
}
712713

713714
fn invoices_by_tracker(&self, tracker: &H256) -> Vec<Invoice> {

core/src/client/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ pub trait BlockChainClient:
263263
fn invoice(&self, id: &TransactionId) -> Option<Invoice>;
264264

265265
/// Get the transaction with given tracker.
266-
fn transaction_by_tracker(&self, tracker: &H256) -> Option<LocalizedTransaction>;
266+
fn transactions_by_tracker(&self, tracker: &H256) -> Vec<LocalizedTransaction>;
267267

268268
fn invoices_by_tracker(&self, tracker: &H256) -> Vec<Invoice>;
269269
}

core/src/client/test_client.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ impl BlockChainClient for TestBlockChainClient {
547547
unimplemented!();
548548
}
549549

550-
fn transaction_by_tracker(&self, _: &H256) -> Option<LocalizedTransaction> {
550+
fn transactions_by_tracker(&self, _: &H256) -> Vec<LocalizedTransaction> {
551551
unimplemented!();
552552
}
553553

rpc/src/v1/impls/chain.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,17 @@ where
105105
Ok(self.client.invoice(&transaction_hash.into()).map(|invoice| invoice.to_bool()))
106106
}
107107

108-
fn get_transaction_by_tracker(&self, tracker: H256) -> Result<Option<Transaction>> {
109-
Ok(self.client.transaction_by_tracker(&tracker).map(|tx| {
110-
let transaction_id = tx.hash().into();
111-
let invoice = self.client.invoice(&transaction_id).expect("Invoice must exist when transaction exists");
112-
Transaction::from(tx, invoice.to_bool())
113-
}))
108+
fn get_transactions_by_tracker(&self, tracker: H256) -> Result<Vec<Transaction>> {
109+
Ok(self
110+
.client
111+
.transactions_by_tracker(&tracker)
112+
.into_iter()
113+
.map(|tx| {
114+
let transaction_id = tx.hash().into();
115+
let invoice = self.client.invoice(&transaction_id).expect("Invoice must exist when transaction exists");
116+
Transaction::from(tx, invoice.to_bool())
117+
})
118+
.collect())
114119
}
115120

116121
fn get_transaction_results_by_tracker(&self, tracker: H256) -> Result<Vec<bool>> {

rpc/src/v1/traits/chain.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ build_rpc_trait! {
4242
fn get_transaction_result(&self, H256) -> Result<Option<bool>>;
4343

4444
/// Gets transaction with given transaction tracker.
45-
# [rpc(name = "chain_getTransactionByTracker")]
46-
fn get_transaction_by_tracker(&self, H256) -> Result<Option<Transaction>>;
45+
# [rpc(name = "chain_getTransactionsByTracker")]
46+
fn get_transactions_by_tracker(&self, H256) -> Result<Vec<Transaction>>;
4747

4848
/// Gets transaction results with given transaction tracker.
4949
# [rpc(name = "chain_getTransactionResultsByTracker")]

spec/JSON-RPC.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ When `Transaction` is included in any response, there will be an additional fiel
289289
* [chain_sendSignedTransaction](#chain_sendsignedtransaction)
290290
* [chain_getTransaction](#chain_gettransaction)
291291
* [chain_getTransactionResult](#chain_gettransactionresult)
292-
* [chain_getTransactionByTracker](#chain_gettransactionbytracker)
292+
* [chain_getTransactionsByTracker](#chain_gettransactionsbytracker)
293293
* [chain_getTransactionResultsByTracker](#chain_getTransactionResultsByTracker)
294294
* [chain_getAssetSchemeByTracker](#chain_getassetschemebytracker)
295295
* [chain_getAssetSchemeByType](#chain_getassetschemebytype)
@@ -817,30 +817,30 @@ Errors: `Invalid Params`
817817

818818
[Back to **List of methods**](#list-of-methods)
819819

820-
## chain_getTransactionByTracker
821-
Gets a transaction with the given tracker.
820+
## chain_getTransactionsByTracker
821+
Gets transactions with the given tracker.
822822

823823
### Params
824824
1. tracker - `H256`
825825

826826
### Returns
827-
`null` | `Transaction`
827+
`Transaction[]`
828828

829829
Errors: `Invalid Params`
830830

831831
### Request Example
832832
```
833833
curl \
834834
-H 'Content-Type: application/json' \
835-
-d '{"jsonrpc": "2.0", "method": "chain_getTransactionByTracker", "params": ["0x24df02abcd4e984e90253dc344e89b8431bbb319c66643bfef566dfdf46ec6bc"], "id": null}' \
835+
-d '{"jsonrpc": "2.0", "method": "chain_getTransactionsByTracker", "params": ["0x24df02abcd4e984e90253dc344e89b8431bbb319c66643bfef566dfdf46ec6bc"], "id": null}' \
836836
localhost:8080
837837
```
838838

839839
### Response Example
840840
```
841841
{
842842
"jsonrpc": "2.0",
843-
"result": {
843+
"result": [{
844844
"action": {
845845
"type":"pay",
846846
"amount":"0xa",
@@ -855,7 +855,7 @@ Errors: `Invalid Params`
855855
"seq": 4,
856856
"transactionIndex": 0,
857857
"sig":"0x291d932e55162407eb01915923d68cf78df4815a25fc6033488b644bda44b02251123feac3a3c56a399a2b32331599fd50b7a39ec2c1a2325e37f383c6aeedc301"
858-
}
858+
}],
859859
"id": null,
860860
}
861861
```

test/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
"chai": "^4.2.0",
4545
"chai-as-promised": "^7.1.1",
4646
"codechain-primitives": "^0.4.8",
47-
"codechain-sdk": "^0.6.0",
47+
"codechain-sdk": "https://github.com/majecty/codechain-sdk-js-1.git#f/get-transactions-by-tracker-build",
4848
"crypto": "^1.0.1",
4949
"dgram": "^1.0.1",
5050
"elliptic": "^6.4.1",

test/src/e2e/chain.test.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {
2424
H256,
2525
H512,
2626
MintAsset,
27+
SignedTransaction,
2728
U64
2829
} from "codechain-sdk/lib/core/classes";
2930
import "mocha";
@@ -240,15 +241,15 @@ describe("chain", function() {
240241
await node.sdk.rpc.chain.sendSignedTransaction(signed);
241242
});
242243

243-
it("getTransactionByTracker", async function() {
244+
it("getTransactionsByTracker", async function() {
244245
expect(
245-
((await node.sdk.rpc.chain.getTransactionByTracker(
246+
((await node.sdk.rpc.chain.getTransactionsByTracker(
246247
tx.tracker()
247-
)) as any).unsigned
248-
).to.deep.equal(tx);
248+
)) as any).map((tx: SignedTransaction) => tx.unsigned)
249+
).to.deep.equal([tx]);
249250
expect(
250-
await node.sdk.rpc.chain.getTransactionByTracker(invalidH256)
251-
).to.be.null;
251+
await node.sdk.rpc.chain.getTransactionsByTracker(invalidH256)
252+
).to.deep.equal([]);
252253
});
253254

254255
it("getTransactionResultsByTracker", async function() {

test/yarn.lock

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -554,10 +554,9 @@ codechain-primitives@^0.4.7, codechain-primitives@^0.4.8:
554554
ripemd160 "^2.0.2"
555555
rlp "^2.1.0"
556556

557-
codechain-sdk@^0.6.0:
557+
"codechain-sdk@https://github.com/majecty/codechain-sdk-js-1.git#f/get-transactions-by-tracker-build":
558558
version "0.6.0"
559-
resolved "https://registry.yarnpkg.com/codechain-sdk/-/codechain-sdk-0.6.0.tgz#9bbcac07ee5004221b0b0d5910cfb6e98e40ee77"
560-
integrity sha512-Fo2BnR39AHMArhlxL/jESoCnbipvHUVFrfc2OuI2gdCokI5+4Y1g+X+FSW6lVc4UjnaNP5MZ/upvNgMPfuXxNQ==
559+
resolved "https://github.com/majecty/codechain-sdk-js-1.git#d26d2ffe85c1ec2b27f0e16457fd0719b775f6ed"
561560
dependencies:
562561
buffer "5.1.0"
563562
codechain-keystore "^0.6.0"

0 commit comments

Comments
 (0)