Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Digital currency transaction list endpoint #146

Merged
merged 6 commits into from
Oct 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
40 changes: 38 additions & 2 deletions modules/currency/api/currency-routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import currencySnapshot from '../data/currency-snapshot';
import GBP_USD_TICKER_DATA from '../data/gbp-usd-ticker-data';
import { getQtyFromRequest } from '../../../utils/route-utils';
import getDigitalCurrencyAddress from '../utils/getDigitalCurrencyAddress';
import getDigitalCurrencyTxList from '../utils/getDigitalCurrencyTxList';
import DigitalCoinEnum from '../consts/DigitalCoinEnum';

module.exports = function (app: core.Express) {
Expand Down Expand Up @@ -125,5 +126,40 @@ module.exports = function (app: core.Express) {
const qty = getQtyFromRequest(req);
const addresses = getDigitalCurrencyAddress(qty, DigitalCoinEnum.Litecoin);
res.json(addresses);
});
};
})

filipkujawa marked this conversation as resolved.
Show resolved Hide resolved
/**
* @openapi
* '/currencies/digital-coins/ethereum/tx-list/:address?/:qty?':
* get:
* tags:
* - Currency
* summary: Get the list of transactions performed by an address
* parameters:
* - in: path
* name: address
* description: The address that performed the transactions
* type: string
* - in: path
* name: qty
* description: The number of transactions to be returned
* type: number
* responses:
* '200':
* description: OK
* schema:
* type: json
* items:
* type: object
* example: [{"blockNumber":"27805946","timeStamp":"9942266267","hash":"0xaN6aaOQJX5PFBhXH1RjUlygLdJKqC01qRPC0QbKZ5TIowf7iJnB5DQngiV93jik5","nonce":"18","blockHash":"0xueMI7Aje55ctOTWcCpgMKoyD6Fr5K91uGkaxbpex1gRvKrq3oPyPB5U6qMf7Ia2f","transactionIndex":"5","from":"0xc5102fE9359FD9a28f877a67E36B0F050d81a3CC","to":"0x100807ff56cbc56f4574e515ddbefdbb8d86a7a0","value":"0.1759733580282401","gas":"2270","gasPrice":"573605567923","isError":"0","txreceipt_status":"1","input":"0xKuzGOUc0zN7sGqfFrmhLSsQKz69uZNUbHgSnnTldsCfFBHa682mvwIm2Ly3szQadWJftne0BzIO4obORd3dGKZIXAQ5XEnIveiwQ8ZXwQW9Q1MtnaSh1x5zjJ3Mc4OVHzmNxFMDe","confirmations":"33642"}]
*/

//Returns the list of transactions performed by an address
app.get("/currencies/digital-coins/ethereum/tx-list/:address?/:qty?", (req: Request, res: Response) => {
const address = req.params.address;
const qty = getQtyFromRequest(req);
const tx_list = getDigitalCurrencyTxList(address, qty);
res.json(tx_list);
})

}
20 changes: 20 additions & 0 deletions modules/currency/consts/TransactionInfo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
interface transactionInfo {
blockNumber: string;
timeStamp: string;
hash: string;
nonce: string;
blockHash: string;
transactionIndex: string;
from: string;
to: string;
value: string;
gas: string;
gasPrice: string;
isError: string;
txreceipt_status: string;
input: string;
confirmations: string;

}

export default transactionInfo;
13 changes: 13 additions & 0 deletions modules/currency/tests/api/currency-routes.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import request from 'supertest';
import app from '../../../../app';

describe('currency api endpoints', () => {
describe('GET /currencies/digital-coins/ethereum/tx-list', () => {
it('should return a list of transactions performed by an address', async () => {
const qty = 10;
const response = await request(baseURL).get(`/currencies/digital-coins/ethereum/tx-list/0xc5102fE9359FD9a28f877a67E36B0F050d81a3CC/${qty}`);

expect(response.body.length).toBe(qty);
});
});
});
50 changes: 50 additions & 0 deletions modules/currency/utils/getDigitalCurrencyTxList.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { faker } from '@faker-js/faker';
import transactionInfo from '../consts/TransactionInfo';

const getDigitalCurrencyTxList = (address: string, amount: number) : transactionInfo[] => {

const ETH_TX_LIST = []

for (let i = 0; i < amount; i++) {

let transaction: transactionInfo = {
blockNumber: (Math.floor(Math.random() * 99999999) + 10000000).toString(),
timeStamp: (Math.floor(Math.random() * 9999999999) + 1000000000).toString(),
hash: ("0x" + makeid(64)).toString(),
nonce: (Math.floor(Math.random() * 30) + 1).toString(),
blockHash: "0x" + makeid(64),
transactionIndex: (Math.floor(Math.random() * 30) + 1).toString(),
from: address,
to: faker.finance.ethereumAddress(),
value: (Math.random()).toString(),
gas: (Math.floor(Math.random() * 9999) + 1000).toString(),
gasPrice: (Math.floor(Math.random() * 999999999999) + 100000000000).toString(),
isError: "0",
txreceipt_status: "1",
input: "0x" + makeid(136),
confirmations: (Math.floor(Math.random() * 99999) + 100).toString(),

}

ETH_TX_LIST.push(transaction)

}

return ETH_TX_LIST


}

function makeid(length) {
var result = '';
var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
var charactersLength = characters.length;
for ( var i = 0; i < length; i++ ) {
result += characters.charAt(Math.floor(Math.random() *
charactersLength));
}
return result;
}


export default getDigitalCurrencyTxList;