get-transact API

- Get user's deposit and withdraw history (private request: ie, requires signing)
- Update floTokenAPI
This commit is contained in:
sairajzero 2022-05-25 03:55:55 +05:30
parent 56e571606c
commit 166778e7f8
5 changed files with 240 additions and 180 deletions

View File

@ -1058,6 +1058,33 @@
})
}
exchangeAPI.getUserTransacts = function(floID, proxySecret) {
return new Promise((resolve, reject) => {
let request = {
floID: floID,
timestamp: Date.now()
};
if (floCrypto.getFloID(proxySecret) === floID) //Direct signing (without proxy)
request.pubKey = floCrypto.getPubKeyHex(proxySecret);
request.sign = signRequest({
type: "get_transact",
timestamp: request.timestamp
}, proxySecret);
console.debug(request);
fetch_api('/get-transact', {
method: "POST",
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(request)
}).then(result => responseParse(result)
.then(result => resolve(result))
.catch(error => reject(error)))
.catch(error => reject(error))
})
}
exchangeAPI.addUserTag = function(tag_user, tag, floID, proxySecret) {
return new Promise((resolve, reject) => {
let request = {

View File

@ -1,4 +1,4 @@
(function(EXPORTS) { //floTokenAPI v1.0.3a
(function(EXPORTS) { //floTokenAPI v1.0.3b
/* Token Operator to send/receive tokens via blockchain using API calls*/
'use strict';
const tokenAPI = EXPORTS;
@ -20,6 +20,13 @@
if (floGlobals.currency) tokenAPI.currency = floGlobals.currency;
Object.defineProperties(floGlobals, {
currency: {
get: () => DEFAULT.currency,
set: currency => DEFAULT.currency = currency
}
});
const fetch_api = tokenAPI.fetch = function(apicall) {
return new Promise((resolve, reject) => {
console.log(DEFAULT.apiURL + apicall);

View File

@ -83,6 +83,7 @@ module.exports = function App(secret, DB) {
app.post('/withdraw-flo', Request.WithdrawFLO);
app.post('/deposit-token', Request.DepositToken);
app.post('/withdraw-token', Request.WithdrawToken);
app.post('/get-transact', Request.GetUserTransacts);
//Manage user tags (Access to trusted IDs only)
app.post('/add-tag', Request.AddUserTag);

View File

@ -254,6 +254,18 @@ function getAccountDetails(floID) {
});
}
function getUserTransacts(floID) {
return new Promise((resolve, reject) => {
DB.query("(SELECT 'deposit' as type, txid, floID, token, amount, status FROM InputToken WHERE floID=?)" +
"UNION (SELECT 'deposit' as type, txid, floID, 'FLO' as token, amount, status FROM InputFLO WHERE floID=?)" +
"UNION (SELECT 'withdraw' as type, txid, floID, token, amount, status FROM OutputToken WHERE floID=?)" +
"UNION (SELECT 'withdraw' as type, txid, floID, 'FLO' as token, amount, status FROM OutputFLO WHERE floID=?)",
[floID, floID, floID, floID])
.then(result => resolve(result))
.catch(error => reject(error))
})
}
function getTransactionDetails(txid) {
return new Promise((resolve, reject) => {
let tableName, type;
@ -712,6 +724,7 @@ function blockchainReCheck() {
retryWithdrawalToken();
confirmWithdrawalFLO();
confirmWithdrawalToken();
console.debug("Last Block :", lastSyncBlockHeight);
}
}).catch(error => console.error(error));
}
@ -731,6 +744,7 @@ module.exports = {
getRateHistory,
getBalance,
getAccountDetails,
getUserTransacts,
getTransactionDetails,
transferToken,
depositFLO,

View File

@ -265,6 +265,16 @@ function WithdrawToken(req, res) {
);
}
function GetUserTransacts(req, res) {
let data = req.body;
processRequest(res, "User Transacts", {
type: "get_transact",
timestamp: data.timestamp
}, data.sign, data.floID, data.pubKey,
() => market.getUserTransacts(data.floID)
);
}
function AddUserTag(req, res) {
let data = req.body;
if (!trustedIDs.includes(data.floID))
@ -509,6 +519,7 @@ module.exports = {
WithdrawFLO,
DepositToken,
WithdrawToken,
GetUserTransacts,
AddUserTag,
RemoveUserTag,
AddDistributor,