started to add code for multi currency support, fixed async await loop in sync
This commit is contained in:
parent
3d99c9a73e
commit
bb7d29aa71
@ -63,23 +63,23 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<h5>Buy--Sell</h5>
|
<h5>Buy--Sell</h5>
|
||||||
<div class="box tradebox">
|
<div class="box tradebox" id="tradebox">
|
||||||
<div class="buybox">
|
<!-- <div class="buybox">
|
||||||
<strong>Buy BTC</strong>
|
<strong>Buy BTC</strong>
|
||||||
<ul class="panel-box trade_amount_box" id="buyul">
|
<ul class="panel-box trade_amount_box" id="buyul">
|
||||||
<li>INR 10000</li>
|
<li>CASH 10000</li>
|
||||||
<li>INR 50000</li>
|
<li>CASH 50000</li>
|
||||||
<li>INR 100000</li>
|
<li>CASH 100000</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
<div class="sellbox">
|
<div class="sellbox">
|
||||||
<strong>Sell BTC</strong>
|
<strong>Sell BTC</strong>
|
||||||
<ul class="panel-box trade_amount_box" id="sellul">
|
<ul class="panel-box trade_amount_box" id="sellul">
|
||||||
<li>INR 10000</li>
|
<li>CASH 10000</li>
|
||||||
<li>INR 50000</li>
|
<li>CASH 50000</li>
|
||||||
<li>INR 100000</li>
|
<li>CASH 100000</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div> -->
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="output_div"></div>
|
<div id="output_div"></div>
|
||||||
@ -9100,7 +9100,7 @@
|
|||||||
// remove this line later
|
// remove this line later
|
||||||
// btcTradeMargin is tolerable difference between BTC trader should deposit and BTC he actually deposited
|
// btcTradeMargin is tolerable difference between BTC trader should deposit and BTC he actually deposited
|
||||||
RMAssets =
|
RMAssets =
|
||||||
`validAssets=BTC,INR#!#supernodes=127.0.0.1,212.88.88.2#!#MASTER_NODE=023B9F60692A17FAC805D012C5C8ADA3DD19A980A3C5F0D8A5B3500CC54D6E8B75
|
`tradableAsset1=BTC,FLO#!#tradableAsset2=INR,USD,BTC,FLO#!#supernodes=127.0.0.1,212.88.88.2#!#MASTER_NODE=023B9F60692A17FAC805D012C5C8ADA3DD19A980A3C5F0D8A5B3500CC54D6E8B75
|
||||||
#!#MASTER_RECEIVING_ADDRESS=oVRq2nka1GtALQT8pbuLHAGjqAQ7PAo6uy#!#validTradingAmount=10000,50000,100000#!#btcTradeMargin=5000
|
#!#MASTER_RECEIVING_ADDRESS=oVRq2nka1GtALQT8pbuLHAGjqAQ7PAo6uy#!#validTradingAmount=10000,50000,100000#!#btcTradeMargin=5000
|
||||||
#!#supernodesPubKeys=029FDA7EA817F7A035F81C8A6B35AA53649690DF741E13C0B3DB99B06360F14385,#!#d3js=58f54395efa8346e8e94d12609770f66b916897e7f4e05f6c98780cffa5c70a3`;
|
#!#supernodesPubKeys=029FDA7EA817F7A035F81C8A6B35AA53649690DF741E13C0B3DB99B06360F14385,#!#d3js=58f54395efa8346e8e94d12609770f66b916897e7f4e05f6c98780cffa5c70a3`;
|
||||||
let floAssetsArray = RMAssets.split('#!#');
|
let floAssetsArray = RMAssets.split('#!#');
|
||||||
@ -9584,7 +9584,7 @@
|
|||||||
supernode_signed_res);
|
supernode_signed_res);
|
||||||
doSend(buy_request_response);
|
doSend(buy_request_response);
|
||||||
// Init trading
|
// Init trading
|
||||||
localbitcoinplusplus.trade.prototype.createTradePipes();
|
localbitcoinplusplus.trade.prototype.createTradePipes(request.params.currency);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -9606,7 +9606,7 @@
|
|||||||
supernode_signed_res);
|
supernode_signed_res);
|
||||||
doSend(sell_request_response);
|
doSend(sell_request_response);
|
||||||
// Init trading
|
// Init trading
|
||||||
localbitcoinplusplus.trade.prototype.createTradePipes();
|
localbitcoinplusplus.trade.prototype.createTradePipes(request.params.currency);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -9637,14 +9637,15 @@
|
|||||||
if (is_valid_request !== true) return false;
|
if (is_valid_request !== true) return false;
|
||||||
|
|
||||||
// This code will only run for supernodes
|
// This code will only run for supernodes
|
||||||
if (typeof params.product !== "undefined" && localbitcoinplusplus.master_configurations
|
if (typeof params.product !== "undefined"
|
||||||
.validAssets.includes(params.product) &&
|
&& (localbitcoinplusplus.master_configurations.tradableAsset1.includes(params.product)
|
||||||
typeof params.depositing_amount !== "undefined" && typeof localbitcoinplusplus
|
|| localbitcoinplusplus.master_configurations.tradableAsset2.includes(params.product))
|
||||||
.master_configurations.validTradingAmount !== 'undefined' &&
|
&& typeof params.depositing_amount !== "undefined"
|
||||||
localbitcoinplusplus.master_configurations.validTradingAmount.includes(
|
&& localbitcoinplusplus.master_configurations.tradableAsset2.includes(params.currency)
|
||||||
parseFloat(params.depositing_amount)) &&
|
&& typeof localbitcoinplusplus.master_configurations.validTradingAmount !== 'undefined'
|
||||||
typeof params.trader_flo_address ==
|
&& localbitcoinplusplus.master_configurations.validTradingAmount.includes(parseFloat(params.depositing_amount))
|
||||||
"string" && params.trader_flo_address.length > 0
|
&& typeof params.trader_flo_address == "string"
|
||||||
|
&& params.trader_flo_address.length > 0
|
||||||
) {
|
) {
|
||||||
localbitcoinplusplus.wallets.prototype.getUserPublicKey(params.trader_flo_address,
|
localbitcoinplusplus.wallets.prototype.getUserPublicKey(params.trader_flo_address,
|
||||||
function(requester_public_key) {
|
function(requester_public_key) {
|
||||||
@ -9669,10 +9670,10 @@
|
|||||||
params.btc_address = generate_btc_keys_for_requester.address;
|
params.btc_address = generate_btc_keys_for_requester.address;
|
||||||
|
|
||||||
/***************************************************
|
/***************************************************
|
||||||
GET EQUIVALENT BTC HERE IN TERMS OF ORDERED INR I.E 10K, 50K...
|
GET EQUIVALENT BTC HERE IN TERMS OF ORDERED CASH I.E 10K, 50K...
|
||||||
******************************************************/
|
******************************************************/
|
||||||
params.bitcoinToBePaid = localbitcoinplusplus.trade.prototype.calculateBTCEquivalentOfCash(
|
params.bitcoinToBePaid = localbitcoinplusplus.trade.prototype.calculateBTCEquivalentOfCash(
|
||||||
params.depositing_amount);
|
params.depositing_amount, params.currency);
|
||||||
|
|
||||||
let receivedTradeInfo = {...params};
|
let receivedTradeInfo = {...params};
|
||||||
|
|
||||||
@ -9729,12 +9730,11 @@
|
|||||||
return chunk_array;
|
return chunk_array;
|
||||||
});
|
});
|
||||||
|
|
||||||
// Send chunks of privat keys to other supernodes
|
// Send chunks of private keys to other supernodes
|
||||||
this_btc_pvt_key_shamirs_secret_array.map(shares=>{
|
this_btc_pvt_key_shamirs_secret_array.map(shares=>{
|
||||||
let store_pvtkey_req = localbitcoinplusplus.rpc.prototype
|
let store_pvtkey_req = localbitcoinplusplus.rpc.prototype
|
||||||
.send_rpc
|
.send_rpc
|
||||||
.call(this, "store_shamirs_secret_pvtkey_shares",
|
.call(this, "store_shamirs_secret_pvtkey_shares", shares);
|
||||||
shares);
|
|
||||||
doSend(store_pvtkey_req);
|
doSend(store_pvtkey_req);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@ -9786,7 +9786,7 @@
|
|||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
} else if (params.product == "INR") {
|
} else if (!localbitcoinplusplus.master_configurations.tradableAsset1.includes(params.product)) {
|
||||||
params.id = helper_functions.unique_id();
|
params.id = helper_functions.unique_id();
|
||||||
params.status = 1;
|
params.status = 1;
|
||||||
let receivedTradeInfo = { ...params };
|
let receivedTradeInfo = { ...params };
|
||||||
@ -9797,17 +9797,13 @@
|
|||||||
su_data.myLocalFLOPublicKey.length > 0 &&
|
su_data.myLocalFLOPublicKey.length > 0 &&
|
||||||
localbitcoinplusplus.master_configurations.supernodesPubKeys
|
localbitcoinplusplus.master_configurations.supernodesPubKeys
|
||||||
.includes(su_data.myLocalFLOPublicKey)) {
|
.includes(su_data.myLocalFLOPublicKey)) {
|
||||||
let receivedTradeInfoHash = Crypto.SHA256(JSON.stringify(
|
let receivedTradeInfoHash = Crypto.SHA256(JSON.stringify(receivedTradeInfo));
|
||||||
receivedTradeInfo));
|
|
||||||
|
|
||||||
receivedTradeInfo["depositDataHash"] =
|
receivedTradeInfo["depositDataHash"] = receivedTradeInfoHash;
|
||||||
receivedTradeInfoHash;
|
receivedTradeInfo["order_validator_sign"] = localbitcoinplusplus.wallets.prototype.sign(
|
||||||
receivedTradeInfo["order_validator_sign"] =
|
receivedTradeInfoHash, localbitcoinplusplus.wallets.MY_SUPERNODE_PRIVATE_KEY
|
||||||
localbitcoinplusplus.wallets.prototype.sign(
|
);
|
||||||
receivedTradeInfoHash, localbitcoinplusplus.wallets.MY_SUPERNODE_PRIVATE_KEY
|
receivedTradeInfo["order_validator_public_key"] = su_data.myLocalFLOPublicKey;
|
||||||
);
|
|
||||||
receivedTradeInfo["order_validator_public_key"] =
|
|
||||||
su_data.myLocalFLOPublicKey;
|
|
||||||
|
|
||||||
// YOU NEED TO DETERMINE A BANK ACCOUNT HERE IF NO ONE IS WITHDRAWING
|
// YOU NEED TO DETERMINE A BANK ACCOUNT HERE IF NO ONE IS WITHDRAWING
|
||||||
try {
|
try {
|
||||||
@ -9815,16 +9811,13 @@
|
|||||||
readDBbyIndex("withdraw_cash", "status", 1).then(
|
readDBbyIndex("withdraw_cash", "status", 1).then(
|
||||||
function (
|
function (
|
||||||
withdrawers_list) {
|
withdrawers_list) {
|
||||||
if (typeof withdrawers_list ==
|
if (typeof withdrawers_list == "object") {
|
||||||
"object") {
|
|
||||||
if (withdrawers_list.length > 0) {
|
if (withdrawers_list.length > 0) {
|
||||||
withdrawers_list.map(
|
withdrawers_list.filter(wd=>wd.product == params.currency).map(
|
||||||
function (
|
function (withdrawer) {
|
||||||
withdrawer) {
|
if (withdrawer.withdraw_amount == params.depositing_amount
|
||||||
if (withdrawer.withdraw_amount ==
|
&& withdrawer.product == params.currency
|
||||||
params.depositing_amount
|
|
||||||
) {
|
) {
|
||||||
|
|
||||||
withdrawer.status = 2; // A depositor has been asked to deposit money
|
withdrawer.status = 2; // A depositor has been asked to deposit money
|
||||||
withdrawer.depositor_found_at = + new Date();
|
withdrawer.depositor_found_at = + new Date();
|
||||||
withdrawer.depositor_flo_id = receivedTradeInfo.trader_flo_address;
|
withdrawer.depositor_flo_id = receivedTradeInfo.trader_flo_address;
|
||||||
@ -9856,12 +9849,7 @@
|
|||||||
doSend(deposit_request_response);
|
doSend(deposit_request_response);
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
// Return error to the requester
|
console.warning("Deposit request failed: We could not find a withdrawer.");
|
||||||
// return {
|
|
||||||
// error: true,
|
|
||||||
// method: "deposit_asset_request_response",
|
|
||||||
// data: "Deposit request failed: We could not find a withdrawer."
|
|
||||||
// };
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
@ -9889,13 +9877,8 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
console.error("Deposit request failed: We could not find a withdrawer. Come again later.");
|
||||||
throw new Error(error);
|
throw new Error(error);
|
||||||
|
|
||||||
// return {
|
|
||||||
// error: true,
|
|
||||||
// method: "deposit_asset_request_response",
|
|
||||||
// data: "Deposit request failed: We could not find a withdrawer. Come again later."
|
|
||||||
// };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -9914,8 +9897,9 @@
|
|||||||
|
|
||||||
if (is_valid_request !== true) return false;
|
if (is_valid_request !== true) return false;
|
||||||
|
|
||||||
if (typeof params.product !== "undefined" &&
|
if (typeof params.product !== "undefined"
|
||||||
localbitcoinplusplus.master_configurations.validAssets.includes(params.product) &&
|
&& (localbitcoinplusplus.master_configurations.tradableAsset1.include(params.product)
|
||||||
|
|| localbitcoinplusplus.master_configurations.tradableAsset2.includes(params.product)) &&
|
||||||
typeof params.withdrawing_amount !== "undefined" &&
|
typeof params.withdrawing_amount !== "undefined" &&
|
||||||
typeof localbitcoinplusplus.master_configurations.validTradingAmount !==
|
typeof localbitcoinplusplus.master_configurations.validTradingAmount !==
|
||||||
'undefined' &&
|
'undefined' &&
|
||||||
@ -9924,7 +9908,7 @@
|
|||||||
typeof params.trader_flo_address == "string" && params.trader_flo_address
|
typeof params.trader_flo_address == "string" && params.trader_flo_address
|
||||||
.length > 0 &&
|
.length > 0 &&
|
||||||
typeof params.receivinAddress == "string" && params.receivinAddress.length >
|
typeof params.receivinAddress == "string" && params.receivinAddress.length >
|
||||||
0
|
0 && typeof params.currency !== "undefined"
|
||||||
) {
|
) {
|
||||||
params.id = helper_functions.unique_id();
|
params.id = helper_functions.unique_id();
|
||||||
params.status = 1;
|
params.status = 1;
|
||||||
@ -9938,8 +9922,11 @@
|
|||||||
btc_balance_res.btc_balance > 0) {
|
btc_balance_res.btc_balance > 0) {
|
||||||
let withdrawer_btc_balance = parseFloat(btc_balance_res.btc_balance);
|
let withdrawer_btc_balance = parseFloat(btc_balance_res.btc_balance);
|
||||||
let withdrawing_btc_amount_in_cash = parseFloat(params.withdrawing_amount);
|
let withdrawing_btc_amount_in_cash = parseFloat(params.withdrawing_amount);
|
||||||
|
if(!localbitcoinplusplus.master_configurations.tradableAsset2.includes(params.currency)) {
|
||||||
|
params.currency = "USD";
|
||||||
|
}
|
||||||
let eqBTC = localbitcoinplusplus.trade.prototype.calculateBTCEquivalentOfCash(
|
let eqBTC = localbitcoinplusplus.trade.prototype.calculateBTCEquivalentOfCash(
|
||||||
withdrawing_btc_amount_in_cash);
|
withdrawing_btc_amount_in_cash, params.currency);
|
||||||
eqBTC = parseFloat(eqBTC).toFixed(8);
|
eqBTC = parseFloat(eqBTC).toFixed(8);
|
||||||
let withdrawer_new_btc_balance = withdrawer_btc_balance - eqBTC;
|
let withdrawer_new_btc_balance = withdrawer_btc_balance - eqBTC;
|
||||||
if (withdrawer_btc_balance > 0 &&
|
if (withdrawer_btc_balance > 0 &&
|
||||||
@ -10033,7 +10020,7 @@
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else if (params.product == "INR") {
|
} else if (!localbitcoinplusplus.master_configurations.tradableAsset1.includes(params.product)) {
|
||||||
// Check if there's no already a withdraw cash order of this user
|
// Check if there's no already a withdraw cash order of this user
|
||||||
/*ONLY DELETE A WITHDRAW ORDER WHEN A DEPOSITOR HAS CONFIRMED DEPOSIT
|
/*ONLY DELETE A WITHDRAW ORDER WHEN A DEPOSITOR HAS CONFIRMED DEPOSIT
|
||||||
AND RECEIVER HAS CONFIRMED WITHDRAW*/
|
AND RECEIVER HAS CONFIRMED WITHDRAW*/
|
||||||
@ -10111,23 +10098,13 @@
|
|||||||
return true;
|
return true;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
|
|
||||||
// return {
|
|
||||||
// error: true,
|
|
||||||
// method: "withdrawal_request_response",
|
|
||||||
// data: "Withdrawal request failed: "+error
|
|
||||||
// };
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// Return error to the requester
|
// Return error to the requester
|
||||||
// return {
|
console.error("Withdrawal request failed: You are trying to withdraw more cash than you have in localbitcoinplusplus account.");
|
||||||
// error: true,
|
|
||||||
// method: "withdrawal_request_response",
|
|
||||||
// data: "Withdrawal request failed: You are trying to withdraw more cash than you have in localbitcoinplusplus account."
|
|
||||||
// };
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -10160,7 +10137,8 @@
|
|||||||
let transaction_key = btc_reserves.supernode_transaction_key;
|
let transaction_key = btc_reserves.supernode_transaction_key;
|
||||||
if (transaction_key.length>0) {
|
if (transaction_key.length>0) {
|
||||||
let btc_private_key = localbitcoinplusplus.wallets.prototype.rebuild_private_key(btc_pk_shares_array, transaction_key);
|
let btc_private_key = localbitcoinplusplus.wallets.prototype.rebuild_private_key(btc_pk_shares_array, transaction_key);
|
||||||
localbitcoinplusplus.trade.prototype.sendTransaction(withdraw_res.utxo_addr, btc_private_key, withdraw_res.receiverBTCAddress, withdraw_res.receiverBTCEquivalentInCash, withdraw_res.change_adress, function(res) {
|
localbitcoinplusplus.trade.prototype.sendTransaction(withdraw_res.utxo_addr, btc_private_key, withdraw_res.receiverBTCAddress,
|
||||||
|
withdraw_res.receiverBTCEquivalentInCash, withdraw_res.currency, withdraw_res.change_adress, function(res) {
|
||||||
console.log(res);
|
console.log(res);
|
||||||
if (typeof res == "string" && res.length>0) {
|
if (typeof res == "string" && res.length>0) {
|
||||||
try {
|
try {
|
||||||
@ -10183,7 +10161,7 @@
|
|||||||
|
|
||||||
readDBbyIndex('deposit', 'btc_address', withdraw_res.utxo_addr).then(function(deposit_arr) {
|
readDBbyIndex('deposit', 'btc_address', withdraw_res.utxo_addr).then(function(deposit_arr) {
|
||||||
if (typeof deposit_arr=="object") {
|
if (typeof deposit_arr=="object") {
|
||||||
let eqBTC = localbitcoinplusplus.trade.prototype.calculateBTCEquivalentOfCash(withdraw_res.receiverBTCEquivalentInCash);
|
let eqBTC = localbitcoinplusplus.trade.prototype.calculateBTCEquivalentOfCash(withdraw_res.receiverBTCEquivalentInCash, withdraw_res.currency);
|
||||||
eqBTC = parseFloat(eqBTC);
|
eqBTC = parseFloat(eqBTC);
|
||||||
deposit_arr.bitcoinToBePaid -= eqBTC;
|
deposit_arr.bitcoinToBePaid -= eqBTC;
|
||||||
|
|
||||||
@ -10283,18 +10261,28 @@
|
|||||||
this.rpc_job = null;
|
this.rpc_job = null;
|
||||||
this.floAddress = null;
|
this.floAddress = null;
|
||||||
this.user_flo_address = null;
|
this.user_flo_address = null;
|
||||||
this.sorted_trade_list = [];
|
this.sorted_trade_list = [];
|
||||||
|
const DEFAULT_FIAT_CURRENCY = "USD";
|
||||||
|
|
||||||
|
Object.defineProperty(localbitcoinplusplus.trade, 'user_preffered_currency', {
|
||||||
|
get: function() {
|
||||||
|
return typeof localbitcoinplusplus.wallets.my_preferred_trade_currency !== "undefined"
|
||||||
|
? localbitcoinplusplus.wallets.my_preferred_trade_currency:DEFAULT_FIAT_CURRENCY;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Trade.prototype = {
|
Trade.prototype = {
|
||||||
get trustLevel() {
|
|
||||||
return this.level;
|
getTrustLevel(){return this.level},
|
||||||
},
|
|
||||||
set trustLevel(level) {
|
setTrustLevel(level) {
|
||||||
if (typeof level === "number" && level === parseInt(level, 10) && level > 0 && level < 6) {
|
if (typeof level === "number" && level === parseInt(level, 10) && level > 0 && level < 6) {
|
||||||
this.level = level;
|
this.level = level;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
validate_order(order_type, user_flo_address, product, currency, buy_price) {
|
validate_order(order_type, user_flo_address, product, currency, buy_price) {
|
||||||
|
|
||||||
if (this.valid_order_type.indexOf(order_type) >= 0) {
|
if (this.valid_order_type.indexOf(order_type) >= 0) {
|
||||||
@ -10307,19 +10295,19 @@
|
|||||||
} else {
|
} else {
|
||||||
this.errors.push("No receiving BTC or Bank address provided.");
|
this.errors.push("No receiving BTC or Bank address provided.");
|
||||||
}
|
}
|
||||||
if (typeof localbitcoinplusplus.master_configurations.validAssets !== 'undefined' &&
|
if (typeof localbitcoinplusplus.master_configurations.tradableAsset1 !== 'undefined' &&
|
||||||
localbitcoinplusplus.master_configurations.validAssets.indexOf(product) >= 0) {
|
localbitcoinplusplus.master_configurations.tradableAsset1.indexOf(product) >= 0) {
|
||||||
this.product = product;
|
this.product = product;
|
||||||
} else {
|
} else {
|
||||||
this.errors.push("Invalid product.");
|
this.errors.push("Invalid trading product.");
|
||||||
}
|
}
|
||||||
if (typeof localbitcoinplusplus.master_configurations.validAssets !== 'undefined' &&
|
if (typeof localbitcoinplusplus.master_configurations.tradableAsset2 !== 'undefined' &&
|
||||||
localbitcoinplusplus.master_configurations.validAssets.indexOf(currency) >= 0) {
|
localbitcoinplusplus.master_configurations.tradableAsset2.indexOf(currency) >= 0) {
|
||||||
this.currency = currency;
|
this.currency = currency;
|
||||||
} else {
|
} else {
|
||||||
this.errors.push("Invalid product.");
|
this.errors.push("Invalid exchanging currency or asset.");
|
||||||
}
|
}
|
||||||
if (typeof buy_price == "number" && buy_price > 0) {
|
if (localbitcoinplusplus.master_configurations.validTradingAmount.includes(buy_price)) {
|
||||||
this.buy_price = buy_price;
|
this.buy_price = buy_price;
|
||||||
} else {
|
} else {
|
||||||
this.errors.push("Invalid buying price. Please place a valid buy amount.");
|
this.errors.push("Invalid buying price. Please place a valid buy amount.");
|
||||||
@ -10366,11 +10354,13 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (params.order_type != "buy" || params.product != "BTC" || params.currency != "INR") {
|
if (params.order_type != "buy" || !localbitcoinplusplus.master_configurations.tradableAsset1.includes(params.product)
|
||||||
|
|| !localbitcoinplusplus.master_configurations.tradableAsset2.includes(params.currency)
|
||||||
|
|| params.currency==params.product) {
|
||||||
throw new Error("Invalid buy request.");
|
throw new Error("Invalid buy request.");
|
||||||
}
|
}
|
||||||
|
|
||||||
//Check buyer's INR balance
|
//Check buyer's fiat balance
|
||||||
readDB("cash_balances", params.trader_flo_address).then(function (res) {
|
readDB("cash_balances", params.trader_flo_address).then(function (res) {
|
||||||
if (typeof res !== "undefined" && typeof res.cash_balance == "number" && !isNaN(res.cash_balance)) {
|
if (typeof res !== "undefined" && typeof res.cash_balance == "number" && !isNaN(res.cash_balance)) {
|
||||||
let buyer_cash_balance = parseFloat(res.cash_balance);
|
let buyer_cash_balance = parseFloat(res.cash_balance);
|
||||||
@ -10379,8 +10369,7 @@
|
|||||||
throw new Error("Insufficient balance.");
|
throw new Error("Insufficient balance.");
|
||||||
}
|
}
|
||||||
// calculate equivalent BTC for x amount of Cash
|
// calculate equivalent BTC for x amount of Cash
|
||||||
let eqBTC = localbitcoinplusplus.trade.prototype.calculateBTCEquivalentOfCash(
|
let eqBTC = localbitcoinplusplus.trade.prototype.calculateBTCEquivalentOfCash(buy_price_btc, params.currency);
|
||||||
buy_price_btc);
|
|
||||||
eqBTC = parseFloat(eqBTC);
|
eqBTC = parseFloat(eqBTC);
|
||||||
if (typeof eqBTC == "number" && eqBTC > 0) {
|
if (typeof eqBTC == "number" && eqBTC > 0) {
|
||||||
|
|
||||||
@ -10430,8 +10419,10 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (params.order_type != "sell" || params.product != "BTC" || params.currency != "INR" &&
|
if (params.order_type != "sell"
|
||||||
localbitcoinplusplus.master_configurations.validTradingAmount.includes(params.buy_price)) {
|
|| !localbitcoinplusplus.master_configurations.tradableAsset1.includes(params.product)
|
||||||
|
|| !localbitcoinplusplus.master_configurations.tradableAsset2.includes(params.currency)
|
||||||
|
|| params.currency==params.product) {
|
||||||
throw new Error("Invalid sell request.");
|
throw new Error("Invalid sell request.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -10442,8 +10433,7 @@
|
|||||||
typeof res.btc_balance == "number" && res.btc_balance > 0) {
|
typeof res.btc_balance == "number" && res.btc_balance > 0) {
|
||||||
let seller_btc_balance = parseFloat(res.btc_balance);
|
let seller_btc_balance = parseFloat(res.btc_balance);
|
||||||
let sell_price_in_inr = parseFloat(params.buy_price);
|
let sell_price_in_inr = parseFloat(params.buy_price);
|
||||||
let eqBTC = localbitcoinplusplus.trade.prototype.calculateBTCEquivalentOfCash(
|
let eqBTC = localbitcoinplusplus.trade.prototype.calculateBTCEquivalentOfCash(sell_price_in_inr, params.currency);
|
||||||
sell_price_in_inr);
|
|
||||||
eqBTC = parseFloat(eqBTC);
|
eqBTC = parseFloat(eqBTC);
|
||||||
if (typeof eqBTC == "number" && eqBTC > 0) {
|
if (typeof eqBTC == "number" && eqBTC > 0) {
|
||||||
|
|
||||||
@ -10459,8 +10449,7 @@
|
|||||||
//Add cash balance
|
//Add cash balance
|
||||||
params['id'] = helper_functions.unique_id();
|
params['id'] = helper_functions.unique_id();
|
||||||
|
|
||||||
let hashed_data = Crypto.SHA256(JSON.stringify(
|
let hashed_data = Crypto.SHA256(JSON.stringify(params));
|
||||||
params));
|
|
||||||
// Signing of the data by Supernode
|
// Signing of the data by Supernode
|
||||||
let signed_data = localbitcoinplusplus.wallets.prototype
|
let signed_data = localbitcoinplusplus.wallets.prototype
|
||||||
.sign(hashed_data, localbitcoinplusplus.wallets.MY_SUPERNODE_PRIVATE_KEY);
|
.sign(hashed_data, localbitcoinplusplus.wallets.MY_SUPERNODE_PRIVATE_KEY);
|
||||||
@ -10485,18 +10474,21 @@
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
depositAsset(assetType, amount, userFLOaddress) {
|
depositAsset(assetType, amount, userFLOaddress) {
|
||||||
if (typeof localbitcoinplusplus.master_configurations.validAssets !== 'undefined' && !
|
if (typeof localbitcoinplusplus.master_configurations.tradableAsset1 == 'undefined' ||
|
||||||
localbitcoinplusplus.master_configurations.validAssets.includes(assetType)) {
|
typeof localbitcoinplusplus.master_configurations.tradableAsset2 == 'undefined' ||
|
||||||
|
(!localbitcoinplusplus.master_configurations.tradableAsset1.includes(assetType) &&
|
||||||
|
!localbitcoinplusplus.master_configurations.tradableAsset2.includes(assetType))) {
|
||||||
throw new Error("Invalid asset error");
|
throw new Error("Invalid asset error");
|
||||||
} else if (parseFloat(amount) <= 0) {
|
} else if (parseFloat(amount) <= 0) {
|
||||||
throw new Error("Invalid amount error.");
|
throw new Error("Invalid amount error.");
|
||||||
} else if (userFLOaddress.length < 0) {
|
} else if (userFLOaddress.length < 0) {
|
||||||
throw new Error("User address required.");
|
throw new Error("User address required.");
|
||||||
}
|
}
|
||||||
|
let currency = localbitcoinplusplus.trade.user_preffered_currency;
|
||||||
let deposit_request_object = {
|
let deposit_request_object = {
|
||||||
trader_flo_address: userFLOaddress,
|
trader_flo_address: userFLOaddress,
|
||||||
depositing_amount: amount,
|
depositing_amount: amount,
|
||||||
|
currency:currency,
|
||||||
depositor_key_signature: null,
|
depositor_key_signature: null,
|
||||||
depositor_public_key: null,
|
depositor_public_key: null,
|
||||||
operation_type: "deposit",
|
operation_type: "deposit",
|
||||||
@ -10509,8 +10501,10 @@
|
|||||||
doSend(deposit_request);
|
doSend(deposit_request);
|
||||||
},
|
},
|
||||||
withdrawAsset(assetType, amount, receivinAddress, userFLOaddress, callback) {
|
withdrawAsset(assetType, amount, receivinAddress, userFLOaddress, callback) {
|
||||||
if (typeof localbitcoinplusplus.master_configurations.validAssets !== 'undefined' && !
|
if (typeof localbitcoinplusplus.master_configurations.tradableAsset1 == 'undefined' ||
|
||||||
localbitcoinplusplus.master_configurations.validAssets.includes(assetType)) {
|
typeof localbitcoinplusplus.master_configurations.tradableAsset2 == 'undefined' ||
|
||||||
|
!localbitcoinplusplus.master_configurations.tradableAsset1.includes(assetType) ||
|
||||||
|
!localbitcoinplusplus.master_configurations.tradableAsset2.includes(assetType)) {
|
||||||
throw new Error("Invalid asset error");
|
throw new Error("Invalid asset error");
|
||||||
} else if (parseFloat(amount) <= 0) {
|
} else if (parseFloat(amount) <= 0) {
|
||||||
throw new Error("Invalid amount error.");
|
throw new Error("Invalid amount error.");
|
||||||
@ -10528,24 +10522,26 @@
|
|||||||
wihdrawer_public_key: null,
|
wihdrawer_public_key: null,
|
||||||
operation_type: "withdraw",
|
operation_type: "withdraw",
|
||||||
order_validator_public_key: null,
|
order_validator_public_key: null,
|
||||||
product: assetType
|
product: assetType,
|
||||||
|
currency: localbitcoinplusplus.wallets.my_preferred_trade_currency
|
||||||
}
|
}
|
||||||
|
|
||||||
let withdraw_request = localbitcoinplusplus.rpc.prototype.send_rpc.call(this,
|
let withdraw_request = localbitcoinplusplus.rpc.prototype.send_rpc.call(this,
|
||||||
"withdraw_request_method", withdraw_request_object);
|
"withdraw_request_method", withdraw_request_object);
|
||||||
doSend(withdraw_request);
|
doSend(withdraw_request);
|
||||||
},
|
},
|
||||||
calculateBTCEquivalentOfCash(btc_buy_price) {
|
calculateBTCEquivalentOfCash(btc_buy_price, currency="USD") {
|
||||||
if (localbitcoinplusplus.master_configurations.validTradingAmount.includes(btc_buy_price)) {
|
if (localbitcoinplusplus.master_configurations.validTradingAmount.includes(btc_buy_price)) {
|
||||||
let current_btc_price = localbitcoinplusplus.trade.prototype.get_current_btc_price_in_fiat.call();
|
if(!localbitcoinplusplus.master_configurations.tradableAsset2.includes(currency)) return false;
|
||||||
|
let current_btc_price = localbitcoinplusplus.trade.prototype.get_current_btc_price_in_fiat(currency);
|
||||||
if (current_btc_price > 0) {
|
if (current_btc_price > 0) {
|
||||||
return parseFloat(btc_buy_price / current_btc_price).toFixed(8);
|
return parseFloat(btc_buy_price / current_btc_price).toFixed(8);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
},
|
},
|
||||||
get_current_btc_price_in_fiat() {
|
get_current_btc_price_in_fiat(currency_code) {
|
||||||
return localbitcoinplusplus.trade.current_btc_price_in_cash;
|
return eval(`localbitcoinplusplus.trade.current_btc_price_in_${currency_code}`);
|
||||||
},
|
},
|
||||||
set_current_btc_price_in_fiat(currency_code) {
|
set_current_btc_price_in_fiat(currency_code) {
|
||||||
let url = `https://api.coindesk.com/v1/bpi/currentprice/${currency_code}.json`;
|
let url = `https://api.coindesk.com/v1/bpi/currentprice/${currency_code}.json`;
|
||||||
@ -10553,15 +10549,14 @@
|
|||||||
if (typeof res == "string" && res.length > 0) {
|
if (typeof res == "string" && res.length > 0) {
|
||||||
try {
|
try {
|
||||||
let res_object = JSON.parse(res);
|
let res_object = JSON.parse(res);
|
||||||
if (typeof res_object.bpi.INR.rate_float == "number") {
|
return Object.defineProperty(localbitcoinplusplus.trade,
|
||||||
return Object.defineProperty(localbitcoinplusplus.trade,
|
`current_btc_price_in_${currency_code}`, {
|
||||||
'current_btc_price_in_cash', {
|
value: {rate:eval(`res_object.bpi.${currency_code}.rate_float`),
|
||||||
value: parseFloat(res_object.bpi.INR.rate_float),
|
timestamp: + new Date()},
|
||||||
writable: false,
|
writable: false,
|
||||||
configurable: true,
|
configurable: true,
|
||||||
enumerable: true
|
enumerable: true
|
||||||
});
|
});
|
||||||
}
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
return false;
|
return false;
|
||||||
@ -10569,7 +10564,7 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
sendTransaction(utxo_addr, utxo_addr_wif, receiver_address, receiving_amount, change_adress, callback) {
|
sendTransaction(utxo_addr, utxo_addr_wif, receiver_address, receiving_amount, receiving_amount_currency="USD", change_adress, callback) {
|
||||||
let url = `${localbitcoinplusplus.flocha}/api/addr/${utxo_addr}/utxo`;
|
let url = `${localbitcoinplusplus.flocha}/api/addr/${utxo_addr}/utxo`;
|
||||||
helper_functions.ajaxGet(url, function (res) {
|
helper_functions.ajaxGet(url, function (res) {
|
||||||
|
|
||||||
@ -10578,10 +10573,10 @@
|
|||||||
if (!localbitcoinplusplus.master_configurations.validTradingAmount.includes(receiving_amount)) {
|
if (!localbitcoinplusplus.master_configurations.validTradingAmount.includes(receiving_amount)) {
|
||||||
throw new Error('Invalid amount');
|
throw new Error('Invalid amount');
|
||||||
}
|
}
|
||||||
let btc_eq_receiving_amount = localbitcoinplusplus.trade.prototype.calculateBTCEquivalentOfCash(receiving_amount);
|
let btc_eq_receiving_amount = localbitcoinplusplus.trade.prototype.calculateBTCEquivalentOfCash(receiving_amount, receiving_amount_currency);
|
||||||
btc_eq_receiving_amount = parseFloat(btc_eq_receiving_amount).toFixed(8);
|
btc_eq_receiving_amount = parseFloat(btc_eq_receiving_amount).toFixed(8);
|
||||||
let utxo_list = JSON.parse(res);
|
let utxo_list = JSON.parse(res);
|
||||||
var trx = bitjs.transaction();
|
let trx = bitjs.transaction();
|
||||||
let sum = 0;
|
let sum = 0;
|
||||||
|
|
||||||
for (var key in utxo_list) {
|
for (var key in utxo_list) {
|
||||||
@ -10638,12 +10633,14 @@
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
/*Finds the best buy sell id match for a trade*/
|
/*Finds the best buy sell id match for a trade*/
|
||||||
createTradePipes() {
|
createTradePipes(trading_currency="USD") {
|
||||||
try {
|
try {
|
||||||
readAllDB("sellOrders").then(function (sellOrdersList) {
|
readAllDB("sellOrders").then(function (sellOrdersList) {
|
||||||
if (sellOrdersList.length > 0) {
|
if (sellOrdersList.length > 0) {
|
||||||
|
sellOrdersList = sellOrdersList.filter(sellOrder=>sellOrder.currency==trading_currency);
|
||||||
readAllDB("buyOrders").then(function (buyOrdersList) {
|
readAllDB("buyOrders").then(function (buyOrdersList) {
|
||||||
if (buyOrdersList.length > 0) {
|
if (buyOrdersList.length > 0) {
|
||||||
|
buyOrdersList = buyOrdersList.filter(buyOrder=>buyOrder.currency==trading_currency);
|
||||||
localbitcoinplusplus.master_configurations.validTradingAmount.map(
|
localbitcoinplusplus.master_configurations.validTradingAmount.map(
|
||||||
li => {
|
li => {
|
||||||
eval(
|
eval(
|
||||||
@ -10670,8 +10667,7 @@
|
|||||||
localbitcoinplusplus.trade.prototype.launchTrade(
|
localbitcoinplusplus.trade.prototype.launchTrade(
|
||||||
buyPipe.value[i], sellPipe.value[i],
|
buyPipe.value[i], sellPipe.value[i],
|
||||||
function (supernode_res) {
|
function (supernode_res) {
|
||||||
if (typeof supernode_res ==
|
if (typeof supernode_res == "object") {
|
||||||
"object") {
|
|
||||||
let server_res =
|
let server_res =
|
||||||
localbitcoinplusplus.rpc
|
localbitcoinplusplus.rpc
|
||||||
.prototype.send_rpc.call(
|
.prototype.send_rpc.call(
|
||||||
@ -10694,9 +10690,8 @@
|
|||||||
},
|
},
|
||||||
launchTrade(buyPipeObj, sellPipeObj, callback) {
|
launchTrade(buyPipeObj, sellPipeObj, callback) {
|
||||||
if (buyPipeObj.order_type == "buy" && sellPipeObj.order_type == "sell" &&
|
if (buyPipeObj.order_type == "buy" && sellPipeObj.order_type == "sell" &&
|
||||||
buyPipeObj.buy_price == sellPipeObj.buy_price &&
|
|
||||||
buyPipeObj.buy_price == sellPipeObj.buy_price == 1 &&
|
|
||||||
buyPipeObj.buy_price == sellPipeObj.buy_price
|
buyPipeObj.buy_price == sellPipeObj.buy_price
|
||||||
|
&& buyPipeObj.currency == sellPipeObj.currency
|
||||||
) {
|
) {
|
||||||
// Check buyer's cash balance
|
// Check buyer's cash balance
|
||||||
readDB("cash_balances", buyPipeObj.trader_flo_address).then(function (buyPipeCashRes) {
|
readDB("cash_balances", buyPipeObj.trader_flo_address).then(function (buyPipeCashRes) {
|
||||||
@ -10708,8 +10703,7 @@
|
|||||||
throw new Error("Insufficient cash balance of buyer.");
|
throw new Error("Insufficient cash balance of buyer.");
|
||||||
}
|
}
|
||||||
// calculate equivalent BTC for x amount of Cash
|
// calculate equivalent BTC for x amount of Cash
|
||||||
let eqBTCBuyer = localbitcoinplusplus.trade.prototype.calculateBTCEquivalentOfCash(
|
let eqBTCBuyer = localbitcoinplusplus.trade.prototype.calculateBTCEquivalentOfCash(buy_price_btc, buyPipeObj.currency);
|
||||||
buy_price_btc);
|
|
||||||
|
|
||||||
if (!isNaN(eqBTCBuyer) && eqBTCBuyer != "" && eqBTCBuyer != undefined) {
|
if (!isNaN(eqBTCBuyer) && eqBTCBuyer != "" && eqBTCBuyer != undefined) {
|
||||||
eqBTCBuyer = parseFloat(eqBTCBuyer);
|
eqBTCBuyer = parseFloat(eqBTCBuyer);
|
||||||
@ -10723,7 +10717,7 @@
|
|||||||
.toFixed(8);
|
.toFixed(8);
|
||||||
let sell_price_in_inr = parseFloat(sellPipeObj.buy_price);
|
let sell_price_in_inr = parseFloat(sellPipeObj.buy_price);
|
||||||
let eqBTCSeller = localbitcoinplusplus.trade.prototype.calculateBTCEquivalentOfCash(
|
let eqBTCSeller = localbitcoinplusplus.trade.prototype.calculateBTCEquivalentOfCash(
|
||||||
sell_price_in_inr);
|
sell_price_in_inr, buy_price_btc.currency);
|
||||||
if (!isNaN(eqBTCSeller) && eqBTCSeller != "" && eqBTCSeller !=
|
if (!isNaN(eqBTCSeller) && eqBTCSeller != "" && eqBTCSeller !=
|
||||||
undefined) {
|
undefined) {
|
||||||
eqBTCSeller = parseFloat(eqBTCSeller);
|
eqBTCSeller = parseFloat(eqBTCSeller);
|
||||||
@ -11278,26 +11272,37 @@
|
|||||||
if (typeof localbitcoinplusplus.wallets.my_local_flo_address!=="string"
|
if (typeof localbitcoinplusplus.wallets.my_local_flo_address!=="string"
|
||||||
|| su_db_data.trader_flo_address !== localbitcoinplusplus.wallets.my_local_flo_address) return false;
|
|| su_db_data.trader_flo_address !== localbitcoinplusplus.wallets.my_local_flo_address) return false;
|
||||||
|
|
||||||
for (var tableStoreName in su_db_data) {
|
(async function() {
|
||||||
// skip loop if the property is from prototype
|
for (let tableStoreName in su_db_data) {
|
||||||
if (tableStoreName=='trader_flo_address' || !su_db_data.hasOwnProperty(tableStoreName)) continue;
|
// skip loop if the property is from prototype
|
||||||
|
if (tableStoreName=='trader_flo_address' || !su_db_data.hasOwnProperty(tableStoreName)) continue;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
removeAllinDB(tableStoreName).then(function(res) {
|
let obj = su_db_data[tableStoreName];
|
||||||
if (res!==false) {
|
if (["btc_balances", "cash_balances", "userPublicData"].includes(tableStoreName)) {
|
||||||
var obj = su_db_data[res];
|
|
||||||
if (obj.length>0) {
|
if (obj.length>0) {
|
||||||
for (var prop in obj) {
|
for (var prop in obj) {
|
||||||
if(!obj.hasOwnProperty(prop)) continue;
|
if(!obj.hasOwnProperty(prop)) continue;
|
||||||
addDB(res, obj[prop]);
|
await updateinDB(tableStoreName, obj[prop], obj[prop].trader_flo_address);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
let resdbdata = await removeAllinDB(tableStoreName);
|
||||||
|
if (resdbdata!==false) {
|
||||||
|
if (obj.length>0) {
|
||||||
|
for (var prop in obj) {
|
||||||
|
if(!obj.hasOwnProperty(prop)) continue;
|
||||||
|
await addDB(resdbdata, obj[prop]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
})()
|
||||||
|
|
||||||
// Pass data to build_deposit_withdraw_table function
|
// Pass data to build_deposit_withdraw_table function
|
||||||
try {
|
try {
|
||||||
@ -11505,7 +11510,7 @@
|
|||||||
readDBbyIndex('cash_balances', 'trader_flo_address', withdraw_data.depositor_flo_id).then(function(depositor_cash_data) {
|
readDBbyIndex('cash_balances', 'trader_flo_address', withdraw_data.depositor_flo_id).then(function(depositor_cash_data) {
|
||||||
if (typeof depositor_cash_data=="object") {
|
if (typeof depositor_cash_data=="object") {
|
||||||
if (depositor_cash_data.length==0) {
|
if (depositor_cash_data.length==0) {
|
||||||
depositor_cash_data = {cash_balance:0, trader_flo_address:withdraw_data.depositor_flo_id};
|
depositor_cash_data = {cash_balance:0, trader_flo_address:withdraw_data.depositor_flo_id, currency:localbitcoinplusplus.trade.user_preffered_currency};
|
||||||
addDB('cash_balances', depositor_cash_data);
|
addDB('cash_balances', depositor_cash_data);
|
||||||
}
|
}
|
||||||
depositor_cash_data.cash_balance += parseFloat(withdraw_data.withdraw_amount);
|
depositor_cash_data.cash_balance += parseFloat(withdraw_data.withdraw_amount);
|
||||||
@ -11589,9 +11594,9 @@
|
|||||||
if (typeof res_obj.params == "object" && typeof res_obj.params[0] == "object") {
|
if (typeof res_obj.params == "object" && typeof res_obj.params[0] == "object") {
|
||||||
let req_data = res_obj.params[0].public_data;
|
let req_data = res_obj.params[0].public_data;
|
||||||
try {
|
try {
|
||||||
//let flo_address = localbitcoinplusplus.publicKey.getBitcoinAddressFromByteArray(req_data.trader_flo_pubKey);
|
let flo_address = bitjs.pubkey2address(req_data.trader_flo_pubKey);
|
||||||
|
|
||||||
if (req_data.trader_flo_address.length) {
|
if (flo_address==req_data.trader_flo_address && req_data.trader_flo_address.length>0) {
|
||||||
|
|
||||||
let public_req_object = {
|
let public_req_object = {
|
||||||
trader_flo_address: req_data.trader_flo_address,
|
trader_flo_address: req_data.trader_flo_address,
|
||||||
@ -11713,7 +11718,8 @@
|
|||||||
id: "00-01",
|
id: "00-01",
|
||||||
myLocalFLOAddress: "",
|
myLocalFLOAddress: "",
|
||||||
myLocalFLOPublicKey: "",
|
myLocalFLOPublicKey: "",
|
||||||
myAddressTrustLevel: 1
|
myAddressTrustLevel: 1,
|
||||||
|
preferredTradeCurrency: "USD"
|
||||||
};
|
};
|
||||||
|
|
||||||
const userPublicData = {
|
const userPublicData = {
|
||||||
@ -11739,6 +11745,7 @@
|
|||||||
id: "",
|
id: "",
|
||||||
trader_flo_address: null,
|
trader_flo_address: null,
|
||||||
withdraw_amount: null,
|
withdraw_amount: null,
|
||||||
|
currency: null,
|
||||||
receivinAddress: null,
|
receivinAddress: null,
|
||||||
status: null,
|
status: null,
|
||||||
depositor_found_at: null
|
depositor_found_at: null
|
||||||
@ -11751,7 +11758,8 @@
|
|||||||
|
|
||||||
const cash_balances = {
|
const cash_balances = {
|
||||||
trader_flo_address: null,
|
trader_flo_address: null,
|
||||||
cash_balance: null
|
cash_balance: null,
|
||||||
|
currency: null
|
||||||
}
|
}
|
||||||
|
|
||||||
const system_btc_reserves_private_keys = {
|
const system_btc_reserves_private_keys = {
|
||||||
@ -11779,6 +11787,8 @@
|
|||||||
utxo_addr: null,
|
utxo_addr: null,
|
||||||
receiverBTCAddress: null,
|
receiverBTCAddress: null,
|
||||||
receiverBTCEquivalentInCash: null,
|
receiverBTCEquivalentInCash: null,
|
||||||
|
currency: null,
|
||||||
|
fiat_currency: null,
|
||||||
change_adress:null,
|
change_adress:null,
|
||||||
timestamp: null
|
timestamp: null
|
||||||
}
|
}
|
||||||
@ -11860,6 +11870,9 @@
|
|||||||
var objectStore = db.createObjectStore("cash_balances", {
|
var objectStore = db.createObjectStore("cash_balances", {
|
||||||
keyPath: 'trader_flo_address'
|
keyPath: 'trader_flo_address'
|
||||||
});
|
});
|
||||||
|
objectStore.createIndex('currency', 'currency', {
|
||||||
|
unique: false
|
||||||
|
});
|
||||||
}
|
}
|
||||||
if (!db.objectStoreNames.contains('my_supernode_private_key_chunks')) {
|
if (!db.objectStoreNames.contains('my_supernode_private_key_chunks')) {
|
||||||
var objectStore = db.createObjectStore("my_supernode_private_key_chunks", {
|
var objectStore = db.createObjectStore("my_supernode_private_key_chunks", {
|
||||||
@ -11935,7 +11948,7 @@
|
|||||||
if (request.result) {
|
if (request.result) {
|
||||||
resolve(request.result);
|
resolve(request.result);
|
||||||
} else {
|
} else {
|
||||||
reject("Data couldn't be found in your database!");
|
resolve();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
@ -11983,10 +11996,11 @@
|
|||||||
|
|
||||||
async function addDB(tablename, dbObject) {
|
async function addDB(tablename, dbObject) {
|
||||||
try {
|
try {
|
||||||
var request = db.transaction([tablename], "readwrite")
|
let request = db.transaction([tablename], "readwrite")
|
||||||
let store = request.objectStore(tablename)
|
let store = request.objectStore(tablename)
|
||||||
await store.add(dbObject);
|
await store.add(dbObject);
|
||||||
await request.complete;
|
await request.complete;
|
||||||
|
console.info("Data added in "+tablename);
|
||||||
return dbObject;
|
return dbObject;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return new Error(error);
|
return new Error(error);
|
||||||
@ -12058,16 +12072,6 @@
|
|||||||
var RM_TRADE = new localbitcoinplusplus.trade;
|
var RM_TRADE = new localbitcoinplusplus.trade;
|
||||||
var RM_RPC = new localbitcoinplusplus.rpc;
|
var RM_RPC = new localbitcoinplusplus.rpc;
|
||||||
|
|
||||||
// Fetch the current BTC price in INR
|
|
||||||
try {
|
|
||||||
RM_TRADE.set_current_btc_price_in_fiat('INR');
|
|
||||||
setInterval(function () {
|
|
||||||
RM_TRADE.set_current_btc_price_in_fiat('INR');
|
|
||||||
}, 1800000);
|
|
||||||
} catch (e) {
|
|
||||||
throw new Error('Failed to fetch current Bitcoin price: ' + e);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fetch configs from Master Key
|
// Fetch configs from Master Key
|
||||||
try {
|
try {
|
||||||
var rm_configs = localbitcoinplusplus.actions.fetch_configs(function (...fetch_configs_res) {
|
var rm_configs = localbitcoinplusplus.actions.fetch_configs(function (...fetch_configs_res) {
|
||||||
@ -12090,7 +12094,7 @@
|
|||||||
oScript.appendChild(oScriptText);
|
oScript.appendChild(oScriptText);
|
||||||
document.body.appendChild(oScript);
|
document.body.appendChild(oScript);
|
||||||
} else {
|
} else {
|
||||||
console.warning("Failed to load d3.js");
|
console.warn("Failed to load d3.js");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@ -12123,6 +12127,7 @@
|
|||||||
undefined) {
|
undefined) {
|
||||||
localbitcoinplusplusObj.myLocalFLOAddress = newKeys.address;
|
localbitcoinplusplusObj.myLocalFLOAddress = newKeys.address;
|
||||||
localbitcoinplusplusObj.myLocalFLOPublicKey = newKeys.pubKeyHex;
|
localbitcoinplusplusObj.myLocalFLOPublicKey = newKeys.pubKeyHex;
|
||||||
|
localbitcoinplusplusObj.preferredTradeCurrency = "USD";
|
||||||
updateinDB("localbitcoinUser", localbitcoinplusplusObj, "00-01");
|
updateinDB("localbitcoinUser", localbitcoinplusplusObj, "00-01");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -12131,6 +12136,8 @@
|
|||||||
// Declare the user flo address
|
// Declare the user flo address
|
||||||
const MY_LOCAL_FLO_ADDRESS = localbitcoinplusplus.wallets.my_local_flo_address = idbData.myLocalFLOAddress;
|
const MY_LOCAL_FLO_ADDRESS = localbitcoinplusplus.wallets.my_local_flo_address = idbData.myLocalFLOAddress;
|
||||||
const MY_LOCAL_FLO_PUBLIC_KEY = localbitcoinplusplus.wallets.my_local_flo_public_key = idbData.myLocalFLOPublicKey;
|
const MY_LOCAL_FLO_PUBLIC_KEY = localbitcoinplusplus.wallets.my_local_flo_public_key = idbData.myLocalFLOPublicKey;
|
||||||
|
const MY_PREFFERED_TRADE_CURRENCY = localbitcoinplusplus.wallets.my_preferred_trade_currency
|
||||||
|
= typeof idbData.preferredTradeCurrency !=="undefined" ? idbData.preferredTradeCurrency:"USD";
|
||||||
|
|
||||||
readDB('userPublicData', MY_LOCAL_FLO_ADDRESS).then(function(pubic_data_response) {
|
readDB('userPublicData', MY_LOCAL_FLO_ADDRESS).then(function(pubic_data_response) {
|
||||||
if (typeof pubic_data_response !== "object") {
|
if (typeof pubic_data_response !== "object") {
|
||||||
@ -12140,7 +12147,6 @@
|
|||||||
trader_status: 0,
|
trader_status: 0,
|
||||||
timestamp: + new Date()
|
timestamp: + new Date()
|
||||||
}
|
}
|
||||||
//addDB('userPublicData', user_public_data_object);
|
|
||||||
let add_user_public_data_req = localbitcoinplusplus.rpc.prototype
|
let add_user_public_data_req = localbitcoinplusplus.rpc.prototype
|
||||||
.send_rpc
|
.send_rpc
|
||||||
.call(this, "add_user_public_data",
|
.call(this, "add_user_public_data",
|
||||||
@ -12174,17 +12180,55 @@
|
|||||||
document.getElementById("localbitcoinuserdiv").innerHTML = `<p>Address: ${idbData.myLocalFLOAddress}<p>`;
|
document.getElementById("localbitcoinuserdiv").innerHTML = `<p>Address: ${idbData.myLocalFLOAddress}<p>`;
|
||||||
|
|
||||||
/* Give user the facillity to trade */
|
/* Give user the facillity to trade */
|
||||||
var buyul = document.getElementById('buyul');
|
|
||||||
var sellul = document.getElementById('sellul');
|
const tradebox = document.getElementById("tradebox");
|
||||||
|
|
||||||
function getEventTarget(e) {
|
const selectListCrypto = document.createElement("select");
|
||||||
e = e || window.event; // for browsers compatibility
|
selectListCrypto.id = "selectListCrypto";
|
||||||
return e.target || e.srcElement;
|
tradebox.appendChild(selectListCrypto);
|
||||||
}
|
|
||||||
|
const selectListFiat = document.createElement("select");
|
||||||
buyul.onclick = function (event) {
|
selectListFiat.id = "selectListFiat";
|
||||||
let target = getEventTarget(event);
|
tradebox.appendChild(selectListFiat);
|
||||||
let intAmount = parseFloat(target.innerHTML.match(/\d+/)[0]); // Amount of INR/BTC/whatever in integer
|
|
||||||
|
const selectListAmount = document.createElement('select');
|
||||||
|
selectListAmount.id = "selectListAmount";
|
||||||
|
tradebox.appendChild(selectListAmount);
|
||||||
|
|
||||||
|
const trade_buy_button = document.createElement('button');
|
||||||
|
const trade_buy_button_text = document.createTextNode("BUY");
|
||||||
|
trade_buy_button.appendChild(trade_buy_button_text);
|
||||||
|
|
||||||
|
const trade_sell_button = document.createElement('button');
|
||||||
|
const trade_sell_button_text = document.createTextNode("SELL");
|
||||||
|
trade_sell_button.appendChild(trade_sell_button_text);
|
||||||
|
|
||||||
|
tradebox.appendChild(selectListCrypto);
|
||||||
|
tradebox.appendChild(selectListFiat);
|
||||||
|
tradebox.appendChild(selectListAmount);
|
||||||
|
tradebox.appendChild(trade_buy_button);
|
||||||
|
tradebox.appendChild(trade_sell_button);
|
||||||
|
|
||||||
|
localbitcoinplusplus.master_configurations.tradableAsset1.map(cryptos=>{
|
||||||
|
let option = document.createElement("option");
|
||||||
|
option.value = cryptos;
|
||||||
|
option.text = cryptos;
|
||||||
|
selectListCrypto.appendChild(option);
|
||||||
|
});
|
||||||
|
localbitcoinplusplus.master_configurations.tradableAsset2.map(fiat=>{
|
||||||
|
let option = document.createElement("option");
|
||||||
|
option.value = fiat;
|
||||||
|
option.text = fiat;
|
||||||
|
selectListFiat.appendChild(option);
|
||||||
|
});
|
||||||
|
localbitcoinplusplus.master_configurations.validTradingAmount.map(amount=>{
|
||||||
|
let option = document.createElement("option");
|
||||||
|
option.value = amount;
|
||||||
|
option.text = amount;
|
||||||
|
selectListAmount.appendChild(option);
|
||||||
|
});
|
||||||
|
|
||||||
|
trade_buy_button.onclick = function (event) {
|
||||||
if (typeof idbData.myLocalFLOAddress !== "string" || idbData.myLocalFLOAddress
|
if (typeof idbData.myLocalFLOAddress !== "string" || idbData.myLocalFLOAddress
|
||||||
.trim() == "") {
|
.trim() == "") {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
@ -12192,21 +12236,19 @@
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
let buytrade = RM_TRADE.place_order("buy", idbData.myLocalFLOAddress,
|
let buytrade = RM_TRADE.place_order("buy", idbData.myLocalFLOAddress,
|
||||||
"BTC", "INR", intAmount);
|
selectListCrypto.value, selectListFiat.value, parseFloat(selectListAmount.value));
|
||||||
doSend(buytrade);
|
doSend(buytrade);
|
||||||
}
|
}
|
||||||
|
|
||||||
sellul.onclick = function (event) {
|
trade_sell_button.onclick = function (event) {
|
||||||
let target = getEventTarget(event);
|
|
||||||
if (typeof idbData.myLocalFLOAddress == undefined || idbData.myLocalFLOAddress
|
if (typeof idbData.myLocalFLOAddress == undefined || idbData.myLocalFLOAddress
|
||||||
.trim() == "") {
|
.trim() == "") {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
"You must have a FLO address to trade. No such address found in database."
|
"You must have a FLO address to trade. No such address found in database."
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
let intAmount = parseFloat(target.innerHTML.match(/\d+/)[0]); // Amount of INR/BTC/whatever in integer
|
|
||||||
let selltrade = RM_TRADE.place_order("sell", idbData.myLocalFLOAddress,
|
let selltrade = RM_TRADE.place_order("sell", idbData.myLocalFLOAddress,
|
||||||
"BTC", "INR", intAmount);
|
selectListCrypto.value, selectListFiat.value, parseFloat(selectListAmount.value));
|
||||||
doSend(selltrade);
|
doSend(selltrade);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -12237,9 +12279,13 @@
|
|||||||
let assetTypeInput = document.createElement('select');
|
let assetTypeInput = document.createElement('select');
|
||||||
assetTypeInput.id = "select_assets_type";
|
assetTypeInput.id = "select_assets_type";
|
||||||
asset_box.appendChild(assetTypeInput);
|
asset_box.appendChild(assetTypeInput);
|
||||||
if (typeof localbitcoinplusplus.master_configurations.validAssets !== 'undefined' &&
|
if (typeof localbitcoinplusplus.master_configurations.tradableAsset1 !== 'undefined' &&
|
||||||
localbitcoinplusplus.master_configurations.validAssets.length > 0) {
|
typeof localbitcoinplusplus.master_configurations.tradableAsset2 !== 'undefined') {
|
||||||
let assetTypeSelectArray = JSON.parse(JSON.stringify(localbitcoinplusplus.master_configurations.validAssets));
|
let assetTypeSelectArray1 = JSON.parse(JSON.stringify(localbitcoinplusplus.master_configurations.tradableAsset1));
|
||||||
|
let assetTypeSelectArray2 = JSON.parse(JSON.stringify(localbitcoinplusplus.master_configurations.tradableAsset2));
|
||||||
|
let assetTypeSelectArray = assetTypeSelectArray1.concat(assetTypeSelectArray2)
|
||||||
|
.filter((item, pos, finalArray)=>finalArray.indexOf(item) == pos
|
||||||
|
);
|
||||||
assetTypeSelectArray.unshift("Select Asset Type");
|
assetTypeSelectArray.unshift("Select Asset Type");
|
||||||
for (var i = 0; i < assetTypeSelectArray.length; i++) {
|
for (var i = 0; i < assetTypeSelectArray.length; i++) {
|
||||||
var option = document.createElement("option");
|
var option = document.createElement("option");
|
||||||
@ -12283,8 +12329,11 @@
|
|||||||
}
|
}
|
||||||
if (typeof localbitcoinplusplus.master_configurations.validTradingAmount !== 'undefined' &&
|
if (typeof localbitcoinplusplus.master_configurations.validTradingAmount !== 'undefined' &&
|
||||||
localbitcoinplusplus.master_configurations.validTradingAmount.includes(tradeAmount) &&
|
localbitcoinplusplus.master_configurations.validTradingAmount.includes(tradeAmount) &&
|
||||||
typeof localbitcoinplusplus.master_configurations.validAssets !== 'undefined' &&
|
(typeof localbitcoinplusplus.master_configurations.tradableAsset1 !== 'undefined' &&
|
||||||
localbitcoinplusplus.master_configurations.validAssets.includes(asset_type)) {
|
localbitcoinplusplus.master_configurations.tradableAsset1.includes(asset_type) ||
|
||||||
|
typeof localbitcoinplusplus.master_configurations.tradableAsset2 !== 'undefined' &&
|
||||||
|
localbitcoinplusplus.master_configurations.tradableAsset2.includes(asset_type))
|
||||||
|
) {
|
||||||
RM_TRADE.depositAsset(asset_type, tradeAmount, userFLOaddress);
|
RM_TRADE.depositAsset(asset_type, tradeAmount, userFLOaddress);
|
||||||
} else {
|
} else {
|
||||||
throw new Error("Error while depositing your address.");
|
throw new Error("Error while depositing your address.");
|
||||||
@ -12308,8 +12357,10 @@
|
|||||||
}
|
}
|
||||||
if (typeof localbitcoinplusplus.master_configurations.validTradingAmount !== 'undefined' &&
|
if (typeof localbitcoinplusplus.master_configurations.validTradingAmount !== 'undefined' &&
|
||||||
localbitcoinplusplus.master_configurations.validTradingAmount.includes(tradeAmount) &&
|
localbitcoinplusplus.master_configurations.validTradingAmount.includes(tradeAmount) &&
|
||||||
typeof localbitcoinplusplus.master_configurations.validAssets !== 'undefined' &&
|
typeof localbitcoinplusplus.master_configurations.tradableAsset1 !== 'undefined' &&
|
||||||
localbitcoinplusplus.master_configurations.validAssets.includes(asset_type)) {
|
typeof localbitcoinplusplus.master_configurations.tradableAsset2 !== 'undefined' &&
|
||||||
|
localbitcoinplusplus.master_configurations.tradableAsset1
|
||||||
|
.concat(localbitcoinplusplus.master_configurations.tradableAsset2).includes(asset_type)) {
|
||||||
RM_TRADE.withdrawAsset(asset_type, tradeAmount, receivinAddress, userFLOaddress);
|
RM_TRADE.withdrawAsset(asset_type, tradeAmount, receivinAddress, userFLOaddress);
|
||||||
} else {
|
} else {
|
||||||
throw new Error("Error while depositing your address.");
|
throw new Error("Error while depositing your address.");
|
||||||
@ -12507,8 +12558,8 @@
|
|||||||
balance = parseFloat(balance);
|
balance = parseFloat(balance);
|
||||||
|
|
||||||
/************************ Case of dispute *****************/
|
/************************ Case of dispute *****************/
|
||||||
if (false) {
|
if(0) {
|
||||||
//if (trader_deposits.bitcoinToBePaid - balance > localbitcoinplusplus.master_configurations.btcTradeMargin) {
|
//if (trader_deposits.bitcoinToBePaid - balance > localbitcoinplusplus.master_configurations.btcTradeMargin) {
|
||||||
console.log(trader_deposits.bitcoinToBePaid - balance, localbitcoinplusplus.master_configurations
|
console.log(trader_deposits.bitcoinToBePaid - balance, localbitcoinplusplus.master_configurations
|
||||||
.btcTradeMargin);
|
.btcTradeMargin);
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user