API for close-blockchain-bonds
This commit is contained in:
parent
90d2a4764e
commit
7c99f41e48
@ -1307,6 +1307,37 @@
|
||||
})
|
||||
}
|
||||
|
||||
exchangeAPI.closeBlockchainBond = function (bond_id, floID, privKey) {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (!floCrypto.verifyPrivKey(privKey, floID))
|
||||
return reject(ExchangeError(ExchangeError.BAD_REQUEST_CODE, "Invalid Private Key", errorCode.INVALID_PRIVATE_KEY));
|
||||
let request = {
|
||||
floID: floID,
|
||||
bond_id: bond_id,
|
||||
timestamp: Date.now()
|
||||
};
|
||||
request.pubKey = floCrypto.getPubKeyHex(privKey);
|
||||
request.sign = signRequest({
|
||||
type: "close_blockchain_bond",
|
||||
bond_id: data.bond_id,
|
||||
timestamp: data.timestamp
|
||||
}, privKey);
|
||||
console.debug(request);
|
||||
|
||||
fetch_api('/close-blockchain-bonds', {
|
||||
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.init = function refreshDataFromBlockchain(adminID = floGlobals.adminID, appName = floGlobals.application) {
|
||||
return new Promise((resolve, reject) => {
|
||||
let nodes, assets, tags, lastTx;
|
||||
|
||||
@ -89,6 +89,9 @@ module.exports = function App(secret, DB) {
|
||||
app.post('/convert-to', Request.ConvertTo);
|
||||
app.post('/convert-from', Request.ConvertFrom);
|
||||
|
||||
//close blockchain-bond
|
||||
app.post('/close-blockchain-bonds', Request.CloseBlockchainBond);
|
||||
|
||||
//Manage user tags (Access to trusted IDs only)
|
||||
app.post('/add-tag', Request.AddUserTag);
|
||||
app.post('/remove-tag', Request.RemoveUserTag);
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
|
||||
const market = require("./market");
|
||||
const conversion = require('./services/conversion');
|
||||
const blokchain_bonds = require("./services/bonds");
|
||||
|
||||
const {
|
||||
SIGN_EXPIRE_TIME,
|
||||
@ -322,6 +323,18 @@ function ConvertFrom(req, res) {
|
||||
}, () => conversion.convertFromCoin(data.floID, data.txid, data.coin));
|
||||
}
|
||||
|
||||
function CloseBlockchainBond(req, res) {
|
||||
let data = req.body;
|
||||
if (!data.pubKey)
|
||||
res.status(INVALID.e_code).send(INVALID.str(eCode.MISSING_PARAMETER, "Public key missing"));
|
||||
else
|
||||
processRequest(res, data.floID, data.pubKey, data.sign, "Conversion", {
|
||||
type: "close_blockchain_bond",
|
||||
bond_id: data.bond_id,
|
||||
timestamp: data.timestamp
|
||||
}, () => blokchain_bonds.closeBond(data.bond_id, data.floID, `${data.timestamp}.${data.sign}`));
|
||||
}
|
||||
|
||||
/* Public Requests */
|
||||
|
||||
function GetLoginCode(req, res) {
|
||||
@ -517,6 +530,7 @@ module.exports = {
|
||||
RemoveDistributor,
|
||||
ConvertTo,
|
||||
ConvertFrom,
|
||||
CloseBlockchainBond,
|
||||
set trustedIDs(ids) {
|
||||
trustedIDs = ids;
|
||||
},
|
||||
@ -532,6 +546,8 @@ module.exports = {
|
||||
set DB(db) {
|
||||
DB = db;
|
||||
market.DB = db;
|
||||
conversion.DB;
|
||||
blokchain_bonds.DB;
|
||||
},
|
||||
set secret(s) {
|
||||
secret = s;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user