added autoupdate external scripts feature
This commit is contained in:
parent
4811e9e8b1
commit
402e0ab6fb
@ -9104,10 +9104,13 @@
|
|||||||
// remove this line later
|
// remove this line later
|
||||||
// btcTradeMargin is tolerable difference between Crypto trader should deposit and cryptos he actually deposited
|
// btcTradeMargin is tolerable difference between Crypto trader should deposit and cryptos he actually deposited
|
||||||
RMAssets =
|
RMAssets =
|
||||||
`tradableAsset1=BTC,FLO,BTC_TEST,FLO_TEST#!#tradableAsset2=INR,USD,BTC,FLO,BTC_TEST,FLO_TEST#!#supernodes=127.0.0.1,212.88.88.2#!#MASTER_NODE=023B9F60692A17FAC805D012C5C8ADA3DD19A980A3C5F0D8A5B3500CC54D6E8B75
|
`tradableAsset1=BTC,FLO,BTC_TEST,FLO_TEST#!#tradableAsset2=INR,USD,BTC,FLO,BTC_TEST,FLO_TEST
|
||||||
|
#!#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=033038E5F9A9CD59F21E4E1577BAC732DF7F4988634CF1ADE2EB74FC512689FC27,038C6D5C0DF3AA49501C20DD8333F9F67A854E87AA639A688FAE4F434718F2792D,
|
#!#supernodesPubKeys=02BCBC8186CE5E978BCBC6B70F6CAD8FED936A725FEF377EFE4A56AD6E6D4E8392,
|
||||||
#!#d3js=58f54395efa8346e8e94d12609770f66b916897e7f4e05f6c98780cffa5c70a3#!#ShamirsMaxShares=8`;
|
#!#externalFiles={"testjs":"bebabf9b08571c23064b35c25850fdbc004044779af58f6327e3b316410f5884",
|
||||||
|
"d3js":"58f54395efa8346e8e94d12609770f66b916897e7f4e05f6c98780cffa5c70a3"}
|
||||||
|
#!#ShamirsMaxShares=8`;
|
||||||
let floAssetsArray = RMAssets.split('#!#');
|
let floAssetsArray = RMAssets.split('#!#');
|
||||||
|
|
||||||
if (floAssetsArray.length > 0 && typeof floAssetsArray[0] !== undefined &&
|
if (floAssetsArray.length > 0 && typeof floAssetsArray[0] !== undefined &&
|
||||||
@ -9554,7 +9557,7 @@
|
|||||||
|
|
||||||
let publicKey_for_users_entered_private_key;
|
let publicKey_for_users_entered_private_key;
|
||||||
try {
|
try {
|
||||||
publicKey_for_users_entered_private_key = RM_WALLET.generateFloKeys(users_entered_private_key).pubKeyHex;
|
publicKey_for_users_entered_private_key = localbitcoinplusplus.wallets.prototype.generateFloKeys(users_entered_private_key).pubKeyHex;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new Error(error);
|
throw new Error(error);
|
||||||
}
|
}
|
||||||
@ -10032,232 +10035,234 @@
|
|||||||
await localbitcoinplusplus.trade.prototype.resolve_current_crypto_price_in_fiat(params.product, params.currency);
|
await localbitcoinplusplus.trade.prototype.resolve_current_crypto_price_in_fiat(params.product, params.currency);
|
||||||
let trade_margin = await localbitcoinplusplus.trade.prototype.getAssetTradeAndWithdrawLimit(params.trader_flo_address, params.product, params.currency);
|
let trade_margin = await localbitcoinplusplus.trade.prototype.getAssetTradeAndWithdrawLimit(params.trader_flo_address, params.product, params.currency);
|
||||||
|
|
||||||
if (localbitcoinplusplus.master_configurations.tradableAsset1.includes(params.product)) {
|
if (localbitcoinplusplus.master_configurations.tradableAsset1.includes(params.product)) {
|
||||||
let eqCrypto = localbitcoinplusplus.trade.prototype.calculateCryptoEquivalentOfCash(params.withdrawing_amount);
|
let eqCrypto = localbitcoinplusplus.trade.prototype.calculateCryptoEquivalentOfCash(params.withdrawing_amount);
|
||||||
if (trade_margin.remaining_crypto_credit<0 && trade_margin.remaining_crypto_credit<eqCrypto) {
|
if (trade_margin.remaining_crypto_credit<0 && trade_margin.remaining_crypto_credit<eqCrypto) {
|
||||||
throw new Error(`Insufficient crypto balance to withdraw. You can withdraw upto: ${params.product} ${trade_margin.remaining_crypto_credit}`);
|
throw new Error(`Insufficient crypto balance to withdraw. You can withdraw upto: ${params.product} ${trade_margin.remaining_crypto_credit}`);
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (trade_margin.remaining_fiat_credit<0 && trade_margin.remaining_fiat_credit<params.withdrawing_amount) {
|
|
||||||
throw new Error(`Insufficient fiat balance to withdraw. You can withdraw upto: ${params.currency} ${trade_margin.remaining_fiat_credit}`);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
if (trade_margin.remaining_fiat_credit<0 && trade_margin.remaining_fiat_credit<params.withdrawing_amount) {
|
||||||
|
throw new Error(`Insufficient fiat balance to withdraw. You can withdraw upto: ${params.currency} ${trade_margin.remaining_fiat_credit}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
params.id = helper_functions.unique_id();
|
params.id = helper_functions.unique_id();
|
||||||
params.status = 1;
|
params.status = 1;
|
||||||
if (localbitcoinplusplus.master_configurations.tradableAsset1.includes(params.product)) {
|
if (localbitcoinplusplus.master_configurations.tradableAsset1.includes(params.product)) {
|
||||||
// Check how much cryptos the user can withdraw
|
// Check how much cryptos the user can withdraw
|
||||||
let withdrawer_btc_id = `${params.trader_flo_address}_${params.product}`;
|
let withdrawer_btc_id = `${params.trader_flo_address}_${params.product}`;
|
||||||
readDB("crypto_balances", withdrawer_btc_id).then(function (btc_balance_res) {
|
readDB("crypto_balances", withdrawer_btc_id).then(function (btc_balance_res) {
|
||||||
if (typeof btc_balance_res == "object" && typeof btc_balance_res
|
if (typeof btc_balance_res == "object" && typeof btc_balance_res
|
||||||
.trader_flo_address == "string" &&
|
.trader_flo_address == "string" &&
|
||||||
btc_balance_res.crypto_balance > 0) {
|
btc_balance_res.crypto_balance > 0) {
|
||||||
let withdrawer_btc_balance = parseFloat(btc_balance_res.crypto_balance);
|
let withdrawer_btc_balance = parseFloat(btc_balance_res.crypto_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)) {
|
if(!localbitcoinplusplus.master_configurations.tradableAsset2.includes(params.currency)) {
|
||||||
throw new Error("Invalid or unsupported currency.");
|
throw new Error("Invalid or unsupported currency.");
|
||||||
}
|
}
|
||||||
let eqBTC = localbitcoinplusplus.trade.prototype.calculateCryptoEquivalentOfCash(
|
let eqBTC = localbitcoinplusplus.trade.prototype.calculateCryptoEquivalentOfCash(
|
||||||
withdrawing_btc_amount_in_cash, params.currency, params.product);
|
withdrawing_btc_amount_in_cash, params.currency, params.product);
|
||||||
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_new_btc_balance > 0 &&
|
if (withdrawer_new_btc_balance > 0 &&
|
||||||
withdrawer_btc_balance > 0 &&
|
withdrawer_btc_balance > 0 &&
|
||||||
withdrawing_btc_amount_in_cash > 0 &&
|
withdrawing_btc_amount_in_cash > 0 &&
|
||||||
eqBTC > 0 && eqBTC <= withdrawer_btc_balance) {
|
eqBTC > 0 && eqBTC <= withdrawer_btc_balance) {
|
||||||
|
|
||||||
// Now details of Bitcoins can be sent to withdrawer
|
// Now details of Bitcoins can be sent to withdrawer
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
***********IMPORTANT: CHANGE RECEIVING ADDRESS TO BTC THAN FLO HERE**********
|
***********IMPORTANT: CHANGE RECEIVING ADDRESS TO BTC THAN FLO HERE**********
|
||||||
***********AND DO SOMETHING ABOUT PRIVATE KEY BELOW**************************
|
***********AND DO SOMETHING ABOUT PRIVATE KEY BELOW**************************
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
let sum_total_btc = 0;
|
let sum_total_btc = 0;
|
||||||
let valid_utxo_list = [];
|
let valid_utxo_list = [];
|
||||||
let receiverBTCAddress = params.receivinAddress
|
let receiverBTCAddress = params.receivinAddress
|
||||||
.trim();
|
.trim();
|
||||||
|
|
||||||
readAllDB("deposit").then(function (deposit_list) {
|
readAllDB("deposit").then(function (deposit_list) {
|
||||||
if (typeof deposit_list == "object" &&
|
if (typeof deposit_list == "object" &&
|
||||||
deposit_list.length > 0) {
|
deposit_list.length > 0) {
|
||||||
deposit_list = deposit_list.filter(
|
deposit_list = deposit_list.filter(
|
||||||
deposits => deposits.status == 2
|
deposits => deposits.status == 2
|
||||||
&& localbitcoinplusplus.master_configurations.tradableAsset1.includes(deposits.product)
|
&& localbitcoinplusplus.master_configurations.tradableAsset1.includes(deposits.product)
|
||||||
&& params.product==deposits.product);
|
&& params.product==deposits.product);
|
||||||
for (const dl in deposit_list) {
|
for (const dl in deposit_list) {
|
||||||
if (deposit_list.hasOwnProperty(dl)) {
|
if (deposit_list.hasOwnProperty(dl)) {
|
||||||
const deposit_dl = deposit_list[dl];
|
const deposit_dl = deposit_list[dl];
|
||||||
sum_total_btc += parseFloat(deposit_dl.bitcoinToBePaid);
|
sum_total_btc += parseFloat(deposit_dl.bitcoinToBePaid);
|
||||||
|
|
||||||
if (eqBTC <= sum_total_btc) {
|
if (eqBTC <= sum_total_btc) {
|
||||||
valid_utxo_list.push(deposit_dl);
|
valid_utxo_list.push(deposit_dl);
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
valid_utxo_list.push(deposit_dl);
|
valid_utxo_list.push(deposit_dl);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let valid_btc_list = valid_utxo_list.map(deposit_arr => {
|
}
|
||||||
deposit_arr.status = 3 // Deposited Bitcoin is under process
|
let valid_btc_list = valid_utxo_list.map(deposit_arr => {
|
||||||
updateinDB("deposit", deposit_arr, deposit_arr.trader_flo_address);
|
deposit_arr.status = 3 // Deposited Bitcoin is under process
|
||||||
|
updateinDB("deposit", deposit_arr, deposit_arr.trader_flo_address);
|
||||||
// save the address and id in a table
|
|
||||||
let withdraw_id = helper_functions.unique_id();
|
// save the address and id in a table
|
||||||
const withdraw_btc_order_object = {
|
let withdraw_id = helper_functions.unique_id();
|
||||||
id: withdraw_id,
|
const withdraw_btc_order_object = {
|
||||||
trader_flo_address: params.trader_flo_address,
|
id: withdraw_id,
|
||||||
utxo_addr: deposit_arr.btc_address,
|
trader_flo_address: params.trader_flo_address,
|
||||||
receiverBTCAddress: params.receivinAddress,
|
utxo_addr: deposit_arr.btc_address,
|
||||||
receiverBTCEquivalentInCash: withdrawing_btc_amount_in_cash,
|
receiverBTCAddress: params.receivinAddress,
|
||||||
currency: params.currency,
|
receiverBTCEquivalentInCash: withdrawing_btc_amount_in_cash,
|
||||||
product: params.product,
|
currency: params.currency,
|
||||||
change_adress:deposit_arr.btc_address,
|
product: params.product,
|
||||||
timestamp: + new Date()
|
change_adress:deposit_arr.btc_address,
|
||||||
}
|
timestamp: + new Date()
|
||||||
addDB('withdraw_btc', withdraw_btc_order_object);
|
}
|
||||||
return {withdraw_id:withdraw_id, deposited_btc_address:deposit_arr.btc_address};
|
addDB('withdraw_btc', withdraw_btc_order_object);
|
||||||
});
|
return {withdraw_id:withdraw_id, deposited_btc_address:deposit_arr.btc_address};
|
||||||
|
});
|
||||||
// doSend btc_private_key_shamirs_id from system_btc_reserves_private_keys
|
|
||||||
valid_btc_list.map(vbl=>{
|
// doSend btc_private_key_shamirs_id from system_btc_reserves_private_keys
|
||||||
readDBbyIndex('system_btc_reserves_private_keys', 'btc_address', vbl.deposited_btc_address).then(function(res) {
|
valid_btc_list.map(vbl=>{
|
||||||
let retrieve_pvtkey_req_id = res[0].id;
|
readDBbyIndex('system_btc_reserves_private_keys', 'btc_address', vbl.deposited_btc_address).then(function(res) {
|
||||||
res[0].btc_private_key_shamirs_id.map(bpks=>{
|
let retrieve_pvtkey_req_id = res[0].id;
|
||||||
let retrieve_pvtkey_req = localbitcoinplusplus.rpc.prototype
|
res[0].btc_private_key_shamirs_id.map(bpks=>{
|
||||||
.send_rpc
|
let retrieve_pvtkey_req = localbitcoinplusplus.rpc.prototype
|
||||||
.call(this, "send_back_shamirs_secret_btc_pvtkey",
|
.send_rpc
|
||||||
{ retrieve_pvtkey_req_id:retrieve_pvtkey_req_id,
|
.call(this, "send_back_shamirs_secret_btc_pvtkey",
|
||||||
chunk_val:bpks,
|
{ retrieve_pvtkey_req_id:retrieve_pvtkey_req_id,
|
||||||
withdraw_id:vbl.withdraw_id
|
chunk_val:bpks,
|
||||||
});
|
withdraw_id:vbl.withdraw_id
|
||||||
doSend(retrieve_pvtkey_req);
|
});
|
||||||
});
|
doSend(retrieve_pvtkey_req);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
});
|
||||||
}
|
|
||||||
});
|
}
|
||||||
|
});
|
||||||
|
|
||||||
} else {
|
|
||||||
// Return error to the requester
|
|
||||||
return {
|
|
||||||
error: true,
|
|
||||||
method: "withdrawal_request_response",
|
|
||||||
data: "Withdrawal request failed: You are trying to withdraw more Bitcoins than you have."
|
|
||||||
};
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
|
console.error(`Withdrawal request failed: You are trying to withdraw more Bitcoins than you have.`);
|
||||||
|
|
||||||
// Return error to the requester
|
// Return error to the requester
|
||||||
return {
|
return {
|
||||||
error: true,
|
error: true,
|
||||||
method: "withdrawal_request_response",
|
method: "withdrawal_request_response",
|
||||||
data: `Withdrawal request failed: You don't seem to have any Bitcoin balance in the system yet.
|
data: "Withdrawal request failed: You are trying to withdraw more Bitcoins than you have."
|
||||||
Please buy some Bitcoins to withdraw.`
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
});
|
} else {
|
||||||
} else if (!localbitcoinplusplus.master_configurations.tradableAsset1.includes(params.product)) {
|
console.error(`Withdrawal request failed: You don't seem to have any Bitcoin balance in the system yet.
|
||||||
// Check if there's no already a withdraw cash order of this user
|
Please buy some Bitcoins to withdraw.`);
|
||||||
/*ONLY DELETE A WITHDRAW ORDER WHEN A DEPOSITOR HAS CONFIRMED DEPOSIT
|
|
||||||
AND RECEIVER HAS CONFIRMED WITHDRAW*/
|
// Return error to the requester
|
||||||
|
return {
|
||||||
|
error: true,
|
||||||
|
method: "withdrawal_request_response",
|
||||||
|
data: `Withdrawal request failed: You don't seem to have any Bitcoin balance in the system yet.
|
||||||
|
Please buy some Bitcoins to withdraw.`
|
||||||
|
};
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else if (!localbitcoinplusplus.master_configurations.tradableAsset1.includes(params.product)) {
|
||||||
|
// Check if there's no already a withdraw cash order of this user
|
||||||
|
/*ONLY DELETE A WITHDRAW ORDER WHEN A DEPOSITOR HAS CONFIRMED DEPOSIT
|
||||||
|
AND RECEIVER HAS CONFIRMED WITHDRAW*/
|
||||||
|
|
||||||
// Check how much Cash user can withdraw
|
// Check how much Cash user can withdraw
|
||||||
const trader_cash_id = `${params.trader_flo_address}_${params.currency}`;
|
const trader_cash_id = `${params.trader_flo_address}_${params.currency}`;
|
||||||
readDB("cash_balances", trader_cash_id).then(function (
|
readDB("cash_balances", trader_cash_id).then(function (
|
||||||
cash_balances_res) {
|
cash_balances_res) {
|
||||||
if (typeof cash_balances_res == "object" && typeof cash_balances_res
|
if (typeof cash_balances_res == "object" && typeof cash_balances_res
|
||||||
.trader_flo_address == "string" &&
|
.trader_flo_address == "string" &&
|
||||||
typeof cash_balances_res.cash_balance == "number" &&
|
typeof cash_balances_res.cash_balance == "number" &&
|
||||||
cash_balances_res.cash_balance > 0) {
|
cash_balances_res.cash_balance > 0) {
|
||||||
let withdrawer_cash_balance = parseFloat(cash_balances_res.cash_balance);
|
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 &&
|
if (withdrawer_cash_balance > 0 &&
|
||||||
withdrawing_cash_amount > 0 &&
|
withdrawing_cash_amount > 0 &&
|
||||||
withdrawer_cash_balance >=
|
withdrawer_cash_balance >=
|
||||||
withdrawing_cash_amount) {
|
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: helper_functions.unique_id(),
|
id: helper_functions.unique_id(),
|
||||||
trader_flo_address: params.trader_flo_address,
|
trader_flo_address: params.trader_flo_address,
|
||||||
withdraw_amount: withdrawing_cash_amount,
|
withdraw_amount: withdrawing_cash_amount,
|
||||||
currency: params.currency,
|
currency: params.currency,
|
||||||
receivinAddress: bank_details,
|
receivinAddress: bank_details,
|
||||||
status: 1 // withdraw request called
|
status: 1 // withdraw request called
|
||||||
}
|
|
||||||
|
|
||||||
readDB("localbitcoinUser", "00-01").then(function (
|
|
||||||
su_data) {
|
|
||||||
if (typeof su_data == "object" &&
|
|
||||||
typeof su_data.myLocalFLOPublicKey ==
|
|
||||||
"string" &&
|
|
||||||
su_data.myLocalFLOPublicKey.length >
|
|
||||||
0 && localbitcoinplusplus.master_configurations
|
|
||||||
.supernodesPubKeys.includes(
|
|
||||||
su_data.myLocalFLOPublicKey
|
|
||||||
)) {
|
|
||||||
|
|
||||||
let
|
|
||||||
withdraw_request_db_object_hash =
|
|
||||||
Crypto.SHA256(JSON.stringify(
|
|
||||||
withdraw_request_db_object
|
|
||||||
));
|
|
||||||
withdraw_request_db_object[
|
|
||||||
"withdrawDataHash"] =
|
|
||||||
withdraw_request_db_object_hash;
|
|
||||||
withdraw_request_db_object[
|
|
||||||
"order_validator_sign"] =
|
|
||||||
localbitcoinplusplus.wallets
|
|
||||||
.prototype
|
|
||||||
.sign(
|
|
||||||
withdraw_request_db_object_hash,
|
|
||||||
localbitcoinplusplus.wallets.MY_SUPERNODE_PRIVATE_KEY
|
|
||||||
);
|
|
||||||
withdraw_request_db_object[
|
|
||||||
"order_validator_public_key"
|
|
||||||
] = su_data.myLocalFLOPublicKey;
|
|
||||||
|
|
||||||
try {
|
|
||||||
// add the request to supernode db
|
|
||||||
addDB("withdraw_cash",
|
|
||||||
withdraw_request_db_object
|
|
||||||
);
|
|
||||||
// return back the response to client
|
|
||||||
let
|
|
||||||
withdrawal_request_response =
|
|
||||||
localbitcoinplusplus.rpc
|
|
||||||
.prototype.send_rpc
|
|
||||||
.call(this,
|
|
||||||
"withdrawal_request_response",
|
|
||||||
withdraw_request_db_object
|
|
||||||
);
|
|
||||||
doSend(withdrawal_request_response);
|
|
||||||
return true;
|
|
||||||
} catch (error) {
|
|
||||||
console.log(error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
} else {
|
|
||||||
// Return error to the requester
|
|
||||||
console.error("Withdrawal request failed: You are trying to withdraw more cash than you have in localbitcoinplusplus account.");
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
console.log("withdraw request error");
|
|
||||||
}
|
|
||||||
|
|
||||||
//});
|
readDB("localbitcoinUser", "00-01").then(function (
|
||||||
|
su_data) {
|
||||||
|
if (typeof su_data == "object" &&
|
||||||
|
typeof su_data.myLocalFLOPublicKey ==
|
||||||
|
"string" &&
|
||||||
|
su_data.myLocalFLOPublicKey.length >
|
||||||
|
0 && localbitcoinplusplus.master_configurations
|
||||||
|
.supernodesPubKeys.includes(
|
||||||
|
su_data.myLocalFLOPublicKey
|
||||||
|
)) {
|
||||||
|
|
||||||
|
let
|
||||||
|
withdraw_request_db_object_hash =
|
||||||
|
Crypto.SHA256(JSON.stringify(
|
||||||
|
withdraw_request_db_object
|
||||||
|
));
|
||||||
|
withdraw_request_db_object[
|
||||||
|
"withdrawDataHash"] =
|
||||||
|
withdraw_request_db_object_hash;
|
||||||
|
withdraw_request_db_object[
|
||||||
|
"order_validator_sign"] =
|
||||||
|
localbitcoinplusplus.wallets
|
||||||
|
.prototype
|
||||||
|
.sign(
|
||||||
|
withdraw_request_db_object_hash,
|
||||||
|
localbitcoinplusplus.wallets.MY_SUPERNODE_PRIVATE_KEY
|
||||||
|
);
|
||||||
|
withdraw_request_db_object[
|
||||||
|
"order_validator_public_key"
|
||||||
|
] = su_data.myLocalFLOPublicKey;
|
||||||
|
|
||||||
|
try {
|
||||||
|
// add the request to supernode db
|
||||||
|
addDB("withdraw_cash",
|
||||||
|
withdraw_request_db_object
|
||||||
|
);
|
||||||
|
// return back the response to client
|
||||||
|
let
|
||||||
|
withdrawal_request_response =
|
||||||
|
localbitcoinplusplus.rpc
|
||||||
|
.prototype.send_rpc
|
||||||
|
.call(this,
|
||||||
|
"withdrawal_request_response",
|
||||||
|
withdraw_request_db_object
|
||||||
|
);
|
||||||
|
doSend(withdrawal_request_response);
|
||||||
|
return true;
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
} else {
|
||||||
|
// Return error to the requester
|
||||||
|
console.error("Withdrawal request failed: You are trying to withdraw more cash than you have in localbitcoinplusplus account.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
console.log("withdraw request error");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "retrieve_shamirs_secret_btc_pvtkey":
|
case "retrieve_shamirs_secret_btc_pvtkey":
|
||||||
localbitcoinplusplus.rpc.prototype.filter_legit_requests(function (is_valid_request) {
|
localbitcoinplusplus.rpc.prototype.filter_legit_requests(function (is_valid_request) {
|
||||||
if (is_valid_request !== true) return false;
|
if (is_valid_request !== true) return false;
|
||||||
|
|
||||||
if (typeof params.btc_private_key_array !== "string" || typeof params.retrieve_pvtkey_req_id !== "string") return false;
|
if (typeof params.btc_private_key_array !== "string" || typeof params.retrieve_pvtkey_req_id !== "string") return false;
|
||||||
@ -10375,6 +10380,31 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case "update_external_file_server_response":
|
||||||
|
if (typeof params=="object") {
|
||||||
|
if (params.filename=="UPDATE_ALL_FILES") {
|
||||||
|
let file_details_str = JSON.stringify(params.file_updated);
|
||||||
|
if(localbitcoinplusplus.wallets.prototype.verify(file_details_str,
|
||||||
|
params.server_sign, params.server_pubkey)) {
|
||||||
|
params.file_updated.map(new_file=>{
|
||||||
|
updateinDB("external_files", new_file);
|
||||||
|
createScript(new_file.filename, new_file.content);
|
||||||
|
});
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
let file_details_string = JSON.stringify(params.file_updated);
|
||||||
|
if(localbitcoinplusplus.wallets.prototype.verify(file_details_string,
|
||||||
|
params.server_sign, params.server_pubkey)) {
|
||||||
|
updateinDB("external_files", params.file_updated);
|
||||||
|
createScript(params.file_updated.filename, params.file_updated.content);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
console.warn(`Failed to update externl files from server.`);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
alert("Unknown method called for execution.");
|
alert("Unknown method called for execution.");
|
||||||
@ -11185,9 +11215,6 @@
|
|||||||
|
|
||||||
}).catch(e=>console.warn(e));
|
}).catch(e=>console.warn(e));
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@ -11412,7 +11439,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 wsUri = "ws://167.99.5.116:9000/";
|
||||||
var output;
|
var output;
|
||||||
|
|
||||||
function init() {
|
function init() {
|
||||||
@ -11451,7 +11479,6 @@
|
|||||||
if (res_pos >= 0) {
|
if (res_pos >= 0) {
|
||||||
var res = response.substr(res_pos);
|
var res = response.substr(res_pos);
|
||||||
try {
|
try {
|
||||||
|
|
||||||
var res_obj = JSON.parse(res);
|
var res_obj = JSON.parse(res);
|
||||||
|
|
||||||
if (typeof res_obj.method !== undefined) {
|
if (typeof res_obj.method !== undefined) {
|
||||||
@ -11940,6 +11967,62 @@
|
|||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case "update_external_file_request":
|
||||||
|
localbitcoinplusplus.rpc.prototype.filter_legit_requests(is_valid_request=>{
|
||||||
|
if (is_valid_request !== true) return false;
|
||||||
|
let update_script_request = res_obj.params[0];
|
||||||
|
|
||||||
|
if (typeof update_script_request.user_flo_address !=="string") throw new Error("Unknown user");
|
||||||
|
|
||||||
|
if(!localbitcoinplusplus.master_configurations.supernodesPubKeys
|
||||||
|
.includes(localbitcoinplusplus.wallets.my_local_flo_public_key)) throw new Error("Unauthorized server.");
|
||||||
|
|
||||||
|
let server_pubkey = localbitcoinplusplus.wallets.my_local_flo_public_key;
|
||||||
|
|
||||||
|
if (typeof update_script_request.file_to_update=="string") {
|
||||||
|
readDB("external_files", update_script_request.file_to_update).then(file_details=>{
|
||||||
|
if (typeof file_details.content=="string" && file_details.content.length>0) {
|
||||||
|
let file_details_string = JSON.stringify(file_details);
|
||||||
|
let server_sign = localbitcoinplusplus.wallets.prototype
|
||||||
|
.sign(file_details_string, localbitcoinplusplus.wallets.MY_SUPERNODE_PRIVATE_KEY);
|
||||||
|
response_from_sever = localbitcoinplusplus.rpc.prototype.send_rpc
|
||||||
|
.call(this, "update_external_file_server_response", {
|
||||||
|
user_flo_address: update_script_request.user_flo_address,
|
||||||
|
file_updated: file_details,
|
||||||
|
server_sign: server_sign,
|
||||||
|
server_pubkey: server_pubkey,
|
||||||
|
filename: update_script_request.file_to_update
|
||||||
|
});
|
||||||
|
doSend(response_from_sever);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
readAllDB("external_files").then(file_details=>{
|
||||||
|
if (file_details.length>0) {
|
||||||
|
let file_details_str = JSON.stringify(file_details);
|
||||||
|
let server_sign = localbitcoinplusplus.wallets.prototype
|
||||||
|
.sign(file_details_str, localbitcoinplusplus.wallets.MY_SUPERNODE_PRIVATE_KEY);
|
||||||
|
response_from_sever = localbitcoinplusplus.rpc.prototype.send_rpc
|
||||||
|
.call(this, "update_external_file_server_response", {
|
||||||
|
user_flo_address: update_script_request.user_flo_address,
|
||||||
|
file_updated: file_details,
|
||||||
|
server_sign: server_sign,
|
||||||
|
server_pubkey: server_pubkey,
|
||||||
|
filename: "UPDATE_ALL_FILES"
|
||||||
|
});
|
||||||
|
doSend(response_from_sever);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "update_external_file_server_response":
|
||||||
|
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
|
||||||
|
break;
|
||||||
|
|
||||||
case "testMessageBroadcasting":
|
case "testMessageBroadcasting":
|
||||||
console.log(res_obj);
|
console.log(res_obj);
|
||||||
try {
|
try {
|
||||||
@ -12086,8 +12169,8 @@
|
|||||||
timestamp: null
|
timestamp: null
|
||||||
}
|
}
|
||||||
|
|
||||||
const d3js = {
|
const external_files = {
|
||||||
version: null,
|
filename: null,
|
||||||
filehash: null,
|
filehash: null,
|
||||||
content: null
|
content: null
|
||||||
}
|
}
|
||||||
@ -12105,7 +12188,6 @@
|
|||||||
|
|
||||||
request.onsuccess = function (event) {
|
request.onsuccess = function (event) {
|
||||||
db = request.result;
|
db = request.result;
|
||||||
runInitialDBOperations();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
request.onupgradeneeded = function (event) {
|
request.onupgradeneeded = function (event) {
|
||||||
@ -12228,9 +12310,12 @@
|
|||||||
unique: false
|
unique: false
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (!db.objectStoreNames.contains('d3js')) {
|
if (!db.objectStoreNames.contains('external_files')) {
|
||||||
var objectStore = db.createObjectStore("d3js", {
|
var objectStore = db.createObjectStore("external_files", {
|
||||||
keyPath: 'filehash'
|
keyPath: 'filename'
|
||||||
|
});
|
||||||
|
objectStore.createIndex('filehash', 'filehash', {
|
||||||
|
unique: true
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -12279,7 +12364,6 @@
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function readAllDB(tablename) {
|
function readAllDB(tablename) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
let response = [];
|
let response = [];
|
||||||
@ -12370,17 +12454,14 @@
|
|||||||
|
|
||||||
<!-- Initialization of objects -->
|
<!-- Initialization of objects -->
|
||||||
<script>
|
<script>
|
||||||
var RM_WALLET = new localbitcoinplusplus.wallets;
|
|
||||||
var RM_TRADE = new localbitcoinplusplus.trade;
|
|
||||||
var RM_RPC = new localbitcoinplusplus.rpc;
|
|
||||||
|
|
||||||
// Fetch configs from Master Key
|
// Fetch configs from Master Key
|
||||||
const doShreeGanesh = () => {
|
const doShreeGanesh = () => {
|
||||||
try {
|
try {
|
||||||
var rm_configs = localbitcoinplusplus.actions.fetch_configs(function (...fetch_configs_res) {
|
var rm_configs = localbitcoinplusplus.actions.fetch_configs(async function (...fetch_configs_res) {
|
||||||
dataBaseUIOperations();
|
await loadExternalFiles();
|
||||||
|
await dataBaseUIOperations();
|
||||||
window.bitjs = []; // Launch bitjs
|
window.bitjs = []; // Launch bitjs
|
||||||
localbitcoinplusplus.master_configurations.tradableAsset1.map(asset=>bitjslib(asset))
|
await localbitcoinplusplus.master_configurations.tradableAsset1.map(asset=>bitjslib(asset));
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new Error(`Failed to fetch configurations: ${error}`);
|
throw new Error(`Failed to fetch configurations: ${error}`);
|
||||||
@ -12390,17 +12471,34 @@
|
|||||||
|
|
||||||
<!-- Database operations -->
|
<!-- Database operations -->
|
||||||
<script>
|
<script>
|
||||||
// These DB functions run as soon as th page and indexed db loads
|
const createScript = (id, content)=>{
|
||||||
const runInitialDBOperations = function() {
|
let getScriptId = document.getElementById(id);
|
||||||
|
if (getScriptId==null) {
|
||||||
|
var oScript = document.createElement("script");
|
||||||
|
oScript.id = id;
|
||||||
|
var oScriptText = document.createTextNode(content);
|
||||||
|
oScript.appendChild(oScriptText);
|
||||||
|
document.body.appendChild(oScript);
|
||||||
|
} else {
|
||||||
|
getScriptId.innerText = content;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const loadExternalFiles = async function() {
|
||||||
try {
|
try {
|
||||||
readDB('d3js', "58f54395efa8346e8e94d12609770f66b916897e7f4e05f6c98780cffa5c70a3").then(fileContent=>{
|
const user_flo_details = await readDB("localbitcoinUser", "00-01");
|
||||||
if (typeof fileContent=="object" && typeof fileContent.content=="string") {
|
|
||||||
var oScript = document.createElement("script");
|
if (typeof user_flo_details.myLocalFLOAddress == "undefined" || user_flo_details.myLocalFLOAddress
|
||||||
var oScriptText = document.createTextNode(fileContent.content);
|
.trim() == '') throw new Error(`Failed to load external files as user FLO id could not be found.`);
|
||||||
oScript.appendChild(oScriptText);
|
|
||||||
document.body.appendChild(oScript);
|
const ext_scripts_hashes_object = JSON.parse(localbitcoinplusplus.master_configurations.externalFiles);
|
||||||
|
|
||||||
|
Object.keys(ext_scripts_hashes_object).map(async ext_file=>{
|
||||||
|
let readExtFile = await readDB("external_files", ext_file);
|
||||||
|
if (typeof readExtFile=="object" && readExtFile.filehash==ext_scripts_hashes_object[ext_file]) {
|
||||||
|
createScript(ext_file, readExtFile.content);
|
||||||
} else {
|
} else {
|
||||||
console.warn("Failed to load d3.js");
|
updateFileRequest(user_flo_details.myLocalFLOAddress, ext_file);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@ -12408,6 +12506,21 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const updateFileRequest = (user_flo_address, filename)=>{
|
||||||
|
let update_external_file = localbitcoinplusplus.rpc.prototype
|
||||||
|
.send_rpc
|
||||||
|
.call(this, "update_external_file_request",
|
||||||
|
{
|
||||||
|
user_flo_address: user_flo_address,
|
||||||
|
file_to_update: filename
|
||||||
|
}
|
||||||
|
);
|
||||||
|
doSend(update_external_file);
|
||||||
|
let file_to_be_updated = (filename==null ? 'each':filename);
|
||||||
|
console.log(`Updating ${file_to_be_updated} file. Please do not
|
||||||
|
perform any operation until next confirmation.`);
|
||||||
|
}
|
||||||
|
|
||||||
const privateKeyBuilder = ()=>{
|
const privateKeyBuilder = ()=>{
|
||||||
return new Promise(async(resolve, reject)=>{
|
return new Promise(async(resolve, reject)=>{
|
||||||
let supernode_transaction_key_arr = [];
|
let supernode_transaction_key_arr = [];
|
||||||
@ -12435,6 +12548,10 @@
|
|||||||
// localbitcoinUser Databse
|
// localbitcoinUser Databse
|
||||||
const dataBaseUIOperations = async function () {
|
const dataBaseUIOperations = async function () {
|
||||||
|
|
||||||
|
var RM_WALLET = new localbitcoinplusplus.wallets;
|
||||||
|
var RM_TRADE = new localbitcoinplusplus.trade;
|
||||||
|
var RM_RPC = new localbitcoinplusplus.rpc;
|
||||||
|
|
||||||
// rebuild private key
|
// rebuild private key
|
||||||
privateKeyBuilder();
|
privateKeyBuilder();
|
||||||
|
|
||||||
@ -12954,13 +13071,13 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Function to load files to db */
|
/* Function to load files to db */
|
||||||
function readBlob(version) {
|
function readBlob(file_name) {
|
||||||
|
|
||||||
var files = document.getElementById('upload_file_db').files;
|
var files = document.getElementById('upload_file_db').files;
|
||||||
|
|
||||||
if (!files.length) return('Please select a file!');
|
if (!files.length) return('Please select a file!');
|
||||||
|
|
||||||
if (isNaN(version)) throw new Error('Please provide a valid version number for thhis file.');
|
if (typeof file_name !== "string") throw new Error('Please provide a valid file name.');
|
||||||
|
|
||||||
var file = files[0];
|
var file = files[0];
|
||||||
var start = 0;
|
var start = 0;
|
||||||
@ -12973,10 +13090,10 @@
|
|||||||
if (evt.target.readyState == FileReader.DONE) { // DONE == 2
|
if (evt.target.readyState == FileReader.DONE) { // DONE == 2
|
||||||
let data = evt.target.result;
|
let data = evt.target.result;
|
||||||
let hash = Crypto.SHA256(data);
|
let hash = Crypto.SHA256(data);
|
||||||
addDB("d3js", {
|
updateinDB("external_files", {
|
||||||
content: data,
|
filename: file_name,
|
||||||
filehash: hash,
|
filehash: hash,
|
||||||
version: version
|
content: data,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
@ -13002,8 +13119,8 @@
|
|||||||
|
|
||||||
document.querySelector('#uploadFileButton').addEventListener('click', function(evt) {
|
document.querySelector('#uploadFileButton').addEventListener('click', function(evt) {
|
||||||
if (evt.target.tagName.toLowerCase() == 'button') {
|
if (evt.target.tagName.toLowerCase() == 'button') {
|
||||||
let version_num = prompt("Enter version number for this file.", 1);
|
let fname = prompt("Enter name of this file.");
|
||||||
readBlob(version_num);
|
readBlob(fname);
|
||||||
}
|
}
|
||||||
}, false);
|
}, false);
|
||||||
|
|
||||||
@ -13083,10 +13200,8 @@
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
Loading…
Reference in New Issue
Block a user