Get transaction details

- Transaction details can be fetched using the following API
/get-transaction?txid=<txid>
- Get rates now accepts parameter 'asset' (optional) to return rate of particular asset.
/get-rates?asset=<asset>
/get-rates
- Get transactions (trade) API is changed to the following
/list-trades
This commit is contained in:
sairajzero 2022-03-12 03:31:01 +05:30
parent 0520791696
commit 3296b16710
5 changed files with 80 additions and 14 deletions

View File

@ -141,9 +141,9 @@ function getSellList() {
});
}
function getTransactionList() {
function getTradeList() {
return new Promise((resolve, reject) => {
exchangeAPI('/list-transactions')
exchangeAPI('/list-trades')
.then(result => responseParse(result)
.then(result => resolve(result))
.catch(error => reject(error)))
@ -151,9 +151,9 @@ function getTransactionList() {
});
}
function getRates() {
function getRates(asset = null) {
return new Promise((resolve, reject) => {
exchangeAPI('/get-rates')
exchangeAPI('/get-rates' + (asset ? "?asset=" + asset : ""))
.then(result => responseParse(result)
.then(result => resolve(result))
.catch(error => reject(error)))
@ -161,6 +161,18 @@ function getRates() {
});
}
function getTx(txid) {
return new Promise((resolve, reject) => {
if (!txid)
return reject('txid required');
exchangeAPI('/get-transaction?txid=' + txid)
.then(result => responseParse(result)
.then(result => resolve(result))
.catch(error => reject(error)))
.catch(error => reject(error));
})
}
function signRequest(request, privKey) {
if (typeof request !== "object")
throw Error("Request is not an object");

View File

@ -1456,7 +1456,7 @@
}
} else {
try {
const marketTransactions = await getTransactionList()
const marketTransactions = await getTradeList()
marketTransactions.forEach(transaction => {
const { seller, buyer, asset, quantity, unitValue, tx_time } = transaction
const transactionDetails = {

View File

@ -71,13 +71,14 @@ module.exports = function App(secret, DB) {
//transfer amount to another user
app.post('/transfer-token', Request.TransferToken);
//list sell or buy order
//list all orders and trades
app.get('/list-sellorders', Request.ListSellOrders);
app.get('/list-buyorders', Request.ListBuyOrders);
//list all process transactions and rate
app.get('/list-transactions', Request.ListTransactions);
app.get('/get-rates', Request.getRates)
app.get('/list-trades', Request.ListTradeTransactions);
//get rates and tx
app.get('/get-rates', Request.getRates);
app.get('/get-transaction', Request.getTransaction);
//get account details
app.post('/account', Request.Account);

View File

@ -4,6 +4,7 @@ const coupling = require('./coupling');
const {
MINIMUM_BUY_REQUIREMENT,
TRADE_HASH_PREFIX,
TRANSFER_HASH_PREFIX
} = require('./_constants')["market"];
@ -184,6 +185,26 @@ function getAccountDetails(floID) {
});
}
function getTransactionDetails(txid) {
let tableName, type;
if (txid.startsWith(TRANSFER_HASH_PREFIX)) {
tableName = 'TransferTransactions';
type = 'transfer';
} else if (txid.startsWith(TRADE_HASH_PREFIX)) {
tableName = 'TradeTransactions';
type = 'trade';
} else
return reject(INVALID("Invalid TransactionID"));
DB.query(`SELECT * FROM ${tableName} WHERE txid=?`, [txid]).then(result => {
if (result.length) {
let details = result[0];
details.type = type;
resolve(details);
} else
reject(INVALID("Transaction not found"));
}).catch(error => reject(error))
}
function transferToken(sender, receiver, token, amount) {
return new Promise((resolve, reject) => {
if (floCrypto.validateAddr(sender))
@ -496,6 +517,7 @@ module.exports = {
addSellOrder,
cancelOrder,
getAccountDetails,
getTransactionDetails,
transferToken,
depositFLO,
withdrawFLO,

View File

@ -289,7 +289,7 @@ function ListBuyOrders(req, res) {
.catch(error => res.status(INTERNAL.e_code).send("Try again later!"));
}
function ListTransactions(req, res) {
function ListTradeTransactions(req, res) {
//TODO: Limit size (recent)
DB.query("SELECT * FROM TradeTransactions ORDER BY tx_time DESC")
.then(result => res.send(result))
@ -299,8 +299,38 @@ function ListTransactions(req, res) {
function getRates(req, res) {
if (!serving)
res.status(INVALID.e_code).send(INVALID_SERVER_MSG);
else
res.send(market.rates);
else {
let asset = req.query.asset,
rates = market.rates;
if (asset) {
if (asset in rates)
res.send(rates[asset]);
else
res.status(INVALID.e_code).send("Invalid asset parameter");
} else
res.send(rates);
}
}
function getTransaction(req, res) {
if (!serving)
res.status(INVALID.e_code).send(INVALID_SERVER_MSG);
else {
let txid = req.query.txid;
if (!txid)
res.status(INVALID.e_code).send("txid (transactionID) parameter missing");
market.getTransactionDetails(txid)
.then(result => res.send(result))
.catch(error => {
if (error instanceof INVALID)
res.status(INVALID.e_code).send(error.message);
else {
console.error(error);
res.status(INTERNAL.e_code).send("Unable to process! Try again later!");
}
});
}
}
function Account(req, res) {
@ -512,8 +542,9 @@ module.exports = {
TransferToken,
ListSellOrders,
ListBuyOrders,
ListTransactions,
ListTradeTransactions,
getRates,
getTransaction,
Account,
DepositFLO,
WithdrawFLO,