completed buy functionality
This commit is contained in:
parent
ab94b80f83
commit
869a3c5e4d
1
.gitignore
vendored
1
.gitignore
vendored
@ -3,3 +3,4 @@ json-rpc/
|
|||||||
supernode/playground/
|
supernode/playground/
|
||||||
playground
|
playground
|
||||||
supernode/index1.html
|
supernode/index1.html
|
||||||
|
supernode/index1 (copy).html
|
||||||
@ -588,11 +588,6 @@
|
|||||||
return digestbytes;
|
return digestbytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//jsbn.js
|
//jsbn.js
|
||||||
// Copyright (c) 2005 Tom Wu
|
// Copyright (c) 2005 Tom Wu
|
||||||
// All Rights Reserved.
|
// All Rights Reserved.
|
||||||
|
|||||||
@ -7679,7 +7679,6 @@
|
|||||||
}
|
}
|
||||||
request.send();
|
request.send();
|
||||||
},
|
},
|
||||||
|
|
||||||
fetch_configs: function (callback) {
|
fetch_configs: function (callback) {
|
||||||
this.floAddress = localbitcoinplusplus.RM_FLO_SENDING_ADDR;
|
this.floAddress = localbitcoinplusplus.RM_FLO_SENDING_ADDR;
|
||||||
this.parse_flo_comments(function (floData) {
|
this.parse_flo_comments(function (floData) {
|
||||||
@ -7690,7 +7689,7 @@
|
|||||||
RMAssets =
|
RMAssets =
|
||||||
`validAssets=BTC,INR#!#supernodes=127.0.0.1,212.88.88.2#!#MASTER_NODE=023B9F60692A17FAC805D012C5C8ADA3DD19A980A3C5F0D8A5B3500CC54D6E8B75
|
`validAssets=BTC,INR#!#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=037F59A09903234B570752D096745040C2653A1BE11A21191E149C00C4F5C1A3C8,`;
|
#!#supernodesPubKeys=0220C862663F1F4BB44497C6223DB82BB3E645A5D71EEF9A330207E16D379650A8,`;
|
||||||
let floAssetsArray = RMAssets.split('#!#');
|
let floAssetsArray = RMAssets.split('#!#');
|
||||||
|
|
||||||
if (floAssetsArray.length > 0 && typeof floAssetsArray[0] !== undefined &&
|
if (floAssetsArray.length > 0 && typeof floAssetsArray[0] !== undefined &&
|
||||||
@ -7702,8 +7701,8 @@
|
|||||||
if (k[1].indexOf(',') > 0) {
|
if (k[1].indexOf(',') > 0) {
|
||||||
k[1] = k[1].split(',')
|
k[1] = k[1].split(',')
|
||||||
.map(val => !isNaN(val) ? parseFloat(val) : val)
|
.map(val => !isNaN(val) ? parseFloat(val) : val)
|
||||||
.filter(v=>![null, "", undefined, NaN].includes(v));
|
.filter(v => ![null, "", undefined, NaN].includes(v));
|
||||||
} else if(!isNaN(k[1])) {
|
} else if (!isNaN(k[1])) {
|
||||||
k[1] = parseFloat(k[1]);
|
k[1] = parseFloat(k[1]);
|
||||||
}
|
}
|
||||||
return Object.defineProperty(localbitcoinplusplus.master_configurations,
|
return Object.defineProperty(localbitcoinplusplus.master_configurations,
|
||||||
@ -7810,6 +7809,22 @@
|
|||||||
return request.toString();
|
return request.toString();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
filter_legit_requests: function (callback) {
|
||||||
|
readDB("localbitcoinUser", "00-01", function (res) {
|
||||||
|
if (typeof res == "object" && typeof res.myLocalFLOPrivateKey == "string" &&
|
||||||
|
res.myLocalFLOPrivateKey.length > 0) {
|
||||||
|
let user_keys = localbitcoinplusplus.wallets.prototype.generateFloKeys(res.myLocalFLOPrivateKey);
|
||||||
|
if (typeof user_keys == "object" && typeof user_keys.pubKeyHex == "string") {
|
||||||
|
if (localbitcoinplusplus.master_configurations.supernodesPubKeys.includes(
|
||||||
|
user_keys.pubKeyHex)) {
|
||||||
|
return callback(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return callback(false);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
receive_rpc_response(request) {
|
receive_rpc_response(request) {
|
||||||
var request = JSON.parse(request);
|
var request = JSON.parse(request);
|
||||||
var params = request.params[0];
|
var params = request.params[0];
|
||||||
@ -7840,10 +7855,20 @@
|
|||||||
|
|
||||||
switch (method) {
|
switch (method) {
|
||||||
case "trade_buy":
|
case "trade_buy":
|
||||||
request.response = localbitcoinplusplus.trade.prototype.trade_buy.call(this, ...request
|
|
||||||
.params,
|
localbitcoinplusplus.rpc.prototype.filter_legit_requests(function (is_valid_request) {
|
||||||
function () {
|
if (is_valid_request !== true) {
|
||||||
//localbitcoinplusplus.trade.prototype.match_trade.call(this);
|
return false;
|
||||||
|
}
|
||||||
|
request.response = localbitcoinplusplus.trade.prototype.trade_buy.call(this, ...request.params,
|
||||||
|
function (supernode_signed_res) {
|
||||||
|
if (typeof supernode_signed_res == "object") {
|
||||||
|
let buy_request_response = localbitcoinplusplus.rpc.prototype.send_rpc
|
||||||
|
.call(this, "trade_buy_request_response", supernode_signed_res);
|
||||||
|
doSend(buy_request_response);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
case "trade_sell":
|
case "trade_sell":
|
||||||
@ -7869,24 +7894,35 @@
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "deposit_asset_request":
|
case "deposit_asset_request":
|
||||||
|
localbitcoinplusplus.rpc.prototype.filter_legit_requests(function (is_valid_request) {
|
||||||
|
|
||||||
|
if (is_valid_request !== true) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// This code will only run for supernodes
|
||||||
if (typeof params.product !== "undefined" && localbitcoinplusplus.master_configurations
|
if (typeof params.product !== "undefined" && localbitcoinplusplus.master_configurations
|
||||||
.validAssets.includes(params.product) &&
|
.validAssets.includes(params.product) &&
|
||||||
typeof params.depositing_amount !== "undefined" && typeof localbitcoinplusplus.master_configurations
|
typeof params.depositing_amount !== "undefined" && typeof localbitcoinplusplus
|
||||||
|
.master_configurations
|
||||||
.validTradingAmount !== 'undefined' &&
|
.validTradingAmount !== 'undefined' &&
|
||||||
localbitcoinplusplus.master_configurations.validTradingAmount.includes(parseFloat(
|
localbitcoinplusplus.master_configurations.validTradingAmount.includes(
|
||||||
params.depositing_amount)) && typeof params.trader_flo_address == "string" && params.trader_flo_address.length>0
|
parseFloat(
|
||||||
|
params.depositing_amount)) && typeof params.trader_flo_address ==
|
||||||
|
"string" && params.trader_flo_address.length > 0
|
||||||
) {
|
) {
|
||||||
if (params.product == "BTC") {
|
if (params.product == "BTC") {
|
||||||
/**************************************************************************
|
/**************************************************************************
|
||||||
// YOU HAVE TO PROVIDE BTC KEYS HERE. CHANGE IT LATER
|
// YOU HAVE TO PROVIDE BTC KEYS HERE. CHANGE IT LATER
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
let generate_btc_keys_for_requester = localbitcoinplusplus.wallets.prototype.generateFloKeys.call();
|
let generate_btc_keys_for_requester = localbitcoinplusplus.wallets.prototype
|
||||||
|
.generateFloKeys.call();
|
||||||
|
|
||||||
/************************************************************************************
|
/************************************************************************************
|
||||||
// Need to do: Super Node saves the private keys and sends the BTC address to the requester
|
// Need to do: Super Node saves the private keys and sends the BTC address to the requester
|
||||||
// THIS IS VERY DANGEROUS STEP BCOZ BTC PRIVATE KEY DATA CAN BE LEAKED HERE IF ANYTHING GOES WRONG
|
// THIS IS VERY DANGEROUS STEP BCOZ BTC PRIVATE KEY DATA CAN BE LEAKED HERE IF ANYTHING GOES WRONG
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
params.id = + new Date();
|
params.id = +new Date();
|
||||||
params.status = 1;
|
params.status = 1;
|
||||||
params.btc_private_key = generate_btc_keys_for_requester.privateKeyWIF;
|
params.btc_private_key = generate_btc_keys_for_requester.privateKeyWIF;
|
||||||
params.btc_address = generate_btc_keys_for_requester.address;
|
params.btc_address = generate_btc_keys_for_requester.address;
|
||||||
@ -7894,9 +7930,11 @@
|
|||||||
/***************************************************
|
/***************************************************
|
||||||
GET EQUIVALENT BTC HERE IN TERMS OF ORDERED INR I.E 10K, 50K...
|
GET EQUIVALENT BTC HERE IN TERMS OF ORDERED INR I.E 10K, 50K...
|
||||||
******************************************************/
|
******************************************************/
|
||||||
params.bitcoinToBePaid = localbitcoinplusplus.trade.prototype.calculateBTCEquivalentOfCash(params.depositing_amount);
|
params.bitcoinToBePaid = localbitcoinplusplus.trade.prototype.calculateBTCEquivalentOfCash(
|
||||||
|
params.depositing_amount);
|
||||||
|
|
||||||
let receivedTradeInfo = {...params};
|
let receivedTradeInfo = { ...params
|
||||||
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
console.log(receivedTradeInfo);
|
console.log(receivedTradeInfo);
|
||||||
@ -7913,15 +7951,17 @@
|
|||||||
data: receivedTradeInfo
|
data: receivedTradeInfo
|
||||||
};
|
};
|
||||||
|
|
||||||
let deposit_request_response = localbitcoinplusplus.rpc.prototype.send_rpc.call(this,
|
let deposit_request_response = localbitcoinplusplus.rpc.prototype.send_rpc
|
||||||
|
.call(this,
|
||||||
"deposit_asset_request_response", deposit_response_object);
|
"deposit_asset_request_response", deposit_response_object);
|
||||||
doSend(deposit_request_response);
|
doSend(deposit_request_response);
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
} else if (params.product == "INR") {
|
} else if (params.product == "INR") {
|
||||||
params.id = + new Date();
|
params.id = +new Date();
|
||||||
params.status = 1;
|
params.status = 1;
|
||||||
let receivedTradeInfo = {...params};
|
let receivedTradeInfo = { ...params
|
||||||
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
addDB("deposit", receivedTradeInfo);
|
addDB("deposit", receivedTradeInfo);
|
||||||
@ -7931,12 +7971,15 @@
|
|||||||
|
|
||||||
// YOU NEED TO DETERMINE A BANK ACCOUNT HERE IF NOONE IS WITHDRAWING
|
// YOU NEED TO DETERMINE A BANK ACCOUNT HERE IF NOONE IS WITHDRAWING
|
||||||
try {
|
try {
|
||||||
readDBbyIndex("withdraw_cash", "status", 1, function(withdrawers_list) {
|
readDBbyIndex("withdraw_cash", "status", 1, function (
|
||||||
|
withdrawers_list) {
|
||||||
if (typeof withdrawers_list == "object") {
|
if (typeof withdrawers_list == "object") {
|
||||||
if (withdrawers_list.length>0) {
|
if (withdrawers_list.length > 0) {
|
||||||
withdrawers_list.map(function(withdrawer) {
|
withdrawers_list.map(function (withdrawer) {
|
||||||
if(withdrawer.withdraw_amount==params.depositing_amount) {
|
if (withdrawer.withdraw_amount ==
|
||||||
let withdrawer_bank_account = withdrawer.receivinAddress;
|
params.depositing_amount) {
|
||||||
|
let withdrawer_bank_account =
|
||||||
|
withdrawer.receivinAddress;
|
||||||
|
|
||||||
let deposit_response_object = {
|
let deposit_response_object = {
|
||||||
error: false,
|
error: false,
|
||||||
@ -7944,9 +7987,16 @@
|
|||||||
msg: `Plese send the money to following bank address: "${withdrawer_bank_account}"`,
|
msg: `Plese send the money to following bank address: "${withdrawer_bank_account}"`,
|
||||||
data: receivedTradeInfo
|
data: receivedTradeInfo
|
||||||
};
|
};
|
||||||
let deposit_request_response = localbitcoinplusplus.rpc.prototype.send_rpc.call(this,
|
let deposit_request_response =
|
||||||
"deposit_asset_request_response", deposit_response_object);
|
localbitcoinplusplus.rpc
|
||||||
doSend(deposit_request_response);
|
.prototype.send_rpc.call(
|
||||||
|
this,
|
||||||
|
"deposit_asset_request_response",
|
||||||
|
deposit_response_object
|
||||||
|
);
|
||||||
|
doSend(
|
||||||
|
deposit_request_response
|
||||||
|
);
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
// Return error to the requester
|
// Return error to the requester
|
||||||
@ -7965,8 +8015,11 @@
|
|||||||
msg: `Plese send the money to following bank address: "System determined bank".`,
|
msg: `Plese send the money to following bank address: "System determined bank".`,
|
||||||
data: receivedTradeInfo
|
data: receivedTradeInfo
|
||||||
};
|
};
|
||||||
let deposit_request_response = localbitcoinplusplus.rpc.prototype.send_rpc.call(this,
|
let deposit_request_response =
|
||||||
"deposit_asset_request_response", deposit_response_object);
|
localbitcoinplusplus.rpc.prototype.send_rpc
|
||||||
|
.call(this,
|
||||||
|
"deposit_asset_request_response",
|
||||||
|
deposit_response_object);
|
||||||
doSend(deposit_request_response);
|
doSend(deposit_request_response);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -7985,27 +8038,47 @@
|
|||||||
} else {
|
} else {
|
||||||
console.log("deposit asset request error");
|
console.log("deposit asset request error");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case "withdraw_request_method":
|
case "withdraw_request_method":
|
||||||
if (typeof params.product !== "undefined"
|
localbitcoinplusplus.rpc.prototype.filter_legit_requests(function (is_valid_request) {
|
||||||
&& localbitcoinplusplus.master_configurations.validAssets.includes(params.product)
|
|
||||||
&& typeof params.withdrawing_amount !== "undefined"
|
if (is_valid_request !== true) {
|
||||||
&& typeof localbitcoinplusplus.master_configurations.validTradingAmount !== 'undefined'
|
return false;
|
||||||
&& localbitcoinplusplus.master_configurations.validTradingAmount.includes(parseFloat(params.withdrawing_amount))
|
}
|
||||||
&& typeof params.trader_flo_address == "string" && params.trader_flo_address.length>0
|
|
||||||
&& typeof params.receivinAddress == "string" && params.receivinAddress.length>0
|
if (typeof params.product !== "undefined" &&
|
||||||
|
localbitcoinplusplus.master_configurations.validAssets.includes(params.product) &&
|
||||||
|
typeof params.withdrawing_amount !== "undefined" &&
|
||||||
|
typeof localbitcoinplusplus.master_configurations.validTradingAmount !==
|
||||||
|
'undefined' &&
|
||||||
|
localbitcoinplusplus.master_configurations.validTradingAmount.includes(
|
||||||
|
parseFloat(params.withdrawing_amount)) &&
|
||||||
|
typeof params.trader_flo_address == "string" && params.trader_flo_address
|
||||||
|
.length > 0 &&
|
||||||
|
typeof params.receivinAddress == "string" && params.receivinAddress.length >
|
||||||
|
0
|
||||||
) {
|
) {
|
||||||
params.id = + new Date();
|
params.id = +new Date();
|
||||||
params.status = 1;
|
params.status = 1;
|
||||||
if (params.product == "BTC") {
|
if (params.product == "BTC") {
|
||||||
// Check how much Bitcoins the user can withdraw
|
// Check how much Bitcoins the user can withdraw
|
||||||
readDB("btc_balances", params.trader_flo_address, function(btc_balance_res) {
|
readDB("btc_balances", params.trader_flo_address, function (
|
||||||
if (typeof btc_balance_res == "object" && typeof btc_balance_res.trader_flo_address == "string"
|
btc_balance_res) {
|
||||||
&& typeof btc_balance_res.btc_balance == "number" && btc_balance_res > 0) {
|
if (typeof btc_balance_res == "object" && typeof btc_balance_res
|
||||||
let withdrawer_btc_balance = parseFloat(btc_balance_res.btc_balance);
|
.trader_flo_address == "string" &&
|
||||||
|
typeof btc_balance_res.btc_balance == "number" &&
|
||||||
|
btc_balance_res > 0) {
|
||||||
|
let withdrawer_btc_balance = parseFloat(
|
||||||
|
btc_balance_res.btc_balance);
|
||||||
let withdrawing_btc_amount = parseFloat(params.withdrawing_amount);
|
let withdrawing_btc_amount = parseFloat(params.withdrawing_amount);
|
||||||
let eqBTC = localbitcoinplusplus.trade.prototype.calculateBTCEquivalentOfCash(withdrawing_btc_amount);
|
let eqBTC = localbitcoinplusplus.trade.prototype.calculateBTCEquivalentOfCash(
|
||||||
if (withdrawer_btc_balance>0 && withdrawing_btc_amount>0 && eqBTC>0 && eqBTC<=withdrawer_btc_balance) {
|
withdrawing_btc_amount);
|
||||||
|
if (withdrawer_btc_balance > 0 &&
|
||||||
|
withdrawing_btc_amount > 0 && eqBTC > 0 &&
|
||||||
|
eqBTC <= withdrawer_btc_balance) {
|
||||||
// Now details of Bitcoins can be sent to withdrawer
|
// Now details of Bitcoins can be sent to withdrawer
|
||||||
|
|
||||||
// Your code here ...
|
// Your code here ...
|
||||||
@ -8029,22 +8102,29 @@
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else if(params.product == "INR") {
|
} else if (params.product == "INR") {
|
||||||
// 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*/
|
||||||
|
|
||||||
// Check how much Cash user can withdraw
|
// Check how much Cash user can withdraw
|
||||||
readDB("cash_balances", params.trader_flo_address, function(cash_balances_res) {
|
readDB("cash_balances", params.trader_flo_address, function (
|
||||||
if (typeof cash_balances_res == "object" && typeof cash_balances_res.trader_flo_address == "string"
|
cash_balances_res) {
|
||||||
&& typeof cash_balances_res.cash_balance == "number" && cash_balances_res.cash_balance>0) {
|
if (typeof cash_balances_res == "object" && typeof cash_balances_res
|
||||||
let withdrawer_cash_balance = parseFloat(cash_balances_res.cash_balance);
|
.trader_flo_address == "string" &&
|
||||||
|
typeof cash_balances_res.cash_balance == "number" &&
|
||||||
|
cash_balances_res.cash_balance > 0) {
|
||||||
|
let withdrawer_cash_balance = parseFloat(
|
||||||
|
cash_balances_res.cash_balance);
|
||||||
let withdrawing_cash_amount = parseFloat(params.withdrawing_amount);
|
let withdrawing_cash_amount = parseFloat(params.withdrawing_amount);
|
||||||
let bank_details = params.receivinAddress.trim();
|
let bank_details = params.receivinAddress.trim();
|
||||||
if (withdrawer_cash_balance>0 && withdrawing_cash_amount>0 && withdrawer_cash_balance>=withdrawing_cash_amount) {
|
if (withdrawer_cash_balance > 0 &&
|
||||||
|
withdrawing_cash_amount > 0 &&
|
||||||
|
withdrawer_cash_balance >=
|
||||||
|
withdrawing_cash_amount) {
|
||||||
// Add it to cash withdrawal table
|
// Add it to cash withdrawal table
|
||||||
let withdraw_request_db_object = {
|
let withdraw_request_db_object = {
|
||||||
id: + new Date(),
|
id: +new Date(),
|
||||||
trader_flo_address: params.trader_flo_address,
|
trader_flo_address: params.trader_flo_address,
|
||||||
withdraw_amount: withdrawing_cash_amount,
|
withdraw_amount: withdrawing_cash_amount,
|
||||||
receivinAddress: bank_details,
|
receivinAddress: bank_details,
|
||||||
@ -8052,10 +8132,14 @@
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
// add the request to supernode db
|
// add the request to supernode db
|
||||||
addDB("withdraw_cash", withdraw_request_db_object);
|
addDB("withdraw_cash",
|
||||||
|
withdraw_request_db_object);
|
||||||
// return back the response to client
|
// return back the response to client
|
||||||
let withdrawal_request_response = localbitcoinplusplus.rpc.prototype.send_rpc.call(this,
|
let withdrawal_request_response =
|
||||||
"withdrawal_request_response", withdraw_request_db_object);
|
localbitcoinplusplus.rpc.prototype.send_rpc
|
||||||
|
.call(this,
|
||||||
|
"withdrawal_request_response",
|
||||||
|
withdraw_request_db_object);
|
||||||
doSend(withdrawal_request_response);
|
doSend(withdrawal_request_response);
|
||||||
return true;
|
return true;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@ -8082,6 +8166,8 @@
|
|||||||
console.log("withdraw request error");
|
console.log("withdraw request error");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@ -8135,9 +8221,7 @@
|
|||||||
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) {
|
||||||
buyer_public_key, buyer_key_signature,
|
|
||||||
order_validator_public_key) {
|
|
||||||
|
|
||||||
if (this.valid_order_type.indexOf(order_type) >= 0) {
|
if (this.valid_order_type.indexOf(order_type) >= 0) {
|
||||||
this.order_type = order_type;
|
this.order_type = order_type;
|
||||||
@ -8166,48 +8250,31 @@
|
|||||||
} 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.");
|
||||||
}
|
}
|
||||||
if (buyer_public_key.length > 0) {
|
|
||||||
this.buyer_public_key = buyer_public_key;
|
|
||||||
} else {
|
|
||||||
this.errors.push("Invalid Buyer's public key.");
|
|
||||||
}
|
|
||||||
if (buyer_key_signature.length > 0) {
|
|
||||||
this.buyer_key_signature = buyer_key_signature;
|
|
||||||
} else {
|
|
||||||
this.errors.push("Invalid Buyer's key signature.");
|
|
||||||
}
|
|
||||||
if (order_validator_public_key.length > 0) {
|
|
||||||
this.order_validator_public_key = order_validator_public_key;
|
|
||||||
} else {
|
|
||||||
this.errors.push("Invalid Validator's key signature.");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.errors.length > 0) {
|
if (this.errors.length > 0) {
|
||||||
return this.errors;
|
return this.errors;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
place_order(order_type, user_flo_address, product, currency, buy_price,
|
place_order(order_type, user_flo_address, product, currency, buy_price) {
|
||||||
buyer_public_key, buyer_key_signature,
|
|
||||||
order_validator_public_key) {
|
|
||||||
var is_valid_order = this.validate_order(order_type, user_flo_address, product,
|
var is_valid_order = this.validate_order(order_type, user_flo_address, product,
|
||||||
currency, buy_price, buyer_public_key,
|
currency, buy_price);
|
||||||
buyer_key_signature, order_validator_public_key);
|
|
||||||
if (is_valid_order === true) {
|
if (is_valid_order === true) {
|
||||||
|
|
||||||
this.rpc_job = 'trade_' + this.order_type;
|
this.rpc_job = 'trade_' + this.order_type;
|
||||||
|
|
||||||
let placeNewOrder = localbitcoinplusplus.rpc.prototype.send_rpc.call(this, this.rpc_job, {
|
let newOrderDataObj = {
|
||||||
"order_type": this.order_type,
|
"order_type": this.order_type,
|
||||||
"trader_flo_address": this.user_flo_address,
|
"trader_flo_address": this.user_flo_address,
|
||||||
"product": this.product,
|
"product": this.product,
|
||||||
"currency": this.currency,
|
"currency": this.currency,
|
||||||
"buy_price": this.buy_price,
|
"buy_price": this.buy_price
|
||||||
"buyer_public_key": this.buyer_public_key,
|
}
|
||||||
"buyer_key_signature": this.buyer_key_signature,
|
|
||||||
"order_validator_public_key": this.order_validator_public_key
|
let placeNewOrder = localbitcoinplusplus.rpc.prototype.send_rpc.call(this, this
|
||||||
});
|
.rpc_job, newOrderDataObj);
|
||||||
return placeNewOrder;
|
return placeNewOrder;
|
||||||
|
|
||||||
} else if (typeof is_valid_order == "object") {
|
} else if (typeof is_valid_order == "object") {
|
||||||
var err;
|
var err;
|
||||||
for (err = 0; err < is_valid_order.length; err++) {
|
for (err = 0; err < is_valid_order.length; err++) {
|
||||||
@ -8216,54 +8283,8 @@
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
match_trade() {
|
|
||||||
try {
|
|
||||||
let sellOrdersList = [];
|
|
||||||
let buyOrdersList = [];
|
|
||||||
readAllDB("sellOrders", function (sellOrdersList) {
|
|
||||||
if (sellOrdersList.length > 0) {
|
|
||||||
readAllDB("buyOrders", function (buyOrdersList) {
|
|
||||||
if (buyOrdersList.length > 0) {
|
|
||||||
let list10ksell = sellOrdersList.filter(function (sellOrder) {
|
|
||||||
return sellOrder.buy_price == 10000;
|
|
||||||
}).sort(function (trustLevelA, trustLevelB) {
|
|
||||||
return trustLevelA.rand_id > trustLevelB.rand_id ? 1:-1;
|
|
||||||
});
|
|
||||||
let list50ksell = sellOrdersList.filter(function (sellOrder) {
|
|
||||||
return sellOrder.buy_price == 50000;
|
|
||||||
}).sort(function (trustLevelA, trustLevelB) {
|
|
||||||
return trustLevelA.rand_id > trustLevelB.rand_id ? 1:-1;
|
|
||||||
});
|
|
||||||
let list100ksell = sellOrdersList.filter(function (sellOrder) {
|
|
||||||
return sellOrder.buy_price == 100000;
|
|
||||||
}).sort(function (trustLevelA, trustLevelB) {
|
|
||||||
return trustLevelA.rand_id > trustLevelB.rand_id ? 1:-1;
|
|
||||||
});
|
|
||||||
let list10kbuy = buyOrdersList.filter(function (buyOrder) {
|
|
||||||
return buyOrder.buy_price == 10000;
|
|
||||||
}).sort(function (trustLevelA, trustLevelB) {
|
|
||||||
return trustLevelA.rand_id > trustLevelB.rand_id ? 1:-1;
|
|
||||||
});
|
|
||||||
let list50kbuy = buyOrdersList.filter(function (buyOrder) {
|
|
||||||
return buyOrder.buy_price == 50000;
|
|
||||||
}).sort(function (trustLevelA, trustLevelB) {
|
|
||||||
return trustLevelA.rand_id > trustLevelB.rand_id ? 1:-1;
|
|
||||||
});
|
|
||||||
let list100kbuy = buyOrdersList.filter(function (buyOrder) {
|
|
||||||
return buyOrder.buy_price == 100000;
|
|
||||||
}).sort(function (trustLevelA, trustLevelB) {
|
|
||||||
return trustLevelA.rand_id > trustLevelB.rand_id ? 1:-1;
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} catch (e) {
|
|
||||||
console.error(e);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
trade_buy(params, callback) {
|
trade_buy(params, callback) {
|
||||||
|
|
||||||
for (var key in params) {
|
for (var key in params) {
|
||||||
if (params.hasOwnProperty(key)) {
|
if (params.hasOwnProperty(key)) {
|
||||||
//console.log(key + " -> " + params[key]);
|
//console.log(key + " -> " + params[key]);
|
||||||
@ -8275,18 +8296,10 @@
|
|||||||
if (params.order_type != "buy" || params.product != "BTC" || params.currency != "INR") {
|
if (params.order_type != "buy" || params.product != "BTC" || params.currency != "INR") {
|
||||||
throw new Error("Invalid buy request.");
|
throw new Error("Invalid buy request.");
|
||||||
}
|
}
|
||||||
// "order_type": this.order_type,
|
|
||||||
// "user_flo_address": this.user_flo_address,
|
|
||||||
// "product": this.product,
|
|
||||||
// "currency": this.currency,
|
|
||||||
// "buy_price": this.buy_price,
|
|
||||||
// "buyer_public_key": this.buyer_public_key,
|
|
||||||
// "buyer_key_signature": this.buyer_key_signature,
|
|
||||||
// "order_validator_public_key": this.order_validator_public_key
|
|
||||||
|
|
||||||
//Check buyer's INR balance
|
//Check buyer's INR balance
|
||||||
readDB("cash_balances", params.trader_flo_address, function(res) {
|
readDB("cash_balances", params.trader_flo_address, 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);
|
||||||
let buy_price_btc = parseFloat(params.buy_price);
|
let buy_price_btc = parseFloat(params.buy_price);
|
||||||
if (buyer_cash_balance < buy_price_btc) {
|
if (buyer_cash_balance < buy_price_btc) {
|
||||||
@ -8297,28 +8310,64 @@
|
|||||||
|
|
||||||
if (!isNaN(eqBTC) && typeof eqBTC == "number") {
|
if (!isNaN(eqBTC) && typeof eqBTC == "number") {
|
||||||
eqBTC = parseFloat(eqBTC);
|
eqBTC = parseFloat(eqBTC);
|
||||||
|
let res_btc;
|
||||||
|
|
||||||
readDB("btc_balances", params.trader_flo_address, function(res) {
|
readDB("btc_balances", params.trader_flo_address, function (btc_balances_response) {
|
||||||
if (typeof res == "object" && typeof res.btc_balance == "number" && !NaN(res.btc_balance)) {
|
if (typeof btc_balances_response == "object" && typeof btc_balances_response.btc_balance == "number"
|
||||||
res.btc_balance = parseFloat(res.btc_balance)+eqBTC;
|
&& !isNaN(btc_balances_response.btc_balance)) {
|
||||||
|
btc_balances_response.btc_balance = parseFloat(btc_balances_response.btc_balance) + eqBTC;
|
||||||
|
res_btc = btc_balances_response;
|
||||||
} else {
|
} else {
|
||||||
// The user bought BTC for first time
|
// The user bought BTC for first time
|
||||||
let res = {
|
res_btc = {
|
||||||
trader_flo_address: params.trader_flo_address,
|
trader_flo_address: params.trader_flo_address,
|
||||||
btc_balance: eqBTC
|
btc_balance: eqBTC
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// supernode data query
|
||||||
|
readDB('localbitcoinUser', '00-01', function (user_data) {
|
||||||
|
if (typeof user_data == "object" && typeof user_data.myLocalFLOPrivateKey ==
|
||||||
|
"string" && user_data.myLocalFLOPrivateKey.length > 0) {
|
||||||
|
try {
|
||||||
// Increase BTC balance of buyer with extra eqBTC amount of BTC
|
// Increase BTC balance of buyer with extra eqBTC amount of BTC
|
||||||
updateinDB("btc_balances", res, params.trader_flo_address);
|
updateinDB("btc_balances", res_btc, params.trader_flo_address);
|
||||||
|
|
||||||
// Descrease INR balance of user in cash table
|
// Descrease INR balance of user in cash table
|
||||||
res.cash_balance = buyer_cash_balance - buy_price_btc;
|
let new_cash_balance = buyer_cash_balance - buy_price_btc;
|
||||||
updateinDB("cash_balances", res, params.trader_flo_address);
|
let res_cash = {
|
||||||
|
trader_flo_address: params.trader_flo_address,
|
||||||
|
cash_balance: new_cash_balance
|
||||||
|
}
|
||||||
|
|
||||||
|
updateinDB("cash_balances", res_cash, params.trader_flo_address);
|
||||||
// Add buy oder
|
// Add buy oder
|
||||||
params['id'] = + new Date();
|
params['id'] = +new Date();
|
||||||
|
|
||||||
|
let hashed_data = Crypto.SHA256(JSON.stringify(params));
|
||||||
|
// Signing of the data by Supernode
|
||||||
|
let signed_data = localbitcoinplusplus.wallets.prototype.sign(hashed_data, user_data.myLocalFLOPrivateKey);
|
||||||
|
|
||||||
|
params["data_hash"] = hashed_data;
|
||||||
|
params["supernode_sign"] = signed_data;
|
||||||
|
params["supernodePubKey"] = user_data.myLocalFLOPublicKey;
|
||||||
|
params["status"] = 1;
|
||||||
|
|
||||||
addDB("buyOrders", params);
|
addDB("buyOrders", params);
|
||||||
callback();
|
|
||||||
|
let response_for_client = {
|
||||||
|
"buyOrders_data": params,
|
||||||
|
"btc_balances_data": res_btc,
|
||||||
|
"cash_balances_data": res_cash
|
||||||
|
};
|
||||||
|
|
||||||
|
// Send data for further action
|
||||||
|
callback(response_for_client);
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
callback(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
callback(false);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
throw new Error("Failed to fetch current BTC price.");
|
throw new Error("Failed to fetch current BTC price.");
|
||||||
@ -8334,18 +8383,20 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (params.order_type != "sell" || params.product != "BTC" || params.currency != "INR"
|
if (params.order_type != "sell" || params.product != "BTC" || params.currency != "INR" &&
|
||||||
&& localbitcoinplusplus.master_configurations.validTradingAmount.includes(params.buy_price)) {
|
localbitcoinplusplus.master_configurations.validTradingAmount.includes(params.buy_price)) {
|
||||||
throw new Error("Invalid sell request.");
|
throw new Error("Invalid sell request.");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check BTC balance of the seller
|
// Check BTC balance of the seller
|
||||||
readDB("btc_balances", params.trader_flo_address, function(res) {
|
readDB("btc_balances", params.trader_flo_address, function (res) {
|
||||||
if (typeof res !== "undefined" && typeof res.trader_flo_address == "string" && res.trader_flo_address.length>0
|
if (typeof res !== "undefined" && typeof res.trader_flo_address == "string" && res.trader_flo_address
|
||||||
&& typeof res.btc_balance == "number" && res.btc_balance>0) {
|
.length > 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(sell_price_in_inr);
|
let eqBTC = localbitcoinplusplus.trade.prototype.calculateBTCEquivalentOfCash(
|
||||||
|
sell_price_in_inr);
|
||||||
|
|
||||||
if (!isNaN(eqBTC) && typeof eqBTC == "number") {
|
if (!isNaN(eqBTC) && typeof eqBTC == "number") {
|
||||||
eqBTC = parseFloat(eqBTC);
|
eqBTC = parseFloat(eqBTC);
|
||||||
@ -8354,9 +8405,11 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Increase INR balance of seller
|
// Increase INR balance of seller
|
||||||
readDB("cash_balances", params.trader_flo_address, function(res) {
|
readDB("cash_balances", params.trader_flo_address, function (res) {
|
||||||
if(typeof res == "object" && typeof res.cash_balance == "number" && !isNaN(res.cash_balance)) {
|
if (typeof res == "object" && typeof res.cash_balance == "number" &&
|
||||||
res.cash_balance = parseFloat(res.cash_balance) + sell_price_in_inr;
|
!isNaN(res.cash_balance)) {
|
||||||
|
res.cash_balance = parseFloat(res.cash_balance) +
|
||||||
|
sell_price_in_inr;
|
||||||
} else {
|
} else {
|
||||||
// User got cash for the first time
|
// User got cash for the first time
|
||||||
let res = {
|
let res = {
|
||||||
@ -8371,7 +8424,7 @@
|
|||||||
updateinDB("btc_balances", res, params.trader_flo_address);
|
updateinDB("btc_balances", res, params.trader_flo_address);
|
||||||
|
|
||||||
//Add cash balance
|
//Add cash balance
|
||||||
params['rand_id'] = + new Date();
|
params['rand_id'] = +new Date();
|
||||||
addDB("sellOrders", params);
|
addDB("sellOrders", params);
|
||||||
callback();
|
callback();
|
||||||
});
|
});
|
||||||
@ -8451,7 +8504,7 @@
|
|||||||
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();
|
let current_btc_price = localbitcoinplusplus.trade.prototype.get_current_btc_price_in_fiat.call();
|
||||||
if (current_btc_price > 0) {
|
if (current_btc_price > 0) {
|
||||||
return parseFloat(btc_buy_price/current_btc_price);
|
return parseFloat(btc_buy_price / current_btc_price);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
@ -8461,8 +8514,8 @@
|
|||||||
},
|
},
|
||||||
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`;
|
||||||
helper_functions.ajaxGet(url, function(res) {
|
helper_functions.ajaxGet(url, function (res) {
|
||||||
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") {
|
if (typeof res_object.bpi.INR.rate_float == "number") {
|
||||||
@ -8488,11 +8541,11 @@
|
|||||||
<script>
|
<script>
|
||||||
let helper_functions = {
|
let helper_functions = {
|
||||||
// AJAX Get
|
// AJAX Get
|
||||||
ajaxGet: function(url, callback) {
|
ajaxGet: function (url, callback) {
|
||||||
try {
|
try {
|
||||||
var xhr = new XMLHttpRequest();
|
var xhr = new XMLHttpRequest();
|
||||||
xhr.open('GET', url);
|
xhr.open('GET', url);
|
||||||
xhr.onload = function() {
|
xhr.onload = function () {
|
||||||
if (xhr.status === 200) {
|
if (xhr.status === 200) {
|
||||||
callback(xhr.responseText);
|
callback(xhr.responseText);
|
||||||
} else {
|
} else {
|
||||||
@ -8506,12 +8559,12 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
//AJAX Post
|
//AJAX Post
|
||||||
ajaxPost: function(url, data, callback) {
|
ajaxPost: function (url, data, callback) {
|
||||||
var newName = 'John Smith',
|
var newName = 'John Smith',
|
||||||
xhr = new XMLHttpRequest();
|
xhr = new XMLHttpRequest();
|
||||||
xhr.open('POST', url);
|
xhr.open('POST', url);
|
||||||
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
|
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
|
||||||
xhr.onload = function() {
|
xhr.onload = function () {
|
||||||
if (xhr.status == 200) {
|
if (xhr.status == 200) {
|
||||||
callback();
|
callback();
|
||||||
} else {
|
} else {
|
||||||
@ -8705,8 +8758,8 @@
|
|||||||
|
|
||||||
/* Websocket Code Starts here */
|
/* Websocket Code Starts here */
|
||||||
|
|
||||||
var wsUri = "ws://localhost:9000/";
|
//var wsUri = "ws://localhost:9000/";
|
||||||
//var wsUri = "ws://ranchimall.duckdns.org:9000/";
|
var wsUri = "ws://ranchimall.duckdns.org:9000/";
|
||||||
var output;
|
var output;
|
||||||
|
|
||||||
function init() {
|
function init() {
|
||||||
@ -8746,17 +8799,37 @@
|
|||||||
var res_pos = response.indexOf('{');
|
var res_pos = response.indexOf('{');
|
||||||
if (res_pos >= 0) {
|
if (res_pos >= 0) {
|
||||||
var res = response.substr(res_pos);
|
var res = response.substr(res_pos);
|
||||||
try {var res_obj = JSON.parse(res);
|
try {
|
||||||
|
var res_obj = JSON.parse(res);
|
||||||
if (typeof res_obj.method !== undefined) {
|
if (typeof res_obj.method !== undefined) {
|
||||||
let response_from_sever;
|
let response_from_sever;
|
||||||
switch (res_obj.method) {
|
switch (res_obj.method) {
|
||||||
case "trade_buy":
|
case "trade_buy":
|
||||||
|
|
||||||
response_from_sever = localbitcoinplusplus.rpc.prototype.receive_rpc_response.call(this,
|
response_from_sever = localbitcoinplusplus.rpc.prototype.receive_rpc_response.call(this,
|
||||||
JSON.stringify(res_obj));
|
JSON.stringify(res_obj));
|
||||||
//orderRPC.parse_server_rpc_response(response_from_sever);
|
break;
|
||||||
|
case "trade_buy_request_response":
|
||||||
//doSend(response_from_sever); // send response to client
|
console.log(res_obj.params);
|
||||||
|
if (typeof res_obj.params == "object" && typeof res_obj.params[0] == "object"
|
||||||
|
&& typeof res_obj.params[0].btc_balances_data == "object"
|
||||||
|
&& typeof res_obj.params[0].cash_balances_data == "object"
|
||||||
|
&& typeof res_obj.params[0].buyOrders_data == "object"
|
||||||
|
) {
|
||||||
|
let resp = res_obj.params[0];
|
||||||
|
if (typeof localbitcoinplusplus.master_configurations.supernodesPubKeys == "object"
|
||||||
|
&& localbitcoinplusplus.master_configurations.supernodesPubKeys.includes(resp.buyOrders_data.supernodePubKey)) {
|
||||||
|
let isDataSignedBySuperNode = localbitcoinplusplus.wallets.prototype
|
||||||
|
.verify(resp.buyOrders_data.data_hash, resp.buyOrders_data.supernode_sign, resp.buyOrders_data.supernodePubKey);
|
||||||
|
if (isDataSignedBySuperNode === true) {
|
||||||
|
// Increase BTC balance of buyer with extra eqBTC amount of BTC
|
||||||
|
updateinDB("btc_balances", resp.btc_balances_data, resp.btc_balances_data.trader_flo_address);
|
||||||
|
// Descrease INR balance of user in cash table
|
||||||
|
updateinDB("cash_balances", resp.cash_balances_data, resp.cash_balances_data.trader_flo_address);
|
||||||
|
// Add buy order
|
||||||
|
addDB("buyOrders", resp.buyOrders_data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case "trade_sell":
|
case "trade_sell":
|
||||||
response_from_sever = localbitcoinplusplus.rpc.prototype.receive_rpc_response.call(this,
|
response_from_sever = localbitcoinplusplus.rpc.prototype.receive_rpc_response.call(this,
|
||||||
@ -8777,7 +8850,8 @@
|
|||||||
//doSend(JSON.stringify(response_from_sever)); // send response to client
|
//doSend(JSON.stringify(response_from_sever)); // send response to client
|
||||||
case "deposit_asset_request_response":
|
case "deposit_asset_request_response":
|
||||||
console.log(res_obj);
|
console.log(res_obj);
|
||||||
if (typeof res_obj.params == "object" && typeof res_obj.params[0] == "object" && typeof res_obj.params[0].data == "object") {
|
if (typeof res_obj.params == "object" && typeof res_obj.params[0] == "object" && typeof res_obj
|
||||||
|
.params[0].data == "object") {
|
||||||
addDB('deposit', res_obj.params[0].data);
|
addDB('deposit', res_obj.params[0].data);
|
||||||
let counterTraderAccountAddress =
|
let counterTraderAccountAddress =
|
||||||
`<p><strong>Please pay the amount to following address:</strong></p>
|
`<p><strong>Please pay the amount to following address:</strong></p>
|
||||||
@ -8787,7 +8861,8 @@
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "withdraw_request_method":
|
case "withdraw_request_method":
|
||||||
response_from_sever = localbitcoinplusplus.rpc.prototype.receive_rpc_response.call(this, JSON.stringify(res_obj));
|
response_from_sever = localbitcoinplusplus.rpc.prototype.receive_rpc_response.call(this,
|
||||||
|
JSON.stringify(res_obj));
|
||||||
doSend(JSON.stringify(response_from_sever)); // send response to client
|
doSend(JSON.stringify(response_from_sever)); // send response to client
|
||||||
break;
|
break;
|
||||||
case "withdrawal_request_response":
|
case "withdrawal_request_response":
|
||||||
@ -8874,34 +8949,8 @@
|
|||||||
blockSignature: ""
|
blockSignature: ""
|
||||||
};
|
};
|
||||||
|
|
||||||
let buyList = {
|
|
||||||
id: "",
|
|
||||||
trader_flo_address: null,
|
|
||||||
buy_price: null,
|
|
||||||
buyer_key_signature: null,
|
|
||||||
buyer_public_key: null,
|
|
||||||
currency: null,
|
|
||||||
order_type: null,
|
|
||||||
order_validator_public_key: null,
|
|
||||||
product: null,
|
|
||||||
status: 0
|
|
||||||
};
|
|
||||||
|
|
||||||
let sellList = {
|
|
||||||
id: "",
|
|
||||||
trader_flo_address: null,
|
|
||||||
sell_price: null,
|
|
||||||
seller_key_signature: null,
|
|
||||||
seller_public_key: null,
|
|
||||||
currency: null,
|
|
||||||
order_type: null,
|
|
||||||
order_validator_public_key: null,
|
|
||||||
product: null,
|
|
||||||
status: 0
|
|
||||||
};
|
|
||||||
|
|
||||||
const deposit = {
|
const deposit = {
|
||||||
id:"",
|
id: "",
|
||||||
trader_flo_address: null,
|
trader_flo_address: null,
|
||||||
depositing_amount: 0,
|
depositing_amount: 0,
|
||||||
depositor_key_signature: null,
|
depositor_key_signature: null,
|
||||||
@ -8956,40 +9005,70 @@
|
|||||||
request.onupgradeneeded = function (event) {
|
request.onupgradeneeded = function (event) {
|
||||||
var db = event.target.result;
|
var db = event.target.result;
|
||||||
if (!db.objectStoreNames.contains('localbitcoinUser')) {
|
if (!db.objectStoreNames.contains('localbitcoinUser')) {
|
||||||
var objectStore = db.createObjectStore("localbitcoinUser", {keyPath: "id"});
|
var objectStore = db.createObjectStore("localbitcoinUser", {
|
||||||
objectStore.createIndex('myLocalFLOAddress', 'myLocalFLOAddress', { unique: false });
|
keyPath: "id"
|
||||||
|
});
|
||||||
|
objectStore.createIndex('myLocalFLOAddress', 'myLocalFLOAddress', {
|
||||||
|
unique: false
|
||||||
|
});
|
||||||
objectStore.put(localbitcoinplusplusObj);
|
objectStore.put(localbitcoinplusplusObj);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!db.objectStoreNames.contains('datablocks')) {
|
if (!db.objectStoreNames.contains('datablocks')) {
|
||||||
var objectStore = db.createObjectStore("datablocks", {keyPath: "id"});
|
var objectStore = db.createObjectStore("datablocks", {
|
||||||
|
keyPath: "id"
|
||||||
|
});
|
||||||
objectStore.put(dataBlock);
|
objectStore.put(dataBlock);
|
||||||
}
|
}
|
||||||
if (!db.objectStoreNames.contains('buyOrders')) {
|
if (!db.objectStoreNames.contains('buyOrders')) {
|
||||||
var objectStore = db.createObjectStore("buyOrders", {keyPath: 'id'});
|
var objectStore = db.createObjectStore("buyOrders", {
|
||||||
objectStore.createIndex('trader_flo_address', 'trader_flo_address', { unique: false });
|
keyPath: 'id'
|
||||||
|
});
|
||||||
|
objectStore.createIndex('trader_flo_address', 'trader_flo_address', {
|
||||||
|
unique: false
|
||||||
|
});
|
||||||
}
|
}
|
||||||
if (!db.objectStoreNames.contains('sellOrders')) {
|
if (!db.objectStoreNames.contains('sellOrders')) {
|
||||||
var objectStore = db.createObjectStore("sellOrders", {keyPath: 'id'});
|
var objectStore = db.createObjectStore("sellOrders", {
|
||||||
objectStore.createIndex('trader_flo_address', 'trader_flo_address', { unique: false });
|
keyPath: 'id'
|
||||||
|
});
|
||||||
|
objectStore.createIndex('trader_flo_address', 'trader_flo_address', {
|
||||||
|
unique: false
|
||||||
|
});
|
||||||
}
|
}
|
||||||
if (!db.objectStoreNames.contains('deposit')) {
|
if (!db.objectStoreNames.contains('deposit')) {
|
||||||
var objectStore = db.createObjectStore("deposit", {keyPath: 'id'});
|
var objectStore = db.createObjectStore("deposit", {
|
||||||
objectStore.createIndex('trader_flo_address', 'trader_flo_address', { unique: false });
|
keyPath: 'id'
|
||||||
|
});
|
||||||
|
objectStore.createIndex('trader_flo_address', 'trader_flo_address', {
|
||||||
|
unique: false
|
||||||
|
});
|
||||||
}
|
}
|
||||||
if (!db.objectStoreNames.contains('withdraw_cash')) {
|
if (!db.objectStoreNames.contains('withdraw_cash')) {
|
||||||
var objectStore = db.createObjectStore("withdraw_cash", {keyPath: 'id'});
|
var objectStore = db.createObjectStore("withdraw_cash", {
|
||||||
objectStore.createIndex('trader_flo_address', 'trader_flo_address', { unique: true });
|
keyPath: 'id'
|
||||||
|
});
|
||||||
|
objectStore.createIndex('trader_flo_address', 'trader_flo_address', {
|
||||||
|
unique: true
|
||||||
|
});
|
||||||
}
|
}
|
||||||
if (!db.objectStoreNames.contains('btc_balances')) {
|
if (!db.objectStoreNames.contains('btc_balances')) {
|
||||||
var objectStore = db.createObjectStore("btc_balances", {keyPath: 'trader_flo_address'});
|
var objectStore = db.createObjectStore("btc_balances", {
|
||||||
|
keyPath: 'trader_flo_address'
|
||||||
|
});
|
||||||
}
|
}
|
||||||
if (!db.objectStoreNames.contains('cash_balances')) {
|
if (!db.objectStoreNames.contains('cash_balances')) {
|
||||||
var objectStore = db.createObjectStore("cash_balances", {keyPath: 'trader_flo_address'});
|
var objectStore = db.createObjectStore("cash_balances", {
|
||||||
|
keyPath: 'trader_flo_address'
|
||||||
|
});
|
||||||
}
|
}
|
||||||
if (!db.objectStoreNames.contains('system_btc_reserves')) {
|
if (!db.objectStoreNames.contains('system_btc_reserves')) {
|
||||||
var objectStore = db.createObjectStore("system_btc_reserves", {keyPath: 'btc_address'});
|
var objectStore = db.createObjectStore("system_btc_reserves", {
|
||||||
objectStore.createIndex('trader_flo_address', 'trader_flo_address', { unique: false });
|
keyPath: 'btc_address'
|
||||||
|
});
|
||||||
|
objectStore.createIndex('trader_flo_address', 'trader_flo_address', {
|
||||||
|
unique: false
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -9099,11 +9178,11 @@
|
|||||||
// Fetch the current BTC price in INR
|
// Fetch the current BTC price in INR
|
||||||
try {
|
try {
|
||||||
RM_TRADE.set_current_btc_price_in_fiat('INR');
|
RM_TRADE.set_current_btc_price_in_fiat('INR');
|
||||||
setInterval(function() {
|
setInterval(function () {
|
||||||
RM_TRADE.set_current_btc_price_in_fiat('INR');
|
RM_TRADE.set_current_btc_price_in_fiat('INR');
|
||||||
}, 1800000);
|
}, 1800000);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
throw new Error('Failed to fetch current Bitcoin price: '+ e);
|
throw new Error('Failed to fetch current Bitcoin price: ' + e);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fetch configs from Master Key
|
// Fetch configs from Master Key
|
||||||
@ -9173,24 +9252,14 @@
|
|||||||
buyul.onclick = function (event) {
|
buyul.onclick = function (event) {
|
||||||
let target = getEventTarget(event);
|
let target = getEventTarget(event);
|
||||||
let intAmount = parseFloat(target.innerHTML.match(/\d+/)[0]); // Amount of INR/BTC/whatever in integer
|
let intAmount = parseFloat(target.innerHTML.match(/\d+/)[0]); // Amount of INR/BTC/whatever in integer
|
||||||
let signing_object = {
|
if (typeof idbData.myLocalFLOAddress !== "string" || idbData.myLocalFLOAddress
|
||||||
flo_address: idbData.myLocalFLOAddress,
|
|
||||||
order_type: "buy",
|
|
||||||
trading_product: "BTC",
|
|
||||||
currency: "INR",
|
|
||||||
tradingAmount: intAmount
|
|
||||||
};
|
|
||||||
// Get private key here
|
|
||||||
//let trader_signature = RM_WALLET.sign(JSON.stringify(signing_object), privateKeyWIF);
|
|
||||||
|
|
||||||
if (typeof idbData.myLocalFLOAddress == undefined || idbData.myLocalFLOAddress
|
|
||||||
.trim() == "") {
|
.trim() == "") {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
"You must have a BTC address to receive Bitcoin. No Bitcoin address found in database."
|
"You must have a BTC address to receive Bitcoin. No Bitcoin address found in database."
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
let buytrade = RM_TRADE.place_order("buy", idbData.myLocalFLOAddress, "BTC", "INR", intAmount, idbData.myLocalFLOPublicKey,
|
let buytrade = RM_TRADE.place_order("buy", idbData.myLocalFLOAddress,
|
||||||
"trader_signature", "order_validator_public_key");
|
"BTC", "INR", intAmount);
|
||||||
doSend(buytrade);
|
doSend(buytrade);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -9202,11 +9271,9 @@
|
|||||||
"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 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,
|
||||||
null, "BTC", "INR", intAmount, idbData.myLocalFLOPublicKey,
|
"BTC", "INR", intAmount);
|
||||||
"trader_signature", "order_validator_public_key");
|
|
||||||
doSend(selltrade);
|
doSend(selltrade);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -9352,7 +9419,7 @@
|
|||||||
asset_box.appendChild(depositAssetButton);
|
asset_box.appendChild(depositAssetButton);
|
||||||
asset_box.appendChild(withdrawAssetButton);
|
asset_box.appendChild(withdrawAssetButton);
|
||||||
|
|
||||||
depositAssetButton.addEventListener('click', function() {
|
depositAssetButton.addEventListener('click', function () {
|
||||||
let asset_type = assetTypeInput.value;
|
let asset_type = assetTypeInput.value;
|
||||||
let tradeAmount = parseFloat(tradeAmountSelect.value);
|
let tradeAmount = parseFloat(tradeAmountSelect.value);
|
||||||
if (typeof userFLOaddress == undefined || userFLOaddress.trim().length < 1) {
|
if (typeof userFLOaddress == undefined || userFLOaddress.trim().length < 1) {
|
||||||
@ -9368,10 +9435,12 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
withdrawAssetButton.addEventListener('click', function(params) {
|
withdrawAssetButton.addEventListener('click', function (params) {
|
||||||
let receivinAddress = prompt("Please enter a Bitcoin address or full bank details.");
|
let receivinAddress = prompt("Please enter a Bitcoin address or full bank details.");
|
||||||
if (receivinAddress.trim == "") {
|
if (receivinAddress.trim == "") {
|
||||||
alert("You must specify either a Bitcoin address to withdraw Bitcoin or your bank detail to withdraw cash.");
|
alert(
|
||||||
|
"You must specify either a Bitcoin address to withdraw Bitcoin or your bank detail to withdraw cash."
|
||||||
|
);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -9412,13 +9481,13 @@
|
|||||||
|
|
||||||
<!-- Misc functions -->
|
<!-- Misc functions -->
|
||||||
<script>
|
<script>
|
||||||
function rand(a,b, multiple) {
|
function rand(a, b, multiple) {
|
||||||
return Math.floor(Math.random(a, b) * multiple);
|
return Math.floor(Math.random(a, b) * multiple);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Function to check if user is currently involved in any operation
|
//Function to check if user is currently involved in any operation
|
||||||
function isUserAlreadyTrading(usersFloAddress) {
|
function isUserAlreadyTrading(usersFloAddress) {
|
||||||
let userCurrentBuyOrder = readAllDB("buyOrders", function(buyList) {
|
let userCurrentBuyOrder = readAllDB("buyOrders", function (buyList) {
|
||||||
console.log(buyList);
|
console.log(buyList);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -9429,16 +9498,17 @@
|
|||||||
try {
|
try {
|
||||||
//let url = `https://blockchain.info/q/addressbalance/${BTCAddress}?confirmations=6`;
|
//let url = `https://blockchain.info/q/addressbalance/${BTCAddress}?confirmations=6`;
|
||||||
let url = `https://testnet.flocha.in/api/addr/${trader_deposits.btc_address}/balance`;
|
let url = `https://testnet.flocha.in/api/addr/${trader_deposits.btc_address}/balance`;
|
||||||
helper_functions.ajaxGet(url, function(balance) {
|
helper_functions.ajaxGet(url, function (balance) {
|
||||||
console.log(balance);
|
console.log(balance);
|
||||||
|
|
||||||
if (!isNaN(balance) && parseFloat(balance) > 0) {
|
if (!isNaN(balance) && parseFloat(balance) > 0) {
|
||||||
balance = parseFloat(balance);
|
balance = parseFloat(balance);
|
||||||
|
|
||||||
/************************ Case of dispute *****************/
|
/************************ Case of dispute *****************/
|
||||||
if(false) {
|
if (false) {
|
||||||
//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.btcTradeMargin);
|
console.log(trader_deposits.bitcoinToBePaid - balance, localbitcoinplusplus.master_configurations
|
||||||
|
.btcTradeMargin);
|
||||||
|
|
||||||
trader_deposits.status = 3; // User sent less BTC than he should #Disputed
|
trader_deposits.status = 3; // User sent less BTC than he should #Disputed
|
||||||
updateinDB("deposit", trader_deposits, trader_flo_address);
|
updateinDB("deposit", trader_deposits, trader_flo_address);
|
||||||
@ -9449,7 +9519,7 @@
|
|||||||
updateinDB("deposit", trader_deposits, trader_deposits.trader_flo_address);
|
updateinDB("deposit", trader_deposits, trader_deposits.trader_flo_address);
|
||||||
|
|
||||||
let updateSystemBTCreserve = {
|
let updateSystemBTCreserve = {
|
||||||
id: + new Date(),
|
id: +new Date(),
|
||||||
btc_address: trader_deposits.btc_address,
|
btc_address: trader_deposits.btc_address,
|
||||||
balance: balance,
|
balance: balance,
|
||||||
trader_flo_address: trader_deposits.trader_flo_address
|
trader_flo_address: trader_deposits.trader_flo_address
|
||||||
@ -9461,8 +9531,10 @@
|
|||||||
trader_flo_address: trader_deposits.trader_flo_address,
|
trader_flo_address: trader_deposits.trader_flo_address,
|
||||||
btc_balance: balance
|
btc_balance: balance
|
||||||
}
|
}
|
||||||
readDB('btc_balances', trader_deposits.trader_flo_address, function(res_btc_balances) {
|
readDB('btc_balances', trader_deposits.trader_flo_address, function (
|
||||||
if (typeof res_btc_balances=="object" && typeof res_btc_balances.btc_balance == "number") {
|
res_btc_balances) {
|
||||||
|
if (typeof res_btc_balances == "object" && typeof res_btc_balances.btc_balance ==
|
||||||
|
"number") {
|
||||||
updatedBTCbalances.btc_balance += parseFloat(res_btc_balances.btc_balance);
|
updatedBTCbalances.btc_balance += parseFloat(res_btc_balances.btc_balance);
|
||||||
}
|
}
|
||||||
// Update BTC balance of user in btc_balances
|
// Update BTC balance of user in btc_balances
|
||||||
@ -9476,9 +9548,9 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
setInterval(function() {
|
setInterval(function () {
|
||||||
readDBbyIndex("deposit", 'status', 1, function(res) {
|
readDBbyIndex("deposit", 'status', 1, function (res) {
|
||||||
res.map(function(deposit_trade) { // deposit_trade.trader_flo_address, deposit_trade.btc_address, deposit_trade.bitcoinToBePaid
|
res.map(function (deposit_trade) { // deposit_trade.trader_flo_address, deposit_trade.btc_address, deposit_trade.bitcoinToBePaid
|
||||||
if (deposit_trade.product == "BTC") {
|
if (deposit_trade.product == "BTC") {
|
||||||
validateDepositedBTCBalance(deposit_trade);
|
validateDepositedBTCBalance(deposit_trade);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user