diff --git a/args/schema.sql b/args/schema.sql index 57c4611..71275f7 100644 --- a/args/schema.sql +++ b/args/schema.sql @@ -117,8 +117,8 @@ CREATE TABLE BuyOrder ( CREATE TABLE VaultTransactions ( id INT NOT NULL AUTO_INCREMENT, floID CHAR(34) NOT NULL, - mode BIT NOT NULL, - asset_type BIT NOT NULL, + mode TINYINT NOT NULL, + asset_type TINYINT NOT NULL, asset VARCHAR(32), amount DECIMAL(16, 8), txid VARCHAR(128), @@ -264,7 +264,7 @@ CREATE TABLE ConvertFund( amount DECIMAL(16, 8), coin VARCHAR(8) NOT NULL, quantity DECIMAL(16, 8), - mode BIT NOT NULL, + mode TINYINT NOT NULL, txid VARCHAR(128), r_status TINYINT NOT NULL, PRIMARY KEY(id) @@ -276,7 +276,7 @@ CREATE TABLE DirectConvert( amount DECIMAL(16, 8), coin VARCHAR(8) NOT NULL, quantity DECIMAL(16, 8), - mode BIT NOT NULL, + mode TINYINT NOT NULL, in_txid VARCHAR(128), out_txid VARCHAR(128), locktime TIMESTAMP DEFAULT CURRENT_TIMESTAMP, diff --git a/docs/index.html b/docs/index.html index 107bbdb..a5e729c 100644 --- a/docs/index.html +++ b/docs/index.html @@ -16,6 +16,7 @@ + diff --git a/docs/scripts/btcOperator.js b/docs/scripts/btcOperator.js index ce8b09d..bb0b7ca 100644 --- a/docs/scripts/btcOperator.js +++ b/docs/scripts/btcOperator.js @@ -1,4 +1,4 @@ -(function (EXPORTS) { //btcOperator v1.0.11 +(function (EXPORTS) { //btcOperator v1.0.12 /* BTC Crypto and API Operator */ const btcOperator = EXPORTS; @@ -32,16 +32,30 @@ } const broadcastTx = btcOperator.broadcastTx = rawTxHex => new Promise((resolve, reject) => { - $.ajax({ - type: "POST", - url: URL + "send_tx/BTC/", - data: { - "tx_hex": rawTxHex + let url = 'https://coinb.in/api/?uid=1&key=12345678901234567890123456789012&setmodule=bitcoin&request=sendrawtransaction'; + fetch(url, { + method: 'POST', + headers: { + 'Content-Type': 'application/x-www-form-urlencoded' }, - dataType: "json", - error: e => reject((e.responseJSON && e.responseJSON.status === "fail") ? null : e.responseJSON), - success: r => r.status === "success" ? resolve(r.data.txid) : reject(r) - }) + body: "rawtx=" + rawTxHex + }).then(response => { + response.text().then(resultText => { + let r = resultText.match(/.*<\/result>/); + if (!r) + reject(resultText); + else { + r = r.pop().replace('', '').replace('', ''); + if (r == '1') { + let txid = resultText.match(/.*<\/txid>/).pop().replace('', '').replace('', ''); + resolve(txid); + } else if (r == '0') { + let error = resultText.match(/.*<\/response>/).pop().replace('', '').replace('', ''); + reject(decodeURIComponent(error.replace(/\+/g, " "))); + } else reject(resultText); + } + }).catch(error => reject(error)) + }).catch(error => reject(error)) }); Object.defineProperties(btcOperator, { @@ -461,7 +475,7 @@ }) } - const createSignedTx = btcOperator.createSignedTx = function (senders, privkeys, receivers, amounts, fee, change_addr = null) { + const createSignedTx = btcOperator.createSignedTx = function (senders, privkeys, receivers, amounts, fee = null, change_addr = null) { return new Promise((resolve, reject) => { try { ({ @@ -529,7 +543,7 @@ }) } - btcOperator.createMultiSigTx = function (sender, redeemScript, receivers, amounts, fee) { + btcOperator.createMultiSigTx = function (sender, redeemScript, receivers, amounts, fee = null) { return new Promise((resolve, reject) => { //validate tx parameters if (validateAddress(sender) !== "multisig") diff --git a/docs/scripts/floExchangeAPI.js b/docs/scripts/floExchangeAPI.js index 3af1ae5..b51e678 100644 --- a/docs/scripts/floExchangeAPI.js +++ b/docs/scripts/floExchangeAPI.js @@ -708,39 +708,6 @@ }) } - /* - exchangeAPI.signUp = function (privKey, code, hash) { - return new Promise((resolve, reject) => { - if (!code || !hash) - return reject(ExchangeError(ExchangeError.BAD_REQUEST_CODE, "Login Code missing", errorCode.MISSING_PARAMETER)); - let request = { - pubKey: floCrypto.getPubKeyHex(privKey), - floID: floCrypto.getFloID(privKey), - code: code, - hash: hash, - timestamp: Date.now() - }; - request.sign = signRequest({ - type: "create_account", - random: code, - timestamp: request.timestamp - }, privKey); - console.debug(request); - - fetch_api("/signup", { - method: "POST", - headers: { - 'Content-Type': 'application/json' - }, - body: JSON.stringify(request) - }).then(result => {responseParse(result, false) - .then(result => resolve(result)) - .catch(error => reject(error))}) - .catch(error => reject(error)); - }); - } - */ - exchangeAPI.login = function (privKey, proxyKey, code, hash) { return new Promise((resolve, reject) => { if (!code || !hash) @@ -1252,7 +1219,7 @@ }) } - exchangeAPI.convertToBTC = function (amount, floID, sinkID, privKey, proxySecret = null) { + exchangeAPI.convertToBTC = function (amount, floID, sinkID, 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)); @@ -1264,15 +1231,14 @@ amount: amount, timestamp: Date.now() }; - if (!proxySecret) //Direct signing (without proxy) - request.pubKey = floCrypto.getPubKeyHex(privKey); + request.pubKey = floCrypto.getPubKeyHex(privKey); request.sign = signRequest({ type: "convert_to", coin: request.coin, amount: amount, txid: txid, timestamp: request.timestamp - }, proxySecret || privKey); + }, privKey); console.debug(request); fetch_api('/convert-to', { @@ -1290,13 +1256,13 @@ }) } - exchangeAPI.convertFromBTC = function (quantity, floID, sinkID, privKey, proxySecret = null) { + exchangeAPI.convertFromBTC = function (quantity, floID, sinkID, privKey, fee = null) { 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 btc_id = btcOperator.convert.legacy2bech(floID), btc_sink = btcOperator.convert.legacy2bech(sinkID); - btcOperator.createSignedTx(btc_id, privKey, btc_sink, quantity, null).then(result => { + btcOperator.createSignedTx(btc_id, privKey, btc_sink, quantity, fee).then(result => { let request = { floID: floID, txid: btcOperator.transactionID(result.transaction), @@ -1305,15 +1271,14 @@ quantity: quantity, timestamp: Date.now() }; - if (!proxySecret) //Direct signing (without proxy) - request.pubKey = floCrypto.getPubKeyHex(privKey); + request.pubKey = floCrypto.getPubKeyHex(privKey); request.sign = signRequest({ type: "convert_from", coin: request.coin, quantity: quantity, - txid: data.txid, + txid: request.txid, timestamp: request.timestamp - }, proxySecret || privKey); + }, privKey); console.debug(request); fetch_api('/convert-from', { @@ -1344,6 +1309,7 @@ coin: "BTC", timestamp: Date.now() }; + request.pubKey = floCrypto.getPubKeyHex(privKey); request.sign = signRequest({ type: "deposit_convert_currency_fund", coin: request.coin, @@ -1382,12 +1348,13 @@ coin: "BTC", timestamp: Date.now() }; + request.pubKey = floCrypto.getPubKeyHex(privKey); request.sign = signRequest({ type: "deposit_convert_coin_fund", coin: request.coin, txid: data.txid, timestamp: request.timestamp - }, proxySecret || privKey); + }, privKey); console.debug(request); fetch_api('/deposit-convert-coin-fund', { @@ -1417,6 +1384,7 @@ coin: "BTC", timestamp: Date.now() }; + request.pubKey = floCrypto.getPubKeyHex(privKey); request.sign = signRequest({ type: "withdraw_convert_currency_fund", coin: request.coin, @@ -1451,6 +1419,7 @@ coin: "BTC", timestamp: Date.now() }; + request.pubKey = floCrypto.getPubKeyHex(privKey); request.sign = signRequest({ type: "withdraw_convert_coin_fund", coin: request.coin, diff --git a/src/main.js b/src/main.js index 3aae7d1..2b8b7bd 100644 --- a/src/main.js +++ b/src/main.js @@ -5,6 +5,7 @@ require('../docs/scripts/lib'); global.floCrypto = require('../docs/scripts/floCrypto'); global.floBlockchainAPI = require('../docs/scripts/floBlockchainAPI'); global.floTokenAPI = require('../docs/scripts/floTokenAPI'); +global.btcOperator = require('../docs/scripts/btcOperator'); const Database = require("./database"); const App = require('./app');