Bug fix
- Updated btcOperator - Changed all BIT to TINYINT in SQL schema - Fixed: "Public key missing" error in deposit/withdraw convert fund - Updated btcOperator - Fixed: btcOperator not imported in index.html and main.js
This commit is contained in:
parent
64a81fc762
commit
0389e833a5
@ -117,8 +117,8 @@ CREATE TABLE BuyOrder (
|
|||||||
CREATE TABLE VaultTransactions (
|
CREATE TABLE VaultTransactions (
|
||||||
id INT NOT NULL AUTO_INCREMENT,
|
id INT NOT NULL AUTO_INCREMENT,
|
||||||
floID CHAR(34) NOT NULL,
|
floID CHAR(34) NOT NULL,
|
||||||
mode BIT NOT NULL,
|
mode TINYINT NOT NULL,
|
||||||
asset_type BIT NOT NULL,
|
asset_type TINYINT NOT NULL,
|
||||||
asset VARCHAR(32),
|
asset VARCHAR(32),
|
||||||
amount DECIMAL(16, 8),
|
amount DECIMAL(16, 8),
|
||||||
txid VARCHAR(128),
|
txid VARCHAR(128),
|
||||||
@ -264,7 +264,7 @@ CREATE TABLE ConvertFund(
|
|||||||
amount DECIMAL(16, 8),
|
amount DECIMAL(16, 8),
|
||||||
coin VARCHAR(8) NOT NULL,
|
coin VARCHAR(8) NOT NULL,
|
||||||
quantity DECIMAL(16, 8),
|
quantity DECIMAL(16, 8),
|
||||||
mode BIT NOT NULL,
|
mode TINYINT NOT NULL,
|
||||||
txid VARCHAR(128),
|
txid VARCHAR(128),
|
||||||
r_status TINYINT NOT NULL,
|
r_status TINYINT NOT NULL,
|
||||||
PRIMARY KEY(id)
|
PRIMARY KEY(id)
|
||||||
@ -276,7 +276,7 @@ CREATE TABLE DirectConvert(
|
|||||||
amount DECIMAL(16, 8),
|
amount DECIMAL(16, 8),
|
||||||
coin VARCHAR(8) NOT NULL,
|
coin VARCHAR(8) NOT NULL,
|
||||||
quantity DECIMAL(16, 8),
|
quantity DECIMAL(16, 8),
|
||||||
mode BIT NOT NULL,
|
mode TINYINT NOT NULL,
|
||||||
in_txid VARCHAR(128),
|
in_txid VARCHAR(128),
|
||||||
out_txid VARCHAR(128),
|
out_txid VARCHAR(128),
|
||||||
locktime TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
locktime TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
|||||||
@ -16,6 +16,7 @@
|
|||||||
<script src="https://unpkg.com/uhtml@3.0.1/es.js"></script>
|
<script src="https://unpkg.com/uhtml@3.0.1/es.js"></script>
|
||||||
<script src="scripts/floGlobals.js"></script>
|
<script src="scripts/floGlobals.js"></script>
|
||||||
<script src="scripts/lib.js"></script>
|
<script src="scripts/lib.js"></script>
|
||||||
|
<script src="scripts/btcOperator.js"></script>
|
||||||
<script src="scripts/floCrypto.js"></script>
|
<script src="scripts/floCrypto.js"></script>
|
||||||
<script src="scripts/floBlockchainAPI.js"></script>
|
<script src="scripts/floBlockchainAPI.js"></script>
|
||||||
<script src="scripts/floTokenAPI.js"></script>
|
<script src="scripts/floTokenAPI.js"></script>
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
(function (EXPORTS) { //btcOperator v1.0.11
|
(function (EXPORTS) { //btcOperator v1.0.12
|
||||||
/* BTC Crypto and API Operator */
|
/* BTC Crypto and API Operator */
|
||||||
const btcOperator = EXPORTS;
|
const btcOperator = EXPORTS;
|
||||||
|
|
||||||
@ -32,16 +32,30 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
const broadcastTx = btcOperator.broadcastTx = rawTxHex => new Promise((resolve, reject) => {
|
const broadcastTx = btcOperator.broadcastTx = rawTxHex => new Promise((resolve, reject) => {
|
||||||
$.ajax({
|
let url = 'https://coinb.in/api/?uid=1&key=12345678901234567890123456789012&setmodule=bitcoin&request=sendrawtransaction';
|
||||||
type: "POST",
|
fetch(url, {
|
||||||
url: URL + "send_tx/BTC/",
|
method: 'POST',
|
||||||
data: {
|
headers: {
|
||||||
"tx_hex": rawTxHex
|
'Content-Type': 'application/x-www-form-urlencoded'
|
||||||
},
|
},
|
||||||
dataType: "json",
|
body: "rawtx=" + rawTxHex
|
||||||
error: e => reject((e.responseJSON && e.responseJSON.status === "fail") ? null : e.responseJSON),
|
}).then(response => {
|
||||||
success: r => r.status === "success" ? resolve(r.data.txid) : reject(r)
|
response.text().then(resultText => {
|
||||||
})
|
let r = resultText.match(/<result>.*<\/result>/);
|
||||||
|
if (!r)
|
||||||
|
reject(resultText);
|
||||||
|
else {
|
||||||
|
r = r.pop().replace('<result>', '').replace('</result>', '');
|
||||||
|
if (r == '1') {
|
||||||
|
let txid = resultText.match(/<txid>.*<\/txid>/).pop().replace('<txid>', '').replace('</txid>', '');
|
||||||
|
resolve(txid);
|
||||||
|
} else if (r == '0') {
|
||||||
|
let error = resultText.match(/<response>.*<\/response>/).pop().replace('<response>', '').replace('</response>', '');
|
||||||
|
reject(decodeURIComponent(error.replace(/\+/g, " ")));
|
||||||
|
} else reject(resultText);
|
||||||
|
}
|
||||||
|
}).catch(error => reject(error))
|
||||||
|
}).catch(error => reject(error))
|
||||||
});
|
});
|
||||||
|
|
||||||
Object.defineProperties(btcOperator, {
|
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) => {
|
return new Promise((resolve, reject) => {
|
||||||
try {
|
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) => {
|
return new Promise((resolve, reject) => {
|
||||||
//validate tx parameters
|
//validate tx parameters
|
||||||
if (validateAddress(sender) !== "multisig")
|
if (validateAddress(sender) !== "multisig")
|
||||||
|
|||||||
@ -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) {
|
exchangeAPI.login = function (privKey, proxyKey, code, hash) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
if (!code || !hash)
|
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) => {
|
return new Promise((resolve, reject) => {
|
||||||
if (!floCrypto.verifyPrivKey(privKey, floID))
|
if (!floCrypto.verifyPrivKey(privKey, floID))
|
||||||
return reject(ExchangeError(ExchangeError.BAD_REQUEST_CODE, "Invalid Private Key", errorCode.INVALID_PRIVATE_KEY));
|
return reject(ExchangeError(ExchangeError.BAD_REQUEST_CODE, "Invalid Private Key", errorCode.INVALID_PRIVATE_KEY));
|
||||||
@ -1264,7 +1231,6 @@
|
|||||||
amount: amount,
|
amount: amount,
|
||||||
timestamp: Date.now()
|
timestamp: Date.now()
|
||||||
};
|
};
|
||||||
if (!proxySecret) //Direct signing (without proxy)
|
|
||||||
request.pubKey = floCrypto.getPubKeyHex(privKey);
|
request.pubKey = floCrypto.getPubKeyHex(privKey);
|
||||||
request.sign = signRequest({
|
request.sign = signRequest({
|
||||||
type: "convert_to",
|
type: "convert_to",
|
||||||
@ -1272,7 +1238,7 @@
|
|||||||
amount: amount,
|
amount: amount,
|
||||||
txid: txid,
|
txid: txid,
|
||||||
timestamp: request.timestamp
|
timestamp: request.timestamp
|
||||||
}, proxySecret || privKey);
|
}, privKey);
|
||||||
console.debug(request);
|
console.debug(request);
|
||||||
|
|
||||||
fetch_api('/convert-to', {
|
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) => {
|
return new Promise((resolve, reject) => {
|
||||||
if (!floCrypto.verifyPrivKey(privKey, floID))
|
if (!floCrypto.verifyPrivKey(privKey, floID))
|
||||||
return reject(ExchangeError(ExchangeError.BAD_REQUEST_CODE, "Invalid Private Key", errorCode.INVALID_PRIVATE_KEY));
|
return reject(ExchangeError(ExchangeError.BAD_REQUEST_CODE, "Invalid Private Key", errorCode.INVALID_PRIVATE_KEY));
|
||||||
let btc_id = btcOperator.convert.legacy2bech(floID),
|
let btc_id = btcOperator.convert.legacy2bech(floID),
|
||||||
btc_sink = btcOperator.convert.legacy2bech(sinkID);
|
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 = {
|
let request = {
|
||||||
floID: floID,
|
floID: floID,
|
||||||
txid: btcOperator.transactionID(result.transaction),
|
txid: btcOperator.transactionID(result.transaction),
|
||||||
@ -1305,15 +1271,14 @@
|
|||||||
quantity: quantity,
|
quantity: quantity,
|
||||||
timestamp: Date.now()
|
timestamp: Date.now()
|
||||||
};
|
};
|
||||||
if (!proxySecret) //Direct signing (without proxy)
|
|
||||||
request.pubKey = floCrypto.getPubKeyHex(privKey);
|
request.pubKey = floCrypto.getPubKeyHex(privKey);
|
||||||
request.sign = signRequest({
|
request.sign = signRequest({
|
||||||
type: "convert_from",
|
type: "convert_from",
|
||||||
coin: request.coin,
|
coin: request.coin,
|
||||||
quantity: quantity,
|
quantity: quantity,
|
||||||
txid: data.txid,
|
txid: request.txid,
|
||||||
timestamp: request.timestamp
|
timestamp: request.timestamp
|
||||||
}, proxySecret || privKey);
|
}, privKey);
|
||||||
console.debug(request);
|
console.debug(request);
|
||||||
|
|
||||||
fetch_api('/convert-from', {
|
fetch_api('/convert-from', {
|
||||||
@ -1344,6 +1309,7 @@
|
|||||||
coin: "BTC",
|
coin: "BTC",
|
||||||
timestamp: Date.now()
|
timestamp: Date.now()
|
||||||
};
|
};
|
||||||
|
request.pubKey = floCrypto.getPubKeyHex(privKey);
|
||||||
request.sign = signRequest({
|
request.sign = signRequest({
|
||||||
type: "deposit_convert_currency_fund",
|
type: "deposit_convert_currency_fund",
|
||||||
coin: request.coin,
|
coin: request.coin,
|
||||||
@ -1382,12 +1348,13 @@
|
|||||||
coin: "BTC",
|
coin: "BTC",
|
||||||
timestamp: Date.now()
|
timestamp: Date.now()
|
||||||
};
|
};
|
||||||
|
request.pubKey = floCrypto.getPubKeyHex(privKey);
|
||||||
request.sign = signRequest({
|
request.sign = signRequest({
|
||||||
type: "deposit_convert_coin_fund",
|
type: "deposit_convert_coin_fund",
|
||||||
coin: request.coin,
|
coin: request.coin,
|
||||||
txid: data.txid,
|
txid: data.txid,
|
||||||
timestamp: request.timestamp
|
timestamp: request.timestamp
|
||||||
}, proxySecret || privKey);
|
}, privKey);
|
||||||
console.debug(request);
|
console.debug(request);
|
||||||
|
|
||||||
fetch_api('/deposit-convert-coin-fund', {
|
fetch_api('/deposit-convert-coin-fund', {
|
||||||
@ -1417,6 +1384,7 @@
|
|||||||
coin: "BTC",
|
coin: "BTC",
|
||||||
timestamp: Date.now()
|
timestamp: Date.now()
|
||||||
};
|
};
|
||||||
|
request.pubKey = floCrypto.getPubKeyHex(privKey);
|
||||||
request.sign = signRequest({
|
request.sign = signRequest({
|
||||||
type: "withdraw_convert_currency_fund",
|
type: "withdraw_convert_currency_fund",
|
||||||
coin: request.coin,
|
coin: request.coin,
|
||||||
@ -1451,6 +1419,7 @@
|
|||||||
coin: "BTC",
|
coin: "BTC",
|
||||||
timestamp: Date.now()
|
timestamp: Date.now()
|
||||||
};
|
};
|
||||||
|
request.pubKey = floCrypto.getPubKeyHex(privKey);
|
||||||
request.sign = signRequest({
|
request.sign = signRequest({
|
||||||
type: "withdraw_convert_coin_fund",
|
type: "withdraw_convert_coin_fund",
|
||||||
coin: request.coin,
|
coin: request.coin,
|
||||||
|
|||||||
@ -5,6 +5,7 @@ require('../docs/scripts/lib');
|
|||||||
global.floCrypto = require('../docs/scripts/floCrypto');
|
global.floCrypto = require('../docs/scripts/floCrypto');
|
||||||
global.floBlockchainAPI = require('../docs/scripts/floBlockchainAPI');
|
global.floBlockchainAPI = require('../docs/scripts/floBlockchainAPI');
|
||||||
global.floTokenAPI = require('../docs/scripts/floTokenAPI');
|
global.floTokenAPI = require('../docs/scripts/floTokenAPI');
|
||||||
|
global.btcOperator = require('../docs/scripts/btcOperator');
|
||||||
|
|
||||||
const Database = require("./database");
|
const Database = require("./database");
|
||||||
const App = require('./app');
|
const App = require('./app');
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user