Skip to content
This repository has been archived by the owner on Jun 11, 2024. It is now read-only.

Provide API endpoint for transactions of an account - Closes #1892 #1920

Merged
merged 12 commits into from
Apr 25, 2018

Conversation

Tschakki
Copy link
Contributor

@Tschakki Tschakki commented Apr 23, 2018

What was the problem?

The new API had no endpoint to collect all the transactions of a specific address at once.

How did I fix it?

Create new filter senderIdOrRecipientId for transactions.

How to test it?

Make API call: /api/transactions?senderIdOrRecipientId=<address>

Review checklist

senderIdOrRecipientId:
type: string
format: address
example: 12668885769632475474L
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Tschakki senderIdOrRecipientId is just a request param. It would not be part of POST /transactions request.

senderIdOrRecipientId:
type: string
format: address
example: 12668885769632475474L
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Tschakki senderIdOrRecipientId is just a request param. It would not be part of GET /transactions response.

@MaciejBaj MaciejBaj changed the base branch from 1.0.0 to 1.0.0-beta.7 April 23, 2018 13:39
@MaciejBaj MaciejBaj changed the title New api endpoint for all tx of an account - Closes #1892 Provide API endpoint for transactions of an account - Closes #1892 Apr 23, 2018
@@ -102,6 +102,8 @@ __private.list = function(filter, cb) {
const params = {};
const where = [];
const allowedFieldsMap = {
senderIdOrRecipientId:
't_senderId" IN (${senderId:csv}) OR t_recipientId" IN (${recipientId:csv})',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems to be missing double quote in the beginning of t_senderId and t_recipientId

maxLength: 22
name: senderIdOrRecipientId
in: query
description: Public key to query
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Tschakki Its the address not the public key. Seems you forget to update it.

@@ -102,6 +102,8 @@ __private.list = function(filter, cb) {
const params = {};
const where = [];
const allowedFieldsMap = {
senderIdOrRecipientId:
'"t_senderId" IN (${senderId:csv}) OR "t_recipientId" IN (${recipientId:csv})',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(${senderId:csv}) and (${recipientId:csv}) should be (${senderIdOrRecipientId:csv})

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

haha yes, just found it out myself ^^

@shuse2
Copy link
Collaborator

shuse2 commented Apr 25, 2018

rather than having another query param senderIdOrRecipientId=<address>, which can be asked with other parameters, I think it would be better to add this feature on
/accounts/{address}/transactions.

@nazarhussain
Copy link
Contributor

@shuse2 Yes probably it would be nice to have a nested resource for accounts. Iff it would, then it must support all filters already provided in transactions endpoint.

Current implementation is a the shortest and easy way to meet the requirements we have. After 1.0.0 release will probably be doing improvements in API specially providing feature to compose filters with custom modifiers. That will be the permanent fix for requirement.

.then(res => {
expectSwaggerParamError(res, 'senderIdOrRecipientId');
});
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Tschakki This case handles the case fo empty string. You should also add a case where you specify value but invalid value.

}
});
expect(sender).to.have.length(1);
expect(recipient).to.have.length(1);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The transactions you posted are deterministic and you know there are only two such transactions. So having more clear expectations will be nice.

expect(res.body.data).to.not.empty;
expect(res.body.data[0].recipientId).to.be.eql(accountId);
expect(res.body.data[1].senderId).to.be.eql(accountId);

Notice how clean three line expectations look like and easy to understand.

Copy link
Contributor Author

@Tschakki Tschakki Apr 25, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is true there are only these 2 transactions, but are they returned always in the same chronological order inside of res.body.data?
If not these expectations could fail randomly.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logically there should be one specific order whatever it would be. There can't be random order.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, will change it then!

.then(res => {
expectSwaggerParamError(res, 'senderIdOrRecipientId');
});
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This definitely will fail, as the format of the param you specified in swagger is string not the array. So I don't think its a right test to be added.

@@ -102,6 +102,8 @@ __private.list = function(filter, cb) {
const params = {};
const where = [];
const allowedFieldsMap = {
senderIdOrRecipientId:
'"t_senderId" IN (${senderIdOrRecipientId:csv}) OR "t_recipientId" IN (${senderIdOrRecipientId:csv})',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One test case you should add is to check :csv formatter. Means send comma separated string value of this param. I believe it will fail because of address format we specified in swagger. So either you have to create new format for it or drop :csv here.

@Tschakki Tschakki force-pushed the 1892-api_endpoint_for_all_tx_of_an_account branch from c2f3f89 to b5cd640 Compare April 25, 2018 12:35
@@ -102,6 +102,8 @@ __private.list = function(filter, cb) {
const params = {};
const where = [];
const allowedFieldsMap = {
senderIdOrRecipientId:
'"t_senderId" IN (${senderIdOrRecipientId}) OR "t_recipientId" IN (${senderIdOrRecipientId})',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Tschakki That needs to be changed, now as you are doing checking for only one variable then you should do with the direct assignment.

"t_senderId" = (${senderIdOrRecipientId}) OR "t_recipientId" = (${senderIdOrRecipientId})

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants