Bug fix for token API not working
This commit is contained in:
parent
067684c982
commit
77ebcccd46
@ -1,4 +1,4 @@
|
|||||||
(function (EXPORTS) { //floTokenAPI v1.2.0
|
(function (EXPORTS) { //floTokenAPI v1.2.1
|
||||||
/* Token Operator to send/receive tokens via blockchain using API calls*/
|
/* Token Operator to send/receive tokens via blockchain using API calls*/
|
||||||
'use strict';
|
'use strict';
|
||||||
const tokenAPI = EXPORTS;
|
const tokenAPI = EXPORTS;
|
||||||
@ -79,10 +79,10 @@
|
|||||||
fetch_api(`api/v2/transactionDetails/${txID}`).then(res => {
|
fetch_api(`api/v2/transactionDetails/${txID}`).then(res => {
|
||||||
if (res.result === "error")
|
if (res.result === "error")
|
||||||
reject(res.description);
|
reject(res.description);
|
||||||
else if (!res.parsedFloData)
|
//else if (!res.parsedFloData)
|
||||||
reject("Data piece (parsedFloData) missing");
|
// reject("Data piece (parsedFloData) missing");
|
||||||
else if (!res.transactionDetails)
|
//else if (!res.transactionDetails)
|
||||||
reject("Data piece (transactionDetails) missing");
|
// reject("Data piece (transactionDetails) missing");
|
||||||
else
|
else
|
||||||
resolve(res);
|
resolve(res);
|
||||||
}).catch(error => reject(error))
|
}).catch(error => reject(error))
|
||||||
|
|||||||
@ -129,20 +129,24 @@ function confirmDepositToken() {
|
|||||||
verifyTx.token = function (sender, txid, group, currencyOnly = false) {
|
verifyTx.token = function (sender, txid, group, currencyOnly = false) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
floTokenAPI.getTx(txid).then(tx => {
|
floTokenAPI.getTx(txid).then(tx => {
|
||||||
if (tx.parsedFloData.type !== "transfer")
|
if (tx.type !== "transfer")
|
||||||
return reject([true, "Transaction type not 'transfer'"]);
|
return reject([true, "Transaction type not 'transfer'"]);
|
||||||
else if (tx.parsedFloData.transferType !== "token")
|
else if (tx.transferType !== "token")
|
||||||
return reject([true, "Transaction transfer is not 'token'"]);
|
return reject([true, "Transaction transfer is not 'token'"]);
|
||||||
var token = tx.parsedFloData.tokenIdentification,
|
var token = tx.tokenIdentification,
|
||||||
amount = tx.parsedFloData.tokenAmount;
|
amount = tx.tokenAmount,
|
||||||
|
receiverAddress = tx.receiverAddress,
|
||||||
|
senderAddress = tx.senderAddress;
|
||||||
if (currencyOnly && token !== floGlobals.currency)
|
if (currencyOnly && token !== floGlobals.currency)
|
||||||
return reject([true, "Token not currency"]);
|
return reject([true, "Token not currency"]);
|
||||||
else if (!currencyOnly && ((!assetList.includes(token) && token !== floGlobals.currency) || token === "FLO"))
|
else if (!currencyOnly && ((!assetList.includes(token) && token !== floGlobals.currency) || token === "FLO"))
|
||||||
return reject([true, "Token not authorised"]);
|
return reject([true, "Token not authorised"]);
|
||||||
let vin_sender = tx.transactionDetails.vin.filter(v => v.addr === sender)
|
//let vin_sender = tx.vin.filter(v => v.addr === sender)
|
||||||
if (!vin_sender.length)
|
if (senderAddress != sender)
|
||||||
return reject([true, "Transaction not sent by the sender"]);
|
return reject([true, "Transaction not sent by the sender"]);
|
||||||
let flo_amount = tx.transactionDetails.vout.reduce((a, v) => keys.sink_chest.includes(group, v.scriptPubKey.addresses[0]) ? a + v.value : a, 0);
|
if (!keys.sink_chest.includes(group, receiverAddress))
|
||||||
|
return reject([true, "Transaction receiver is not market ID"]); //Maybe reject as false? (to compensate delay in chestsList loading from other nodes)
|
||||||
|
let flo_amount = tx.vout.reduce((a, v) => keys.sink_chest.includes(group, v.scriptPubKey.addresses[0]) ? a + v.value : a, 0);
|
||||||
if (flo_amount == 0)
|
if (flo_amount == 0)
|
||||||
return reject([true, "Transaction receiver is not market ID"]); //Maybe reject as false? (to compensate delay in chestsList loading from other nodes)
|
return reject([true, "Transaction receiver is not market ID"]); //Maybe reject as false? (to compensate delay in chestsList loading from other nodes)
|
||||||
else
|
else
|
||||||
@ -185,7 +189,7 @@ function confirmVaultWithdraw() {
|
|||||||
}).catch(error => console.error(error));
|
}).catch(error => console.error(error));
|
||||||
} else if (r.asset_type == pCode.ASSET_TYPE_TOKEN)
|
} else if (r.asset_type == pCode.ASSET_TYPE_TOKEN)
|
||||||
floTokenAPI.getTx(r.txid).then(tx => {
|
floTokenAPI.getTx(r.txid).then(tx => {
|
||||||
if (!tx.transactionDetails.blockheight || !tx.transactionDetails.confirmations) //Still not confirmed
|
if (!tx.blockheight || !tx.confirmations) //Still not confirmed
|
||||||
return;
|
return;
|
||||||
DB.query("UPDATE VaultTransactions SET r_status=? WHERE id=?", [pCode.STATUS_SUCCESS, r.id])
|
DB.query("UPDATE VaultTransactions SET r_status=? WHERE id=?", [pCode.STATUS_SUCCESS, r.id])
|
||||||
.then(result => console.info("Token withdrawed:", r.floID, r.asset, r.amount))
|
.then(result => console.info("Token withdrawed:", r.floID, r.asset, r.amount))
|
||||||
@ -286,7 +290,7 @@ function confirmConvert() {
|
|||||||
}).catch(error => console.error(error));
|
}).catch(error => console.error(error));
|
||||||
else if (r.mode == pCode.CONVERT_MODE_PUT)
|
else if (r.mode == pCode.CONVERT_MODE_PUT)
|
||||||
floTokenAPI.getTx(r.out_txid).then(tx => {
|
floTokenAPI.getTx(r.out_txid).then(tx => {
|
||||||
if (!tx.transactionDetails.blockheight || !tx.transactionDetails.confirmations) //Still not confirmed
|
if (!tx.blockheight || !tx.confirmations) //Still not confirmed
|
||||||
return;
|
return;
|
||||||
DB.query("UPDATE DirectConvert SET r_status=? WHERE id=?", [pCode.STATUS_SUCCESS, r.id])
|
DB.query("UPDATE DirectConvert SET r_status=? WHERE id=?", [pCode.STATUS_SUCCESS, r.id])
|
||||||
.then(result => console.info(`${r.floID} converted ${r.quantity} BTC to ${r.amount}`))
|
.then(result => console.info(`${r.floID} converted ${r.quantity} BTC to ${r.amount}`))
|
||||||
@ -350,7 +354,7 @@ function confirmConvertFundWithdraw() {
|
|||||||
}).catch(error => console.error(error));
|
}).catch(error => console.error(error));
|
||||||
} else if (r.mode == pCode.CONVERT_MODE_PUT) {//withdraw currency
|
} else if (r.mode == pCode.CONVERT_MODE_PUT) {//withdraw currency
|
||||||
floTokenAPI.getTx(r.txid).then(tx => {
|
floTokenAPI.getTx(r.txid).then(tx => {
|
||||||
if (!tx.transactionDetails.blockheight || !tx.transactionDetails.confirmations) //Still not confirmed
|
if (!tx.blockheight || !tx.confirmations) //Still not confirmed
|
||||||
return;
|
return;
|
||||||
DB.query("UPDATE ConvertFund SET r_status=? WHERE id=?", [pCode.STATUS_SUCCESS, r.id])
|
DB.query("UPDATE ConvertFund SET r_status=? WHERE id=?", [pCode.STATUS_SUCCESS, r.id])
|
||||||
.then(result => console.info(`Withdraw-fund ${r.amount} ${floGlobals.currency} successful`))
|
.then(result => console.info(`Withdraw-fund ${r.amount} ${floGlobals.currency} successful`))
|
||||||
@ -407,7 +411,7 @@ function confirmConvertRefund() {
|
|||||||
}).catch(error => console.error(error));
|
}).catch(error => console.error(error));
|
||||||
} else if (r.ASSET_TYPE_TOKEN)
|
} else if (r.ASSET_TYPE_TOKEN)
|
||||||
floTokenAPI.getTx(r.out_txid).then(tx => {
|
floTokenAPI.getTx(r.out_txid).then(tx => {
|
||||||
if (!tx.transactionDetails.blockheight || !tx.transactionDetails.confirmations) //Still not confirmed
|
if (!tx.blockheight || !tx.confirmations) //Still not confirmed
|
||||||
return;
|
return;
|
||||||
DB.query("UPDATE RefundConvert SET r_status=? WHERE id=?", [pCode.STATUS_SUCCESS, r.id])
|
DB.query("UPDATE RefundConvert SET r_status=? WHERE id=?", [pCode.STATUS_SUCCESS, r.id])
|
||||||
.then(result => console.info(`Refunded ${r.amount} ${r.asset} to ${r.floID}`))
|
.then(result => console.info(`Refunded ${r.amount} ${r.asset} to ${r.floID}`))
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user