changed getUserPublicKey function to readDB to get userPublicData in deposit_asset_request in backup_receive_rpc_response
This commit is contained in:
parent
2cf168039a
commit
0c7abd21bb
@ -10348,8 +10348,8 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
Promise.all(promises).then(cs=>{
|
Promise.all(promises).then(cs=>{
|
||||||
let isPreviousSupernodesLive = cs.map((su_status, index)=>
|
let isPreviousSupernodesLive = cs.map((su_status)=>
|
||||||
(typeof su_status[index] !== "object" || su_status[index].is_live == true )
|
(typeof su_status[0] !== "object" || su_status[0].is_live == true )
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!isPreviousSupernodesLive.includes(true)) {
|
if (!isPreviousSupernodesLive.includes(true)) {
|
||||||
@ -12833,7 +12833,7 @@
|
|||||||
// already processed above
|
// already processed above
|
||||||
break;
|
break;
|
||||||
case "deposit_asset_request":
|
case "deposit_asset_request":
|
||||||
RM_RPC.filter_legit_backup_requests(params.trader_flo_address, function (is_valid_request) {
|
RM_RPC.filter_legit_backup_requests(params.trader_flo_address, async function (is_valid_request) {
|
||||||
|
|
||||||
if (is_valid_request !== true) return false;
|
if (is_valid_request !== true) return false;
|
||||||
|
|
||||||
@ -12853,355 +12853,357 @@
|
|||||||
typeof params.trader_flo_address == "string" &&
|
typeof params.trader_flo_address == "string" &&
|
||||||
params.trader_flo_address.length > 0
|
params.trader_flo_address.length > 0
|
||||||
) {
|
) {
|
||||||
RM_WALLET.getUserPublicKey(params.trader_flo_address,
|
const requester_public_req = await backup_server_db_instance
|
||||||
async function (requester_public_key) {
|
.backup_readDB('userPublicData', params.trader_flo_address);
|
||||||
if (requester_public_key == undefined ||
|
if (typeof requester_public_req!=="object") return;
|
||||||
requester_public_key == null) {
|
const requester_public_key = requester_public_req.trader_flo_pubKey;
|
||||||
err_msg = 'Failed to get public key of the user.';
|
|
||||||
|
if (typeof requester_public_key == "undefined" ||
|
||||||
|
requester_public_key == null) {
|
||||||
|
err_msg = 'Failed to get public key of the user.';
|
||||||
|
showMessage(err_msg);
|
||||||
|
throw new Error(err_msg);
|
||||||
|
}
|
||||||
|
params.depositor_public_key = requester_public_key;
|
||||||
|
|
||||||
|
await RM_TRADE.resolve_current_crypto_price_in_fiat(
|
||||||
|
params.product, params.currency);
|
||||||
|
|
||||||
|
if (localbitcoinplusplus.master_configurations.tradableAsset1
|
||||||
|
.includes(params.product)) {
|
||||||
|
|
||||||
|
let generate_btc_keys_for_requester = RM_WALLET
|
||||||
|
.generateFloKeys(null, params.product);
|
||||||
|
|
||||||
|
console.table(generate_btc_keys_for_requester);
|
||||||
|
|
||||||
|
params.id = helper_functions.unique_id();
|
||||||
|
params.status = 1;
|
||||||
|
params.btc_address =
|
||||||
|
generate_btc_keys_for_requester.address;
|
||||||
|
|
||||||
|
params.bitcoinToBePaid = RM_TRADE.calculateCryptoEquivalentOfCash(
|
||||||
|
params.depositing_amount, params.currency,
|
||||||
|
params.product);
|
||||||
|
|
||||||
|
let receivedTradeInfo = { ...params };
|
||||||
|
|
||||||
|
if (typeof localbitcoinplusplus.wallets.MY_SUPERNODE_PRIVATE_KEY ==
|
||||||
|
"undefined") {
|
||||||
|
err_msg = 'Failed to determine Super node signing key.';
|
||||||
showMessage(err_msg);
|
showMessage(err_msg);
|
||||||
throw new Error(err_msg);
|
throw new Error(err_msg);
|
||||||
}
|
}
|
||||||
params.depositor_public_key = requester_public_key;
|
|
||||||
|
|
||||||
await RM_TRADE.resolve_current_crypto_price_in_fiat(
|
readDB("localbitcoinUser", "00-01").then(
|
||||||
params.product, params.currency);
|
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)
|
||||||
|
) {
|
||||||
|
|
||||||
if (localbitcoinplusplus.master_configurations.tradableAsset1
|
let receivedTradeInfoHash =
|
||||||
.includes(params.product)) {
|
Crypto.SHA256(JSON.stringify(receivedTradeInfo));
|
||||||
|
|
||||||
let generate_btc_keys_for_requester = RM_WALLET
|
receivedTradeInfo["depositDataHash"] = receivedTradeInfoHash;
|
||||||
.generateFloKeys(null, params.product);
|
receivedTradeInfo["order_validator_sign"] =
|
||||||
|
RM_WALLET.sign(receivedTradeInfoHash,
|
||||||
|
localbitcoinplusplus.wallets.MY_SUPERNODE_PRIVATE_KEY
|
||||||
|
);
|
||||||
|
receivedTradeInfo["order_validator_public_key"] = su_data.myLocalFLOPublicKey;
|
||||||
|
|
||||||
console.table(generate_btc_keys_for_requester);
|
try {
|
||||||
|
const this_btc_pvt_key =
|
||||||
|
generate_btc_keys_for_requester.privateKeyWIF;
|
||||||
|
const this_btc_tx_key =
|
||||||
|
Crypto.util.randomBytes(64);
|
||||||
|
const
|
||||||
|
this_btc_pvt_key_shamirs_secret =
|
||||||
|
RM_WALLET.createShamirsSecretShares(this_btc_pvt_key, 10, 5);
|
||||||
|
if (typeof this_btc_pvt_key_shamirs_secret ==
|
||||||
|
"object" &&
|
||||||
|
this_btc_pvt_key_shamirs_secret
|
||||||
|
.length > 0) {
|
||||||
|
backup_server_db_instance.backup_addDB("deposit", receivedTradeInfo);
|
||||||
|
|
||||||
params.id = helper_functions.unique_id();
|
// Send the address to the requester
|
||||||
params.status = 1;
|
let
|
||||||
params.btc_address =
|
deposit_response_object = {
|
||||||
generate_btc_keys_for_requester.address;
|
error: false,
|
||||||
|
method: "deposit_asset_request_response",
|
||||||
|
msg: `Please send ${params.product} ${params.bitcoinToBePaid} to the following addres: ${generate_btc_keys_for_requester.address}.`,
|
||||||
|
data: receivedTradeInfo
|
||||||
|
};
|
||||||
|
deposit_response_object.receiver_flo_address = params.trader_flo_address;
|
||||||
|
deposit_response_object.trader_flo_address = params.trader_flo_address;
|
||||||
|
|
||||||
params.bitcoinToBePaid = RM_TRADE.calculateCryptoEquivalentOfCash(
|
RM_RPC
|
||||||
params.depositing_amount, params.currency,
|
.send_rpc
|
||||||
params.product);
|
.call(this,
|
||||||
|
"deposit_asset_request_response",
|
||||||
|
deposit_response_object
|
||||||
|
).then(deposit_request_response=>
|
||||||
|
doSend(deposit_request_response));
|
||||||
|
|
||||||
let receivedTradeInfo = { ...params };
|
let
|
||||||
|
this_btc_pvt_key_shamirs_secret_array =
|
||||||
if (typeof localbitcoinplusplus.wallets.MY_SUPERNODE_PRIVATE_KEY ==
|
|
||||||
"undefined") {
|
|
||||||
err_msg = 'Failed to determine Super node signing key.';
|
|
||||||
showMessage(err_msg);
|
|
||||||
throw new Error(err_msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
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 receivedTradeInfoHash =
|
|
||||||
Crypto.SHA256(JSON.stringify(receivedTradeInfo));
|
|
||||||
|
|
||||||
receivedTradeInfo["depositDataHash"] = receivedTradeInfoHash;
|
|
||||||
receivedTradeInfo["order_validator_sign"] =
|
|
||||||
RM_WALLET.sign(receivedTradeInfoHash,
|
|
||||||
localbitcoinplusplus.wallets.MY_SUPERNODE_PRIVATE_KEY
|
|
||||||
);
|
|
||||||
receivedTradeInfo["order_validator_public_key"] = su_data.myLocalFLOPublicKey;
|
|
||||||
|
|
||||||
try {
|
|
||||||
const this_btc_pvt_key =
|
|
||||||
generate_btc_keys_for_requester.privateKeyWIF;
|
|
||||||
const this_btc_tx_key =
|
|
||||||
Crypto.util.randomBytes(64);
|
|
||||||
const
|
|
||||||
this_btc_pvt_key_shamirs_secret =
|
|
||||||
RM_WALLET.createShamirsSecretShares(this_btc_pvt_key, 10, 5);
|
|
||||||
if (typeof this_btc_pvt_key_shamirs_secret ==
|
|
||||||
"object" &&
|
|
||||||
this_btc_pvt_key_shamirs_secret
|
this_btc_pvt_key_shamirs_secret
|
||||||
.length > 0) {
|
.map(chunks => {
|
||||||
backup_server_db_instance.backup_addDB("deposit", receivedTradeInfo);
|
let
|
||||||
|
chunk_ids =
|
||||||
|
Crypto.util
|
||||||
|
.bytesToHex(Crypto.util.randomBytes(64));
|
||||||
|
let
|
||||||
|
chunk_array = {
|
||||||
|
"id": chunk_ids,
|
||||||
|
"privateKeyChunks": Crypto
|
||||||
|
.AES
|
||||||
|
.encrypt(
|
||||||
|
chunks,
|
||||||
|
this_btc_tx_key
|
||||||
|
),
|
||||||
|
"trader_flo_address": params.trader_flo_address
|
||||||
|
};
|
||||||
|
return chunk_array;
|
||||||
|
});
|
||||||
|
|
||||||
// Send the address to the requester
|
// Send chunks of private keys to other supernodes
|
||||||
let
|
this_btc_pvt_key_shamirs_secret_array
|
||||||
deposit_response_object = {
|
.map(shares => {
|
||||||
error: false,
|
RM_RPC
|
||||||
method: "deposit_asset_request_response",
|
.send_rpc
|
||||||
msg: `Please send ${params.product} ${params.bitcoinToBePaid} to the following addres: ${generate_btc_keys_for_requester.address}.`,
|
.call(
|
||||||
data: receivedTradeInfo
|
this,
|
||||||
};
|
"store_shamirs_secret_pvtkey_shares",
|
||||||
deposit_response_object.receiver_flo_address = params.trader_flo_address;
|
shares
|
||||||
deposit_response_object.trader_flo_address = params.trader_flo_address;
|
).then(store_pvtkey_req=>
|
||||||
|
doSend(store_pvtkey_req));
|
||||||
|
|
||||||
RM_RPC
|
});
|
||||||
.send_rpc
|
|
||||||
.call(this,
|
|
||||||
"deposit_asset_request_response",
|
|
||||||
deposit_response_object
|
|
||||||
).then(deposit_request_response=>
|
|
||||||
doSend(deposit_request_response));
|
|
||||||
|
|
||||||
let
|
if (typeof localbitcoinplusplus
|
||||||
this_btc_pvt_key_shamirs_secret_array =
|
.wallets.my_local_flo_address ==
|
||||||
this_btc_pvt_key_shamirs_secret
|
"string" &&
|
||||||
.map(chunks => {
|
typeof localbitcoinplusplus
|
||||||
|
.wallets.my_local_flo_public_key ==
|
||||||
|
"string" &&
|
||||||
|
typeof localbitcoinplusplus
|
||||||
|
.master_configurations
|
||||||
|
.supernodesPubKeys ==
|
||||||
|
"object" &&
|
||||||
|
localbitcoinplusplus
|
||||||
|
.master_configurations
|
||||||
|
.supernodesPubKeys.includes(
|
||||||
|
localbitcoinplusplus
|
||||||
|
.wallets.my_local_flo_public_key
|
||||||
|
)) {
|
||||||
|
try {
|
||||||
|
let
|
||||||
|
this_btc_pvt_key_shamirs_secret__id_array =
|
||||||
|
this_btc_pvt_key_shamirs_secret_array
|
||||||
|
.map(i => i.id);
|
||||||
|
let
|
||||||
|
btc_private_key_shamirs_id =
|
||||||
|
this_btc_pvt_key_shamirs_secret__id_array;
|
||||||
|
let
|
||||||
|
supernode_transaction_key =
|
||||||
|
this_btc_tx_key;
|
||||||
|
const
|
||||||
|
system_btc_reserves_private_keys_object = {
|
||||||
|
id: helper_functions
|
||||||
|
.unique_id(),
|
||||||
|
product: params
|
||||||
|
.product,
|
||||||
|
btc_address: params
|
||||||
|
.btc_address,
|
||||||
|
balance: null,
|
||||||
|
trader_flo_address: params
|
||||||
|
.trader_flo_address,
|
||||||
|
btc_private_key_shamirs_id: btc_private_key_shamirs_id,
|
||||||
|
supernode_transaction_key: supernode_transaction_key
|
||||||
|
}
|
||||||
|
backup_server_db_instance.backup_addDB(
|
||||||
|
"system_btc_reserves_private_keys",
|
||||||
|
system_btc_reserves_private_keys_object
|
||||||
|
);
|
||||||
|
} catch (error) {
|
||||||
|
throw new Error( error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
throw new Error(error);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Send the address to the requester
|
||||||
|
let deposit_response_object = {
|
||||||
|
error: false,
|
||||||
|
method: "deposit_asset_request_response",
|
||||||
|
msg: `Please send the ${params.product} to ${generate_btc_keys_for_requester.address}.`,
|
||||||
|
data: receivedTradeInfo,
|
||||||
|
receiver_flo_address: params.trader_flo_address,
|
||||||
|
trader_flo_address: params.trader_flo_address,
|
||||||
|
};
|
||||||
|
|
||||||
|
RM_RPC.send_rpc
|
||||||
|
.call(this,
|
||||||
|
"deposit_asset_request_response",
|
||||||
|
deposit_response_object
|
||||||
|
).then(deposit_request_response=>
|
||||||
|
doSend(deposit_request_response));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return false;
|
||||||
|
|
||||||
|
} else if (!localbitcoinplusplus.master_configurations
|
||||||
|
.tradableAsset1.includes(params.product)) {
|
||||||
|
params.id = helper_functions.unique_id();
|
||||||
|
params.status = 1;
|
||||||
|
// IMPORTANT - If deposit is a fiat make sure product and currency are both same
|
||||||
|
params.currency = params.product;
|
||||||
|
let receivedTradeInfo = { ...params };
|
||||||
|
|
||||||
|
backup_server_db_instance.backup_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 receivedTradeInfoHash =
|
||||||
|
Crypto.SHA256(JSON.stringify(
|
||||||
|
receivedTradeInfo));
|
||||||
|
|
||||||
|
receivedTradeInfo[
|
||||||
|
"depositDataHash"] =
|
||||||
|
receivedTradeInfoHash;
|
||||||
|
receivedTradeInfo[
|
||||||
|
"order_validator_sign"] =
|
||||||
|
RM_WALLET.sign(
|
||||||
|
receivedTradeInfoHash,
|
||||||
|
localbitcoinplusplus.wallets
|
||||||
|
.MY_SUPERNODE_PRIVATE_KEY
|
||||||
|
);
|
||||||
|
receivedTradeInfo[
|
||||||
|
"order_validator_public_key"
|
||||||
|
] = su_data.myLocalFLOPublicKey;
|
||||||
|
|
||||||
|
// YOU NEED TO DETERMINE A BANK ACCOUNT HERE IF NO ONE IS WITHDRAWING
|
||||||
|
try {
|
||||||
|
backup_server_db_instance.backup_addDB("deposit",
|
||||||
|
receivedTradeInfo);
|
||||||
|
backup_server_db_instance.backup_readDBbyIndex(
|
||||||
|
"withdraw_cash",
|
||||||
|
"status", 1).then(
|
||||||
|
function (
|
||||||
|
withdrawers_list
|
||||||
|
) {
|
||||||
|
if (typeof withdrawers_list ==
|
||||||
|
"object") {
|
||||||
|
if (
|
||||||
|
withdrawers_list.length > 0) {
|
||||||
|
withdrawers_list.filter(
|
||||||
|
wd => wd.currency ==
|
||||||
|
params.currency).map(
|
||||||
|
function (withdrawer) {
|
||||||
|
if (
|
||||||
|
withdrawer.withdraw_amount ==
|
||||||
|
params.depositing_amount &&
|
||||||
|
withdrawer.currency ==
|
||||||
|
params.currency
|
||||||
|
) {
|
||||||
|
withdrawer.status = 2; // A depositor has been asked to deposit money
|
||||||
|
withdrawer.depositor_found_at = + new Date();
|
||||||
|
withdrawer.depositor_flo_id = receivedTradeInfo.trader_flo_address;
|
||||||
|
backup_server_db_instance.backup_updateinDB ("withdraw_cash", withdrawer, withdrawer.trader_flo_address);
|
||||||
|
|
||||||
|
receivedTradeInfo.status = 2; // withdrawer found. Now deposit money to his account
|
||||||
|
backup_server_db_instance.backup_updateinDB(
|
||||||
|
"deposit",
|
||||||
|
receivedTradeInfo,
|
||||||
|
receivedTradeInfo.trader_flo_address
|
||||||
|
);
|
||||||
|
|
||||||
|
let withdrawer_bank_account = withdrawer.receivinAddress;
|
||||||
|
|
||||||
|
let deposit_response_object = {
|
||||||
|
error: false,
|
||||||
|
method: "deposit_asset_request_response",
|
||||||
|
msg: `Plese send the money to following bank address: "${withdrawer_bank_account}"`,
|
||||||
|
data: receivedTradeInfo,
|
||||||
|
withdrawer_data: withdrawer,
|
||||||
|
receiver_flo_address: receivedTradeInfo.trader_flo_address,
|
||||||
|
trader_flo_address: receivedTradeInfo.trader_flo_address,
|
||||||
|
};
|
||||||
|
|
||||||
|
RM_RPC.send_rpc.call(
|
||||||
|
this,
|
||||||
|
"deposit_asset_request_response",
|
||||||
|
deposit_response_object
|
||||||
|
).then(deposit_request_response=>
|
||||||
|
doSend(deposit_request_response));
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
err_msg = "Deposit request failed: We could not find a withdrawer.";
|
||||||
|
showMessage(err_msg);
|
||||||
|
throw new Error(err_msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
//No one is withdrawing so provide your bank details
|
||||||
let
|
let
|
||||||
chunk_ids =
|
deposit_response_object = {
|
||||||
Crypto.util
|
error: false,
|
||||||
.bytesToHex(Crypto.util.randomBytes(64));
|
method: "deposit_asset_request_response",
|
||||||
let
|
msg: `Plese send the money to following bank address: "System determined bank".`,
|
||||||
chunk_array = {
|
data: receivedTradeInfo,
|
||||||
"id": chunk_ids,
|
receiver_flo_address: receivedTradeInfo.trader_flo_address,
|
||||||
"privateKeyChunks": Crypto
|
trader_flo_address: receivedTradeInfo.trader_flo_address,
|
||||||
.AES
|
|
||||||
.encrypt(
|
|
||||||
chunks,
|
|
||||||
this_btc_tx_key
|
|
||||||
),
|
|
||||||
"trader_flo_address": params.trader_flo_address
|
|
||||||
};
|
};
|
||||||
return chunk_array;
|
|
||||||
});
|
|
||||||
|
|
||||||
// Send chunks of private keys to other supernodes
|
receivedTradeInfo.status = 2; // withdrawer found. Now deposit money to his account
|
||||||
this_btc_pvt_key_shamirs_secret_array
|
updateinDB
|
||||||
.map(shares => {
|
(
|
||||||
|
"deposit",
|
||||||
|
receivedTradeInfo,
|
||||||
|
receivedTradeInfo
|
||||||
|
.trader_flo_address
|
||||||
|
);
|
||||||
|
|
||||||
RM_RPC
|
RM_RPC
|
||||||
.send_rpc
|
.send_rpc
|
||||||
.call(
|
.call(
|
||||||
this,
|
this,
|
||||||
"store_shamirs_secret_pvtkey_shares",
|
"deposit_asset_request_response",
|
||||||
shares
|
deposit_response_object
|
||||||
).then(store_pvtkey_req=>
|
).then(deposit_request_response=>
|
||||||
doSend(store_pvtkey_req));
|
doSend(deposit_request_response));
|
||||||
|
return true;
|
||||||
});
|
|
||||||
|
|
||||||
if (typeof localbitcoinplusplus
|
|
||||||
.wallets.my_local_flo_address ==
|
|
||||||
"string" &&
|
|
||||||
typeof localbitcoinplusplus
|
|
||||||
.wallets.my_local_flo_public_key ==
|
|
||||||
"string" &&
|
|
||||||
typeof localbitcoinplusplus
|
|
||||||
.master_configurations
|
|
||||||
.supernodesPubKeys ==
|
|
||||||
"object" &&
|
|
||||||
localbitcoinplusplus
|
|
||||||
.master_configurations
|
|
||||||
.supernodesPubKeys.includes(
|
|
||||||
localbitcoinplusplus
|
|
||||||
.wallets.my_local_flo_public_key
|
|
||||||
)) {
|
|
||||||
try {
|
|
||||||
let
|
|
||||||
this_btc_pvt_key_shamirs_secret__id_array =
|
|
||||||
this_btc_pvt_key_shamirs_secret_array
|
|
||||||
.map(i => i.id);
|
|
||||||
let
|
|
||||||
btc_private_key_shamirs_id =
|
|
||||||
this_btc_pvt_key_shamirs_secret__id_array;
|
|
||||||
let
|
|
||||||
supernode_transaction_key =
|
|
||||||
this_btc_tx_key;
|
|
||||||
const
|
|
||||||
system_btc_reserves_private_keys_object = {
|
|
||||||
id: helper_functions
|
|
||||||
.unique_id(),
|
|
||||||
product: params
|
|
||||||
.product,
|
|
||||||
btc_address: params
|
|
||||||
.btc_address,
|
|
||||||
balance: null,
|
|
||||||
trader_flo_address: params
|
|
||||||
.trader_flo_address,
|
|
||||||
btc_private_key_shamirs_id: btc_private_key_shamirs_id,
|
|
||||||
supernode_transaction_key: supernode_transaction_key
|
|
||||||
}
|
|
||||||
backup_server_db_instance.backup_addDB(
|
|
||||||
"system_btc_reserves_private_keys",
|
|
||||||
system_btc_reserves_private_keys_object
|
|
||||||
);
|
|
||||||
} catch (error) {
|
|
||||||
throw new Error( error);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
});
|
||||||
}
|
} catch (error) {
|
||||||
} catch (error) {
|
err_msg = "Deposit request failed: We could not find a withdrawer. Come again later.";
|
||||||
throw new Error(error);
|
showMessage(err_msg);
|
||||||
}
|
throw new Error(err_msg);
|
||||||
|
|
||||||
// Send the address to the requester
|
|
||||||
let deposit_response_object = {
|
|
||||||
error: false,
|
|
||||||
method: "deposit_asset_request_response",
|
|
||||||
msg: `Please send the ${params.product} to ${generate_btc_keys_for_requester.address}.`,
|
|
||||||
data: receivedTradeInfo,
|
|
||||||
receiver_flo_address: params.trader_flo_address,
|
|
||||||
trader_flo_address: params.trader_flo_address,
|
|
||||||
};
|
|
||||||
|
|
||||||
RM_RPC.send_rpc
|
|
||||||
.call(this,
|
|
||||||
"deposit_asset_request_response",
|
|
||||||
deposit_response_object
|
|
||||||
).then(deposit_request_response=>
|
|
||||||
doSend(deposit_request_response));
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
return false;
|
}
|
||||||
|
});
|
||||||
} else if (!localbitcoinplusplus.master_configurations
|
}
|
||||||
.tradableAsset1.includes(params.product)) {
|
|
||||||
params.id = helper_functions.unique_id();
|
|
||||||
params.status = 1;
|
|
||||||
// IMPORTANT - If deposit is a fiat make sure product and currency are both same
|
|
||||||
params.currency = params.product;
|
|
||||||
let receivedTradeInfo = { ...params };
|
|
||||||
|
|
||||||
backup_server_db_instance.backup_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 receivedTradeInfoHash =
|
|
||||||
Crypto.SHA256(JSON.stringify(
|
|
||||||
receivedTradeInfo));
|
|
||||||
|
|
||||||
receivedTradeInfo[
|
|
||||||
"depositDataHash"] =
|
|
||||||
receivedTradeInfoHash;
|
|
||||||
receivedTradeInfo[
|
|
||||||
"order_validator_sign"] =
|
|
||||||
RM_WALLET.sign(
|
|
||||||
receivedTradeInfoHash,
|
|
||||||
localbitcoinplusplus.wallets
|
|
||||||
.MY_SUPERNODE_PRIVATE_KEY
|
|
||||||
);
|
|
||||||
receivedTradeInfo[
|
|
||||||
"order_validator_public_key"
|
|
||||||
] = su_data.myLocalFLOPublicKey;
|
|
||||||
|
|
||||||
// YOU NEED TO DETERMINE A BANK ACCOUNT HERE IF NO ONE IS WITHDRAWING
|
|
||||||
try {
|
|
||||||
backup_server_db_instance.backup_addDB("deposit",
|
|
||||||
receivedTradeInfo);
|
|
||||||
backup_server_db_instance.backup_readDBbyIndex(
|
|
||||||
"withdraw_cash",
|
|
||||||
"status", 1).then(
|
|
||||||
function (
|
|
||||||
withdrawers_list
|
|
||||||
) {
|
|
||||||
if (typeof withdrawers_list ==
|
|
||||||
"object") {
|
|
||||||
if (
|
|
||||||
withdrawers_list.length > 0) {
|
|
||||||
withdrawers_list.filter(
|
|
||||||
wd => wd.currency ==
|
|
||||||
params.currency).map(
|
|
||||||
function (withdrawer) {
|
|
||||||
if (
|
|
||||||
withdrawer.withdraw_amount ==
|
|
||||||
params.depositing_amount &&
|
|
||||||
withdrawer.currency ==
|
|
||||||
params.currency
|
|
||||||
) {
|
|
||||||
withdrawer.status = 2; // A depositor has been asked to deposit money
|
|
||||||
withdrawer.depositor_found_at = + new Date();
|
|
||||||
withdrawer.depositor_flo_id = receivedTradeInfo.trader_flo_address;
|
|
||||||
backup_server_db_instance.backup_updateinDB ("withdraw_cash", withdrawer, withdrawer.trader_flo_address);
|
|
||||||
|
|
||||||
receivedTradeInfo.status = 2; // withdrawer found. Now deposit money to his account
|
|
||||||
backup_server_db_instance.backup_updateinDB(
|
|
||||||
"deposit",
|
|
||||||
receivedTradeInfo,
|
|
||||||
receivedTradeInfo.trader_flo_address
|
|
||||||
);
|
|
||||||
|
|
||||||
let withdrawer_bank_account = withdrawer.receivinAddress;
|
|
||||||
|
|
||||||
let deposit_response_object = {
|
|
||||||
error: false,
|
|
||||||
method: "deposit_asset_request_response",
|
|
||||||
msg: `Plese send the money to following bank address: "${withdrawer_bank_account}"`,
|
|
||||||
data: receivedTradeInfo,
|
|
||||||
withdrawer_data: withdrawer,
|
|
||||||
receiver_flo_address: receivedTradeInfo.trader_flo_address,
|
|
||||||
trader_flo_address: receivedTradeInfo.trader_flo_address,
|
|
||||||
};
|
|
||||||
|
|
||||||
RM_RPC.send_rpc.call(
|
|
||||||
this,
|
|
||||||
"deposit_asset_request_response",
|
|
||||||
deposit_response_object
|
|
||||||
).then(deposit_request_response=>
|
|
||||||
doSend(deposit_request_response));
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
err_msg = "Deposit request failed: We could not find a withdrawer.";
|
|
||||||
showMessage(err_msg);
|
|
||||||
throw new Error(err_msg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
//No one is withdrawing so provide your bank details
|
|
||||||
let
|
|
||||||
deposit_response_object = {
|
|
||||||
error: false,
|
|
||||||
method: "deposit_asset_request_response",
|
|
||||||
msg: `Plese send the money to following bank address: "System determined bank".`,
|
|
||||||
data: receivedTradeInfo,
|
|
||||||
receiver_flo_address: receivedTradeInfo.trader_flo_address,
|
|
||||||
trader_flo_address: receivedTradeInfo.trader_flo_address,
|
|
||||||
};
|
|
||||||
|
|
||||||
receivedTradeInfo.status = 2; // withdrawer found. Now deposit money to his account
|
|
||||||
updateinDB
|
|
||||||
(
|
|
||||||
"deposit",
|
|
||||||
receivedTradeInfo,
|
|
||||||
receivedTradeInfo
|
|
||||||
.trader_flo_address
|
|
||||||
);
|
|
||||||
|
|
||||||
RM_RPC
|
|
||||||
.send_rpc
|
|
||||||
.call(
|
|
||||||
this,
|
|
||||||
"deposit_asset_request_response",
|
|
||||||
deposit_response_object
|
|
||||||
).then(deposit_request_response=>
|
|
||||||
doSend(deposit_request_response));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} catch (error) {
|
|
||||||
err_msg = "Deposit request failed: We could not find a withdrawer. Come again later.";
|
|
||||||
showMessage(err_msg);
|
|
||||||
throw new Error(err_msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
err_msg = "deposit asset request error";
|
err_msg = "deposit asset request error";
|
||||||
@ -15576,7 +15578,7 @@
|
|||||||
|
|
||||||
if (typeof res_obj.globalParams !== "object"
|
if (typeof res_obj.globalParams !== "object"
|
||||||
|| (typeof res_obj.globalParams.receiversList == "object"
|
|| (typeof res_obj.globalParams.receiversList == "object"
|
||||||
&& !request.globalParams.receiversList
|
&& !res_obj.globalParams.receiversList
|
||||||
.includes(localbitcoinplusplus.wallets.my_local_flo_address)
|
.includes(localbitcoinplusplus.wallets.my_local_flo_address)
|
||||||
)) return;
|
)) return;
|
||||||
|
|
||||||
@ -16634,7 +16636,8 @@
|
|||||||
//"receiver_flo_address": "", // message for all
|
//"receiver_flo_address": "", // message for all
|
||||||
//"ws_url": websocket.url,
|
//"ws_url": websocket.url,
|
||||||
"server_msg": `Your primary/secondary Supernode is live and synced. You can start using the system.`,
|
"server_msg": `Your primary/secondary Supernode is live and synced. You can start using the system.`,
|
||||||
}).then(server_response=>doSend(server_response));
|
})
|
||||||
|
//.then(server_response=>doSend(server_response));
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -16827,7 +16830,7 @@
|
|||||||
|
|
||||||
if (typeof res_obj.globalParams !== "object"
|
if (typeof res_obj.globalParams !== "object"
|
||||||
|| (typeof res_obj.globalParams.receiversList == "object"
|
|| (typeof res_obj.globalParams.receiversList == "object"
|
||||||
&& !request.globalParams.receiversList
|
&& !res_obj.globalParams.receiversList
|
||||||
.includes(localbitcoinplusplus.wallets.my_local_flo_address)
|
.includes(localbitcoinplusplus.wallets.my_local_flo_address)
|
||||||
)) return;
|
)) return;
|
||||||
|
|
||||||
@ -20256,7 +20259,7 @@
|
|||||||
wsUri = await localbitcoinplusplus.kademlia.getSupernodeSeed(idbData.myLocalFLOAddress);
|
wsUri = await localbitcoinplusplus.kademlia.getSupernodeSeed(idbData.myLocalFLOAddress);
|
||||||
|
|
||||||
if (localbitcoinplusplus.master_configurations.supernodesPubKeys.includes(idbData.myLocalFLOPublicKey)) {
|
if (localbitcoinplusplus.master_configurations.supernodesPubKeys.includes(idbData.myLocalFLOPublicKey)) {
|
||||||
|
return;
|
||||||
showMessage(`INFO: Syncing of latest data starting. This could take some time. Do not close the window until then.`);
|
showMessage(`INFO: Syncing of latest data starting. This could take some time. Do not close the window until then.`);
|
||||||
|
|
||||||
// Get data for deposits and withdraw starting from first (and currently alive) backup supernode
|
// Get data for deposits and withdraw starting from first (and currently alive) backup supernode
|
||||||
@ -20954,8 +20957,7 @@
|
|||||||
if (typeof reserve_res == "object") {
|
if (typeof reserve_res == "object") {
|
||||||
reserve_res.map(reserves => {
|
reserve_res.map(reserves => {
|
||||||
reserves.balance = balance;
|
reserves.balance = balance;
|
||||||
_updateinDB('system_btc_reserves_private_keys', reserves,
|
_updateinDB('system_btc_reserves_private_keys', reserves, reserves.id);
|
||||||
reserves.id);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user