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

Commit

Permalink
Merge pull request #1920 from LiskHQ/1892-api_endpoint_for_all_tx_of_…
Browse files Browse the repository at this point in the history
…an_account

Provide API endpoint for transactions of an account - Closes #1892
  • Loading branch information
MaciejBaj authored Apr 25, 2018
2 parents 6b26a2e + 3baca6c commit 0219f8f
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 3 deletions.
1 change: 1 addition & 0 deletions api/controllers/transactions.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ TransactionsController.getTransactions = function(context, next) {
var params = context.request.swagger.params;

var filters = {
senderIdOrRecipientId: params.senderIdOrRecipientId.value,
id: params.id.value,
blockId: params.blockId.value,
recipientId: params.recipientId.value,
Expand Down
2 changes: 2 additions & 0 deletions modules/transactions.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ __private.list = function(filter, cb) {
const params = {};
const where = [];
const allowedFieldsMap = {
senderIdOrRecipientId:
'"t_senderId" = ${senderIdOrRecipientId} OR "t_recipientId" = ${senderIdOrRecipientId}',
id: '"t_id" = ${id}',
blockId: '"t_blockId" = ${blockId}',
fromHeight: '"b_height" >= ${fromHeight}',
Expand Down
9 changes: 9 additions & 0 deletions schema/swagger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -859,6 +859,7 @@ paths:
- $ref: '#/parameters/recipientPublicKey'
- $ref: '#/parameters/senderId'
- $ref: '#/parameters/senderPublicKey'
- $ref: '#/parameters/senderIdOrRecipientId'
- $ref: '#/parameters/transactionType'
- $ref: '#/parameters/height'
- $ref: '#/parameters/minAmount'
Expand Down Expand Up @@ -1086,6 +1087,14 @@ parameters:
type: string
format: publicKey
minLength: 1
senderIdOrRecipientId:
name: senderIdOrRecipientId
in: query
description: Sender Id or Recipient Id to query
type: string
format: address
minLength: 1
maxLength: 22
transactionType:
name: type
in: query
Expand Down
54 changes: 51 additions & 3 deletions test/functional/http/get/transactions.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,31 @@ describe('GET /api/transactions', () => {
passphrase: accountFixtures.genesis.password,
recipientId: account2.address,
});
var transaction3 = lisk.transaction.transfer({
amount: 10 * constants.normalizer, // 10 LSK
passphrase: account.password,
recipientId: account2.address,
});

// Crediting accounts
before(() => {
var promises = [];
promises.push(apiHelpers.sendTransactionPromise(transaction1));
promises.push(apiHelpers.sendTransactionPromise(transaction2));

return Promise.all(promises).then(() => {
transactionList.push(transaction1);
transactionList.push(transaction2);
return waitFor.confirmations(_.map(transactionList, 'id'));

return waitFor
.confirmations(_.map(transactionList, 'id'))
.then(() => {
return apiHelpers.sendTransactionPromise(transaction3);
})
.then(() => {
transactionList.push(transaction3);
return waitFor.confirmations([transaction3.id]);
});
});
});

Expand Down Expand Up @@ -383,6 +398,36 @@ describe('GET /api/transactions', () => {
});
});

describe('senderIdOrRecipientId', () => {
it('using empty senderIdOrRecipientId should fail', () => {
return transactionsEndpoint
.makeRequest({ senderIdOrRecipientId: '' }, 400)
.then(res => {
expectSwaggerParamError(res, 'senderIdOrRecipientId');
});
});
it('using invalid senderIdOrRecipientId should fail', () => {
return transactionsEndpoint
.makeRequest(
{ senderIdOrRecipientId: '1234567890123456789012L' },
400
)
.then(res => {
expectSwaggerParamError(res, 'senderIdOrRecipientId');
});
});
it('using senderIdOrRecipientId should return incoming and outgoing transactions of an account', () => {
var accountId = account.address;
return transactionsEndpoint
.makeRequest({ senderIdOrRecipientId: accountId }, 200)
.then(res => {
expect(res.body.data).to.not.empty;
expect(res.body.data[0].senderId).to.be.eql(accountId);
expect(res.body.data[1].recipientId).to.be.eql(accountId);
});
});
});

describe('recipientPublicKey', () => {
it('using invalid recipientPublicKey should fail', () => {
return transactionsEndpoint
Expand Down Expand Up @@ -575,11 +620,14 @@ describe('GET /api/transactions', () => {
var firstTransaction = null;

return transactionsEndpoint
.makeRequest({ offset: 0 }, 200)
.makeRequest({ offset: 0, limit: 1 }, 200)
.then(res => {
firstTransaction = res.body.data[0];

return transactionsEndpoint.makeRequest({ offset: 1 }, 200);
return transactionsEndpoint.makeRequest(
{ offset: 1, limit: 1 },
200
);
})
.then(res => {
res.body.data.forEach(transaction => {
Expand Down

0 comments on commit 0219f8f

Please sign in to comment.