added switchToBackupWS function to switch to backup ws
This commit is contained in:
parent
8382ff55f8
commit
2245c3e780
@ -10344,15 +10344,20 @@
|
|||||||
},
|
},
|
||||||
updateClosestSupernodeSeeds: function(flo_addr) {
|
updateClosestSupernodeSeeds: function(flo_addr) {
|
||||||
return new Promise(async (resolve, reject) => {
|
return new Promise(async (resolve, reject) => {
|
||||||
let nearestSupernodeAddresslist = await localbitcoinplusplus.kademlia.addClosestSupernodeInDB(flo_addr);
|
|
||||||
await removeAllinDB('myClosestSupernodes');
|
await removeAllinDB('myClosestSupernodes');
|
||||||
|
let nearestSupernodeAddresslist = await localbitcoinplusplus.kademlia.addClosestSupernodeInDB(flo_addr);
|
||||||
nearestSupernodeAddresslist.map((nearestSupernodeAddress, index)=>{
|
nearestSupernodeAddresslist.map((nearestSupernodeAddress, index)=>{
|
||||||
updateinDB('myClosestSupernodes', {
|
updateinDB('myClosestSupernodes', {
|
||||||
id: index+1,
|
id: index+1,
|
||||||
ip: nearestSupernodeAddress.ip,
|
ip: nearestSupernodeAddress.ip,
|
||||||
port: nearestSupernodeAddress.port,
|
port: nearestSupernodeAddress.port,
|
||||||
trader_flo_address: nearestSupernodeAddress.kbucketId
|
trader_flo_address: nearestSupernodeAddress.kbucketId
|
||||||
}).then(res=>showMessage(`INFO: Updated closest supernodes list successfully.`));
|
}).then(updatedClosestSupernodes=>{
|
||||||
|
readAllDB('myClosestSupernodes').then(nearestSupernodeAddresslist=>{
|
||||||
|
showMessage(`INFO: Updated closest supernodes list successfully.`);
|
||||||
|
resolve(nearestSupernodeAddresslist);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
@ -10613,6 +10618,7 @@
|
|||||||
displayMessages();
|
displayMessages();
|
||||||
setTimeout(function(){
|
setTimeout(function(){
|
||||||
closeMessage();
|
closeMessage();
|
||||||
|
clearTimeout();
|
||||||
}, t);
|
}, t);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -11074,6 +11080,24 @@
|
|||||||
return callback(false);
|
return callback(false);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
filter_legit_backup_requests: function (flo_id=null, callback) {
|
||||||
|
if (typeof localbitcoinplusplus.wallets.MY_SUPERNODE_PRIVATE_KEY === "string" &&
|
||||||
|
localbitcoinplusplus.wallets.MY_SUPERNODE_PRIVATE_KEY.length > 0
|
||||||
|
) {
|
||||||
|
const RM_WALLET = new localbitcoinplusplus.wallets;
|
||||||
|
let user_keys = RM_WALLET.generateFloKeys(localbitcoinplusplus.wallets.MY_SUPERNODE_PRIVATE_KEY);
|
||||||
|
if (typeof user_keys == "object" && typeof user_keys.pubKeyHex == "string") {
|
||||||
|
if (localbitcoinplusplus.master_configurations
|
||||||
|
.supernodesPubKeys.includes(user_keys.pubKeyHex)) {
|
||||||
|
return callback(true);
|
||||||
|
} else {
|
||||||
|
return callback(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return callback(false);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
async receive_rpc_response(request) {
|
async receive_rpc_response(request) {
|
||||||
var request = JSON.parse(request);
|
var request = JSON.parse(request);
|
||||||
@ -11418,9 +11442,7 @@
|
|||||||
"store_shamirs_secret_pvtkey_shares",
|
"store_shamirs_secret_pvtkey_shares",
|
||||||
shares
|
shares
|
||||||
);
|
);
|
||||||
doSend(
|
doSend(store_pvtkey_req);
|
||||||
store_pvtkey_req
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (typeof localbitcoinplusplus
|
if (typeof localbitcoinplusplus
|
||||||
@ -11443,8 +11465,7 @@
|
|||||||
let
|
let
|
||||||
this_btc_pvt_key_shamirs_secret__id_array =
|
this_btc_pvt_key_shamirs_secret__id_array =
|
||||||
this_btc_pvt_key_shamirs_secret_array
|
this_btc_pvt_key_shamirs_secret_array
|
||||||
.map(i => i
|
.map(i => i.id);
|
||||||
.id);
|
|
||||||
let
|
let
|
||||||
btc_private_key_shamirs_id =
|
btc_private_key_shamirs_id =
|
||||||
this_btc_pvt_key_shamirs_secret__id_array;
|
this_btc_pvt_key_shamirs_secret__id_array;
|
||||||
@ -12746,14 +12767,17 @@
|
|||||||
sendTransaction(crypto_type, utxo_addr, utxo_addr_wif, receiver_address, receiving_amount,
|
sendTransaction(crypto_type, utxo_addr, utxo_addr_wif, receiver_address, receiving_amount,
|
||||||
receiving_amount_currency = null, change_adress, callback) {
|
receiving_amount_currency = null, change_adress, callback) {
|
||||||
let blockchain_explorer;
|
let blockchain_explorer;
|
||||||
|
let divDecimal = 1;
|
||||||
if (crypto_type == "BTC") {
|
if (crypto_type == "BTC") {
|
||||||
blockchain_explorer = localbitcoinplusplus.server.btc_mainnet;
|
blockchain_explorer = localbitcoinplusplus.server.btc_mainnet;
|
||||||
} else if (crypto_type == "BTC_TEST") {
|
} else if (crypto_type == "BTC_TEST") {
|
||||||
blockchain_explorer = localbitcoinplusplus.server.btc_testnet;
|
blockchain_explorer = localbitcoinplusplus.server.btc_testnet;
|
||||||
} else if (crypto_type == "FLO") {
|
} else if (crypto_type == "FLO") {
|
||||||
blockchain_explorer = localbitcoinplusplus.server.flo_mainnet;
|
blockchain_explorer = localbitcoinplusplus.server.flo_mainnet;
|
||||||
|
divDecimal = 100000000;
|
||||||
} else if (crypto_type == "FLO_TEST") {
|
} else if (crypto_type == "FLO_TEST") {
|
||||||
blockchain_explorer = localbitcoinplusplus.server.flo_testnet;
|
blockchain_explorer = localbitcoinplusplus.server.flo_testnet;
|
||||||
|
divDecimal = 100000000;
|
||||||
}
|
}
|
||||||
|
|
||||||
let url = `${blockchain_explorer}/api/addr/${utxo_addr}/utxo`;
|
let url = `${blockchain_explorer}/api/addr/${utxo_addr}/utxo`;
|
||||||
@ -12785,7 +12809,7 @@
|
|||||||
for (var key in utxo_list) {
|
for (var key in utxo_list) {
|
||||||
if (utxo_list[key].confirmations > 0) {
|
if (utxo_list[key].confirmations > 0) {
|
||||||
var obj = utxo_list[key];
|
var obj = utxo_list[key];
|
||||||
sum += obj.satoshis;
|
sum += obj.satoshis / divDecimal;
|
||||||
|
|
||||||
if (btc_eq_receiving_amount <= sum) {
|
if (btc_eq_receiving_amount <= sum) {
|
||||||
trx.addinput(obj.txid, obj.vout, obj.scriptPubKey);
|
trx.addinput(obj.txid, obj.vout, obj.scriptPubKey);
|
||||||
@ -12796,7 +12820,7 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sum = parseFloat(sum / 100000000).toFixed(8);
|
//sum = parseFloat(sum / 100000000).toFixed(8);
|
||||||
|
|
||||||
let change_amount = sum - btc_eq_receiving_amount - 0.00006060;
|
let change_amount = sum - btc_eq_receiving_amount - 0.00006060;
|
||||||
|
|
||||||
@ -13544,13 +13568,17 @@
|
|||||||
|
|
||||||
RM_WALLET.distributeShamirsSecretShares(newKeys.privateKeyWIF)
|
RM_WALLET.distributeShamirsSecretShares(newKeys.privateKeyWIF)
|
||||||
.then(() => privateKeyBuilder())
|
.then(() => privateKeyBuilder())
|
||||||
// .finally(()=>{
|
.finally(()=>{
|
||||||
// if (typeof localbitcoinplusplus.wallets.MY_SUPERNODE_PRIVATE_KEY=='string'
|
if (typeof localbitcoinplusplus.wallets.MY_SUPERNODE_PRIVATE_KEY=='string'
|
||||||
// && localbitcoinplusplus.wallets.MY_SUPERNODE_PRIVATE_KEY.length>0) {
|
&& localbitcoinplusplus.wallets.MY_SUPERNODE_PRIVATE_KEY.length<1) {
|
||||||
// loadExternalFiles();
|
setTimeout(function(){
|
||||||
// dataBaseUIOperations();
|
RM_WALLET.manually_assign_my_private_key();
|
||||||
// }
|
loadExternalFiles();
|
||||||
// });
|
dataBaseUIOperations();
|
||||||
|
clearTimeout();
|
||||||
|
}, 10000);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// Connect with backup supernodes
|
// Connect with backup supernodes
|
||||||
wsUri.filter((uri, index)=>{
|
wsUri.filter((uri, index)=>{
|
||||||
@ -13589,6 +13617,13 @@
|
|||||||
|
|
||||||
wsUri = await localbitcoinplusplus.kademlia.getSupernodeSeed(idbData.myLocalFLOAddress);
|
wsUri = await localbitcoinplusplus.kademlia.getSupernodeSeed(idbData.myLocalFLOAddress);
|
||||||
|
|
||||||
|
if (localbitcoinplusplus.master_configurations.supernodesPubKeys.includes(idbData.myLocalFLOPublicKey)) {
|
||||||
|
if (wsUri[0].trader_flo_address !== idbData.myLocalFLOAddress) {
|
||||||
|
showMessage(`INFO: Invalid connection. Refreshing the closest supernode list in DB.`);
|
||||||
|
wsUri = await localbitcoinplusplus.kademlia.updateClosestSupernodeSeeds(idbData.myLocalFLOAddress);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Add close supernodes to KBucket
|
// Add close supernodes to KBucket
|
||||||
wsUri.map(d=>{
|
wsUri.map(d=>{
|
||||||
localbitcoinplusplus.kademlia.addNewUserNodeInKbucket(
|
localbitcoinplusplus.kademlia.addNewUserNodeInKbucket(
|
||||||
@ -13599,13 +13634,20 @@
|
|||||||
localbitcoinplusplus.kademlia.restoreSupernodeKBucket();
|
localbitcoinplusplus.kademlia.restoreSupernodeKBucket();
|
||||||
|
|
||||||
// Connect with primary supernodes
|
// Connect with primary supernodes
|
||||||
startWebSocket(`ws://${wsUri[0].ip}:${wsUri[0].port}`);
|
await startWebSocket(`ws://${wsUri[0].ip}:${wsUri[0].port}`);
|
||||||
|
|
||||||
// rebuild private key
|
// rebuild private key
|
||||||
await privateKeyBuilder();
|
await privateKeyBuilder();
|
||||||
|
|
||||||
//loadExternalFiles();
|
setTimeout(function(){
|
||||||
//dataBaseUIOperations();
|
if (typeof localbitcoinplusplus.wallets.MY_SUPERNODE_PRIVATE_KEY!=='string'
|
||||||
|
|| localbitcoinplusplus.wallets.MY_SUPERNODE_PRIVATE_KEY.length<1) {
|
||||||
|
RM_WALLET.manually_assign_my_private_key();
|
||||||
|
loadExternalFiles();
|
||||||
|
dataBaseUIOperations();
|
||||||
|
clearTimeout();
|
||||||
|
}
|
||||||
|
}, 10000);
|
||||||
|
|
||||||
localbitcoinplusplus.MY_SUPERNODE_FLO_ADDRESS = wsUri[0].trader_flo_address;
|
localbitcoinplusplus.MY_SUPERNODE_FLO_ADDRESS = wsUri[0].trader_flo_address;
|
||||||
|
|
||||||
@ -13663,7 +13705,7 @@
|
|||||||
if (typeof res_obj.params == "object"
|
if (typeof res_obj.params == "object"
|
||||||
&& typeof res_obj.params[0] == "object") {
|
&& typeof res_obj.params[0] == "object") {
|
||||||
let received_resp = res_obj.params[0];
|
let received_resp = res_obj.params[0];
|
||||||
RM_RPC.filter_legit_requests(received_resp.trader_flo_address,
|
RM_RPC.filter_legit_backup_requests(received_resp.trader_flo_address,
|
||||||
function (is_valid_request) {
|
function (is_valid_request) {
|
||||||
if(!is_valid_request || received_resp.JOB!=="BACKUP_SERVER_REQUEST") return;
|
if(!is_valid_request || received_resp.JOB!=="BACKUP_SERVER_REQUEST") return;
|
||||||
const requester_supernode_pubkey = received_resp.requesters_pub_key;
|
const requester_supernode_pubkey = received_resp.requesters_pub_key;
|
||||||
@ -13689,19 +13731,15 @@
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "backup_server_sync_response":
|
case "server_sync_response":
|
||||||
if (typeof res_obj.params == "object"
|
if (typeof res_obj.params == "object"
|
||||||
&& typeof res_obj.params[0] == "object") {
|
&& typeof res_obj.params[0] == "object") {
|
||||||
let su_backup_db_data = res_obj.params[0];
|
let su_backup_db_data = res_obj.params[0];
|
||||||
RM_RPC.filter_legit_requests(su_backup_db_data.trader_flo_address,
|
RM_RPC.filter_legit_backup_requests(su_backup_db_data.trader_flo_address,
|
||||||
function (is_valid_request) {
|
function (is_valid_request) {
|
||||||
if(!is_valid_request) return false;
|
if(!is_valid_request) return false;
|
||||||
|
|
||||||
if (typeof localbitcoinplusplus.wallets.my_local_flo_address !== "string" ||
|
const backup_server_db_instance = localbitcoinplusplus.newBackupDatabase.db[res_obj.globalParams.senderFloId];
|
||||||
su_backup_db_data.receiver_flo_address !== localbitcoinplusplus.wallets.my_local_flo_address
|
|
||||||
) return false;
|
|
||||||
|
|
||||||
const backup_server_db_instance = localbitcoinplusplus.newBackupDatabase.db[su_backup_db_data.trader_flo_address];
|
|
||||||
|
|
||||||
if(typeof backup_server_db_instance !== "object") {
|
if(typeof backup_server_db_instance !== "object") {
|
||||||
let backup_db_error_msg = `WARNING: Unknown DB instance. DB Backup failed.`;
|
let backup_db_error_msg = `WARNING: Unknown DB instance. DB Backup failed.`;
|
||||||
@ -13749,18 +13787,53 @@
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case "trade_buy_request_response":
|
case "trade_buy_request_response":
|
||||||
if (typeof res_obj.params == "object" && typeof res_obj.params[0] == "object") {
|
RM_RPC.filter_legit_backup_requests(su_backup_db_data.trader_flo_address,
|
||||||
let buyOrders_data = res_obj.params[0];
|
function (is_valid_request) {
|
||||||
|
|
||||||
|
if(!is_valid_request) return false;
|
||||||
|
|
||||||
|
if (typeof res_obj.params == "object" && typeof res_obj.params[0] == "object") {
|
||||||
|
let buyOrders_data = res_obj.params[0];
|
||||||
|
|
||||||
if (typeof localbitcoinplusplus.master_configurations.supernodesPubKeys == "object" &&
|
if (typeof localbitcoinplusplus.master_configurations.supernodesPubKeys == "object" &&
|
||||||
localbitcoinplusplus.master_configurations.supernodesPubKeys.includes(
|
localbitcoinplusplus.master_configurations.supernodesPubKeys.includes(
|
||||||
buyOrders_data.supernodePubKey)) {
|
buyOrders_data.supernodePubKey)) {
|
||||||
|
let isDataSignedBySuperNode = RM_WALLET
|
||||||
|
.verify(buyOrders_data.data_hash, buyOrders_data.supernode_sign,
|
||||||
|
buyOrders_data.supernodePubKey);
|
||||||
|
if (isDataSignedBySuperNode === true) {
|
||||||
|
|
||||||
|
const backup_server_db_instance = localbitcoinplusplus.newBackupDatabase.db[res_obj.globalParams.senderFloId];
|
||||||
|
|
||||||
|
if(typeof backup_server_db_instance !== "object") {
|
||||||
|
let backup_db_error_msg = `WARNING: Unknown DB instance. DB Backup failed.`;
|
||||||
|
showMessage(backup_db_error_msg);
|
||||||
|
throw new Error(backup_db_error_msg);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Add buy order
|
||||||
|
backup_server_db_instance.backup_addDB("buyOrders", buyOrders_data).then(() => {
|
||||||
|
showMessage(`Your buy order is placed successfully.`);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "trade_sell_request_response":
|
||||||
|
RM_RPC.filter_legit_backup_requests(su_backup_db_data.trader_flo_address,
|
||||||
|
function (is_valid_request) {
|
||||||
|
if(!is_valid_request) return false;
|
||||||
|
if (typeof res_obj.params == "object" && typeof res_obj.params[0] == "object") {
|
||||||
|
let sellOrders_data = res_obj.params[0];
|
||||||
|
if (typeof localbitcoinplusplus.master_configurations.supernodesPubKeys == "object" &&
|
||||||
|
localbitcoinplusplus.master_configurations.supernodesPubKeys
|
||||||
|
.includes(sellOrders_data.supernodePubKey)) {
|
||||||
let isDataSignedBySuperNode = RM_WALLET
|
let isDataSignedBySuperNode = RM_WALLET
|
||||||
.verify(buyOrders_data.data_hash, buyOrders_data.supernode_sign,
|
.verify(sellOrders_data.data_hash, sellOrders_data.supernode_sign,
|
||||||
buyOrders_data.supernodePubKey);
|
sellOrders_data.supernodePubKey);
|
||||||
if (isDataSignedBySuperNode === true) {
|
if (isDataSignedBySuperNode === true) {
|
||||||
|
const backup_server_db_instance = localbitcoinplusplus.newBackupDatabase.db[res_obj.globalParams.senderFloId];
|
||||||
const backup_server_db_instance = localbitcoinplusplus.newBackupDatabase.db[su_backup_db_data.trader_flo_address];
|
|
||||||
|
|
||||||
if(typeof backup_server_db_instance !== "object") {
|
if(typeof backup_server_db_instance !== "object") {
|
||||||
let backup_db_error_msg = `WARNING: Unknown DB instance. DB Backup failed.`;
|
let backup_db_error_msg = `WARNING: Unknown DB instance. DB Backup failed.`;
|
||||||
@ -13769,198 +13842,191 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Add buy order
|
// Add buy order
|
||||||
backup_server_db_instance.backup_addDB("buyOrders", buyOrders_data).then(() => {
|
backup_server_db_instance.backup_addDB("sellOrders", sellOrders_data).then(() => {
|
||||||
showMessage(`Your buy order is placed successfully.`);
|
showMessage(`Your sell order is placed successfully.`);
|
||||||
});
|
});;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
break;
|
|
||||||
case "trade_sell_request_response":
|
|
||||||
if (typeof res_obj.params == "object" && typeof res_obj.params[0] == "object") {
|
|
||||||
let sellOrders_data = res_obj.params[0];
|
|
||||||
if (typeof localbitcoinplusplus.master_configurations.supernodesPubKeys == "object" &&
|
|
||||||
localbitcoinplusplus.master_configurations.supernodesPubKeys.includes(
|
|
||||||
sellOrders_data
|
|
||||||
.supernodePubKey)) {
|
|
||||||
let isDataSignedBySuperNode = RM_WALLET
|
|
||||||
.verify(sellOrders_data.data_hash, sellOrders_data.supernode_sign,
|
|
||||||
sellOrders_data.supernodePubKey);
|
|
||||||
if (isDataSignedBySuperNode === true) {
|
|
||||||
const backup_server_db_instance = localbitcoinplusplus.newBackupDatabase.db[su_backup_db_data.trader_flo_address];
|
|
||||||
|
|
||||||
if(typeof backup_server_db_instance !== "object") {
|
|
||||||
let backup_db_error_msg = `WARNING: Unknown DB instance. DB Backup failed.`;
|
|
||||||
showMessage(backup_db_error_msg);
|
|
||||||
throw new Error(backup_db_error_msg);
|
|
||||||
};
|
|
||||||
|
|
||||||
// Add buy order
|
|
||||||
backup_server_db_instance.backup_addDB("sellOrders", sellOrders_data).then(() => {
|
|
||||||
showMessage(`Your sell order is placed successfully.`);
|
|
||||||
});;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "deposit_asset_request_response":
|
case "deposit_asset_request_response":
|
||||||
if (typeof res_obj.params == "object" && typeof res_obj.params[0] == "object" && typeof res_obj
|
RM_RPC.filter_legit_backup_requests(su_backup_db_data.trader_flo_address,
|
||||||
.params[0].data == "object") {
|
function (is_valid_request) {
|
||||||
let resp = res_obj.params[0];
|
if(!is_valid_request) return false;
|
||||||
if (RM_WALLET
|
if (typeof res_obj.params == "object" && typeof res_obj.params[0] == "object"
|
||||||
.verify(resp.data.depositDataHash, resp.data.order_validator_sign, resp.data.order_validator_public_key)
|
&& typeof res_obj.params[0].data == "object") {
|
||||||
) {
|
let resp = res_obj.params[0];
|
||||||
const backup_server_db_instance = localbitcoinplusplus.newBackupDatabase.db[su_backup_db_data.trader_flo_address];
|
if (RM_WALLET
|
||||||
|
.verify(resp.data.depositDataHash, resp.data.order_validator_sign, resp.data.order_validator_public_key)
|
||||||
|
) {
|
||||||
|
const backup_server_db_instance = localbitcoinplusplus.newBackupDatabase.db[res_obj.globalParams.senderFloId];
|
||||||
|
|
||||||
if(typeof backup_server_db_instance !== "object") {
|
if(typeof backup_server_db_instance !== "object") {
|
||||||
let backup_db_error_msg = `WARNING: Unknown DB instance. DB Backup failed.`;
|
let backup_db_error_msg = `WARNING: Unknown DB instance. DB Backup failed.`;
|
||||||
showMessage(backup_db_error_msg);
|
showMessage(backup_db_error_msg);
|
||||||
throw new Error(backup_db_error_msg);
|
throw new Error(backup_db_error_msg);
|
||||||
};
|
};
|
||||||
|
|
||||||
backup_server_db_instance.backup_addDB('deposit', resp.data);
|
backup_server_db_instance.backup_addDB('deposit', resp.data);
|
||||||
if (typeof resp.withdrawer_data == "object") {
|
if (typeof resp.withdrawer_data == "object") {
|
||||||
backup_server_db_instance.backup_updateinDB("withdraw_cash", resp.withdrawer_data, resp.withdrawer_data.trader_flo_address);
|
backup_server_db_instance.backup_updateinDB("withdraw_cash", resp.withdrawer_data, resp.withdrawer_data.trader_flo_address);
|
||||||
}
|
|
||||||
backup_server_db_instance.backup_readDB("localbitcoinUser", "00-01").then(function (user) {
|
|
||||||
if (typeof user == "object" && user.myLocalFLOAddress == resp.data.trader_flo_address) {
|
|
||||||
let counterTraderAccountAddress =
|
|
||||||
`<p><strong>Please pay the amount to following address:</strong></p>
|
|
||||||
<p>${resp.msg}</p>`;
|
|
||||||
showMessage(counterTraderAccountAddress);
|
|
||||||
modalWindow(counterTraderAccountAddress);
|
|
||||||
}
|
}
|
||||||
});
|
backup_server_db_instance.backup_readDB("localbitcoinUser", "00-01").then(function (user) {
|
||||||
|
if (typeof user == "object" && user.myLocalFLOAddress == resp.data.trader_flo_address) {
|
||||||
|
let counterTraderAccountAddress =
|
||||||
|
`<p><strong>Please pay the amount to following address:</strong></p>
|
||||||
|
<p>${resp.msg}</p>`;
|
||||||
|
showMessage(counterTraderAccountAddress);
|
||||||
|
modalWindow(counterTraderAccountAddress);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "withdrawal_request_response":
|
case "withdrawal_request_response":
|
||||||
if (typeof res_obj.params == "object" && typeof res_obj.params[0] == "object") {
|
RM_RPC.filter_legit_backup_requests(su_backup_db_data.trader_flo_address,
|
||||||
if (RM_WALLET
|
function (is_valid_request) {
|
||||||
.verify(res_obj.params[0].withdrawDataHash, res_obj.params[0].order_validator_sign,
|
if(!is_valid_request) return false;
|
||||||
res_obj.params[0].order_validator_public_key)) {
|
if (typeof res_obj.params == "object" && typeof res_obj.params[0] == "object") {
|
||||||
|
if (RM_WALLET
|
||||||
|
.verify(res_obj.params[0].withdrawDataHash, res_obj.params[0].order_validator_sign,
|
||||||
|
res_obj.params[0].order_validator_public_key)) {
|
||||||
|
|
||||||
const backup_server_db_instance = localbitcoinplusplus.newBackupDatabase.db[su_backup_db_data.trader_flo_address];
|
const backup_server_db_instance = localbitcoinplusplus.newBackupDatabase.db[res_obj.globalParams.senderFloId];
|
||||||
|
|
||||||
if(typeof backup_server_db_instance !== "object") {
|
if(typeof backup_server_db_instance !== "object") {
|
||||||
let backup_db_error_msg = `WARNING: Unknown DB instance. DB Backup failed.`;
|
let backup_db_error_msg = `WARNING: Unknown DB instance. DB Backup failed.`;
|
||||||
showMessage(backup_db_error_msg);
|
showMessage(backup_db_error_msg);
|
||||||
throw new Error(backup_db_error_msg);
|
throw new Error(backup_db_error_msg);
|
||||||
};
|
};
|
||||||
|
|
||||||
backup_server_db_instance.backup_addDB('withdraw_cash', res_obj.params[0]).then(() => {
|
backup_server_db_instance.backup_addDB('withdraw_cash', res_obj.params[0]).then(() => {
|
||||||
showMessage(`Your cash withdrawal request is placed successfully.`);
|
showMessage(`Your cash withdrawal request is placed successfully.`);
|
||||||
});
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "cancel_trade":
|
case "cancel_trade":
|
||||||
if (typeof res_obj.params == "object" && typeof res_obj.params[0] == "object") {
|
RM_RPC.filter_legit_backup_requests(su_backup_db_data.trader_flo_address,
|
||||||
let cancel_request = res_obj.params[0];
|
function (is_valid_request) {
|
||||||
if (cancel_request.job == "cancel_trade_request") {
|
if(!is_valid_request) return false;
|
||||||
const backup_server_db_instance = localbitcoinplusplus.newBackupDatabase.db[su_backup_db_data.trader_flo_address];
|
if (typeof res_obj.params == "object" && typeof res_obj.params[0] == "object") {
|
||||||
|
let cancel_request = res_obj.params[0];
|
||||||
|
if (cancel_request.job == "cancel_trade_request") {
|
||||||
|
const backup_server_db_instance = localbitcoinplusplus.newBackupDatabase.db[res_obj.globalParams.senderFloId];
|
||||||
|
|
||||||
if(typeof backup_server_db_instance !== "object") {
|
if(typeof backup_server_db_instance !== "object") {
|
||||||
let backup_db_error_msg = `WARNING: Unknown DB instance. DB Backup failed.`;
|
let backup_db_error_msg = `WARNING: Unknown DB instance. DB Backup failed.`;
|
||||||
showMessage(backup_db_error_msg);
|
showMessage(backup_db_error_msg);
|
||||||
throw new Error(backup_db_error_msg);
|
throw new Error(backup_db_error_msg);
|
||||||
};
|
};
|
||||||
|
|
||||||
backup_server_db_instance.backup_readDB("userPublicData", cancel_request.trader_flo_address).then((trader_data) => {
|
backup_server_db_instance.backup_readDB("userPublicData", cancel_request.trader_flo_address).then((trader_data) => {
|
||||||
if (typeof trader_data.trader_flo_address !== "string" || typeof trader_data
|
if (typeof trader_data.trader_flo_address !== "string" || typeof trader_data
|
||||||
.trader_flo_pubKey !== "string") {
|
.trader_flo_pubKey !== "string") {
|
||||||
err_msg="ERROR: Failed to cancel the trade. User is unknown.";
|
err_msg="ERROR: Failed to cancel the trade. User is unknown.";
|
||||||
showMessage(err_msg);
|
showMessage(err_msg);
|
||||||
throw new Error(err_msg);
|
throw new Error(err_msg);
|
||||||
}
|
}
|
||||||
tradeDB = cancel_request.trade_type == "buy" ? "buyOrders" :
|
tradeDB = cancel_request.trade_type == "buy" ? "buyOrders" :
|
||||||
"sellOrders";
|
"sellOrders";
|
||||||
if (RM_WALLET
|
if (RM_WALLET
|
||||||
.verify(cancel_request.trade_id, cancel_request.signed_trade_id,
|
.verify(cancel_request.trade_id, cancel_request.signed_trade_id,
|
||||||
trader_data.trader_flo_pubKey)) {
|
trader_data.trader_flo_pubKey)) {
|
||||||
backup_server_db_instance.backup_removeinDB(tradeDB, cancel_request.trade_id)
|
backup_server_db_instance.backup_removeinDB(tradeDB, cancel_request.trade_id)
|
||||||
.then((id) => showMessage(`Trade Id ${id} deleted.`));
|
.then((id) => showMessage(`Trade Id ${id} deleted.`));
|
||||||
|
} else {
|
||||||
|
showMessage(
|
||||||
|
`Failed to verify trade for trade id ${cancel_request.trade_id}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
})
|
||||||
} else {
|
} else {
|
||||||
showMessage(
|
showMessage("Failed to cancel trade.");
|
||||||
`Failed to verify trade for trade id ${cancel_request.trade_id}`
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
} else {
|
});
|
||||||
showMessage("Failed to cancel trade.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "update_all_withdraw_cash_depositor_claim":
|
case "update_all_withdraw_cash_depositor_claim":
|
||||||
if (typeof res_obj.params == "object" && typeof res_obj.params[0] == "object") {
|
RM_RPC.filter_legit_backup_requests(su_backup_db_data.trader_flo_address,
|
||||||
let depositor_claim_response_object = res_obj.params[0];
|
function (is_valid_request) {
|
||||||
let update_withdraw_cash_obj_data_res = {
|
if(!is_valid_request) return false;
|
||||||
depositor_claim: depositor_claim_response_object.depositor_claim
|
if (typeof res_obj.params == "object" && typeof res_obj.params[0] == "object") {
|
||||||
};
|
let depositor_claim_response_object = res_obj.params[0];
|
||||||
let update_withdraw_cash_obj_data_res_str = JSON.stringify(
|
let update_withdraw_cash_obj_data_res = {
|
||||||
update_withdraw_cash_obj_data_res);
|
depositor_claim: depositor_claim_response_object.depositor_claim
|
||||||
let depositor_claim_response_data_hash = Crypto.SHA256(
|
};
|
||||||
update_withdraw_cash_obj_data_res_str);
|
let update_withdraw_cash_obj_data_res_str = JSON.stringify(
|
||||||
let depositor_claim_response_object_verification = RM_WALLET
|
update_withdraw_cash_obj_data_res);
|
||||||
.verify(depositor_claim_response_data_hash, depositor_claim_response_object.sign,
|
let depositor_claim_response_data_hash = Crypto.SHA256(
|
||||||
depositor_claim_response_object.publicKey);
|
update_withdraw_cash_obj_data_res_str);
|
||||||
|
let depositor_claim_response_object_verification = RM_WALLET
|
||||||
|
.verify(depositor_claim_response_data_hash, depositor_claim_response_object.sign,
|
||||||
|
depositor_claim_response_object.publicKey);
|
||||||
|
|
||||||
if ((depositor_claim_response_data_hash == depositor_claim_response_object.hash) &&
|
if ((depositor_claim_response_data_hash == depositor_claim_response_object.hash) &&
|
||||||
(depositor_claim_response_object_verification == true)) {
|
(depositor_claim_response_object_verification == true)) {
|
||||||
const backup_server_db_instance = localbitcoinplusplus.newBackupDatabase.db[su_backup_db_data.trader_flo_address];
|
const backup_server_db_instance = localbitcoinplusplus.newBackupDatabase.db[res_obj.globalParams.senderFloId];
|
||||||
|
|
||||||
if(typeof backup_server_db_instance !== "object") {
|
if(typeof backup_server_db_instance !== "object") {
|
||||||
let backup_db_error_msg = `WARNING: Unknown DB instance. DB Backup failed.`;
|
let backup_db_error_msg = `WARNING: Unknown DB instance. DB Backup failed.`;
|
||||||
showMessage(backup_db_error_msg);
|
showMessage(backup_db_error_msg);
|
||||||
throw new Error(backup_db_error_msg);
|
throw new Error(backup_db_error_msg);
|
||||||
};
|
};
|
||||||
|
|
||||||
backup_server_db_instance.backup_updateinDB('withdraw_cash', depositor_claim_response_object.depositor_claim,
|
backup_server_db_instance.backup_updateinDB('withdraw_cash', depositor_claim_response_object.depositor_claim,
|
||||||
depositor_claim_response_object.depositor_claim.id);
|
depositor_claim_response_object.depositor_claim.id);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
});
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "update_all_deposit_withdraw_success":
|
case "update_all_deposit_withdraw_success":
|
||||||
if (typeof res_obj.params == "object" && typeof res_obj.params[0] == "object") {
|
RM_RPC.filter_legit_backup_requests(su_backup_db_data.trader_flo_address,
|
||||||
let withdraw_success_response = res_obj.params[0];
|
function (is_valid_request) {
|
||||||
let update_cash_balance_obj_res = {
|
if(!is_valid_request) return false;
|
||||||
depositor_cash_data: withdraw_success_response.depositor_cash_data
|
if (typeof res_obj.params == "object" && typeof res_obj.params[0] == "object") {
|
||||||
}
|
let withdraw_success_response = res_obj.params[0];
|
||||||
let update_cash_balance_obj_res_str = JSON.stringify(update_cash_balance_obj_res);
|
let update_cash_balance_obj_res = {
|
||||||
let update_cash_balance_obj_res_hash = Crypto.SHA256(
|
depositor_cash_data: withdraw_success_response.depositor_cash_data
|
||||||
update_cash_balance_obj_res_str);
|
}
|
||||||
let update_cash_balance_obj_res_verification = RM_WALLET
|
let update_cash_balance_obj_res_str = JSON.stringify(update_cash_balance_obj_res);
|
||||||
.verify(update_cash_balance_obj_res_hash, withdraw_success_response.sign,
|
let update_cash_balance_obj_res_hash = Crypto.SHA256(
|
||||||
withdraw_success_response.publicKey);
|
update_cash_balance_obj_res_str);
|
||||||
|
let update_cash_balance_obj_res_verification = RM_WALLET
|
||||||
|
.verify(update_cash_balance_obj_res_hash, withdraw_success_response.sign,
|
||||||
|
withdraw_success_response.publicKey);
|
||||||
|
|
||||||
if ((update_cash_balance_obj_res_hash == withdraw_success_response.hash) &&
|
if ((update_cash_balance_obj_res_hash == withdraw_success_response.hash) &&
|
||||||
update_cash_balance_obj_res_verification == true) {
|
update_cash_balance_obj_res_verification == true) {
|
||||||
const backup_server_db_instance = localbitcoinplusplus.newBackupDatabase.db[su_backup_db_data.trader_flo_address];
|
const backup_server_db_instance = localbitcoinplusplus.newBackupDatabase.db[res_obj.globalParams.senderFloId];
|
||||||
|
|
||||||
if(typeof backup_server_db_instance !== "object") {
|
if(typeof backup_server_db_instance !== "object") {
|
||||||
let backup_db_error_msg = `WARNING: Unknown DB instance. DB Backup failed.`;
|
let backup_db_error_msg = `WARNING: Unknown DB instance. DB Backup failed.`;
|
||||||
showMessage(backup_db_error_msg);
|
showMessage(backup_db_error_msg);
|
||||||
throw new Error(backup_db_error_msg);
|
throw new Error(backup_db_error_msg);
|
||||||
};
|
};
|
||||||
|
|
||||||
backup_server_db_instance.backup_updateinDB('cash_balances', withdraw_success_response.depositor_cash_data);
|
backup_server_db_instance.backup_updateinDB('cash_balances', withdraw_success_response.depositor_cash_data);
|
||||||
backup_server_db_instance.backup_updateinDB('cash_balances', withdraw_success_response.withdrawer_cash_data);
|
backup_server_db_instance.backup_updateinDB('cash_balances', withdraw_success_response.withdrawer_cash_data);
|
||||||
backup_server_db_instance.backup_removeByIndex('deposit', 'trader_flo_address', withdraw_success_response.depositor_cash_data
|
backup_server_db_instance.backup_removeByIndex('deposit', 'trader_flo_address', withdraw_success_response.depositor_cash_data
|
||||||
.trader_flo_address);
|
.trader_flo_address);
|
||||||
backup_server_db_instance.backup_removeinDB('withdraw_cash', withdraw_success_response.withdraw_id);
|
backup_server_db_instance.backup_removeinDB('withdraw_cash', withdraw_success_response.withdraw_id);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
});
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
@ -13984,16 +14050,71 @@
|
|||||||
console.error(evt);
|
console.error(evt);
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
|
async switchToBackupWS(last_connect_url) {
|
||||||
|
const user_data = await readDB('localbitcoinUser', '00-01');
|
||||||
|
const user_flo_address = user_data.myLocalFLOAddress;
|
||||||
|
|
||||||
|
// Only User nodes can switch websocket connections
|
||||||
|
if(typeof user_data.myLocalFLOAddress !== "string"
|
||||||
|
|| localbitcoinplusplus.master_configurations.supernodesPubKeys
|
||||||
|
.includes(user_data.myLocalFLOAddress)) return false;
|
||||||
|
|
||||||
|
const myClosestSupernodesArray = await readAllDB(`myClosestSupernodes`);
|
||||||
|
|
||||||
|
let nextClosestSupernodeElem = myClosestSupernodesArray
|
||||||
|
.filter((wew, index)=>{
|
||||||
|
let ww = `ws://${wew.ip}:${wew.port}`;
|
||||||
|
if(typeof z =='boolean' && z) {
|
||||||
|
z = false;
|
||||||
|
localbitcoinplusplus.MY_SUPERNODE_FLO_ADDRESS = wew.trader_flo_address;
|
||||||
|
return ww;
|
||||||
|
}
|
||||||
|
if(ww==last_connect_url.replace(/\/$/, '')) z = true;
|
||||||
|
})
|
||||||
|
|
||||||
|
let nextClosestSupernode = `ws://${nextClosestSupernodeElem[0].ip}:${nextClosestSupernodeElem[0].port}`;
|
||||||
|
|
||||||
|
await startWebSocket(nextClosestSupernode);
|
||||||
|
|
||||||
|
if(websocket.readyState===1) {
|
||||||
|
|
||||||
|
showMessage(`INFO: Connected to next closest Supernode: ${nextClosestSupernode}`);
|
||||||
|
|
||||||
|
// Connection established, build private key and UI
|
||||||
|
|
||||||
|
await privateKeyBuilder();
|
||||||
|
|
||||||
|
setTimeout(function(){
|
||||||
|
if (typeof localbitcoinplusplus.wallets.MY_SUPERNODE_PRIVATE_KEY!=='string'
|
||||||
|
|| localbitcoinplusplus.wallets.MY_SUPERNODE_PRIVATE_KEY.length<1) {
|
||||||
|
RM_WALLET.manually_assign_my_private_key();
|
||||||
|
loadExternalFiles();
|
||||||
|
dataBaseUIOperations();
|
||||||
|
clearTimeout();
|
||||||
|
}
|
||||||
|
}, 10000);
|
||||||
|
|
||||||
|
return Promise.resolve(true)
|
||||||
|
} else {
|
||||||
|
let ms = `Error: Failed to connect to any supernode.`;
|
||||||
|
showMessage(ms)
|
||||||
|
return Promise.reject(ms);
|
||||||
|
}
|
||||||
|
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
function startWebSocket(wsUri) {
|
function startWebSocket(wsUri) {
|
||||||
|
console.log(wsUri);
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
websocket = new WebSocket(wsUri);
|
websocket = new WebSocket(wsUri);
|
||||||
websocket.onopen = function (evt) {
|
websocket.onopen = function (evt) {
|
||||||
resolve(onOpen(evt))
|
resolve(onOpen(evt))
|
||||||
};
|
};
|
||||||
websocket.onclose = function (evt) {
|
websocket.onclose = function (evt) {
|
||||||
resolve(onClose(evt))
|
reject(onClose(evt))
|
||||||
};
|
};
|
||||||
websocket.onmessage = function (evt) {
|
websocket.onmessage = function (evt) {
|
||||||
resolve(onMessage(evt))
|
resolve(onMessage(evt))
|
||||||
@ -14005,13 +14126,20 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function onOpen(evt) {
|
function onOpen(evt) {
|
||||||
showMessage(`Connected successfully to Supernode: ws://${wsUri[0].ip}.${wsUri[0].port}`);
|
console.log(evt);
|
||||||
|
showMessage(`Connected successfully to Supernode: ${evt.srcElement.url}`);
|
||||||
writeToScreen("CONNECTED");
|
writeToScreen("CONNECTED");
|
||||||
}
|
}
|
||||||
|
|
||||||
function onClose(evt) {
|
function onClose(evt) {
|
||||||
showMessage(`Disconnected to Supernode sever: ws://${wsUri[0].ip}.${wsUri[0].port}`);
|
console.log(evt);
|
||||||
|
console.log(websocket);
|
||||||
|
showMessage(`Disconnected to Supernode sever: ${evt.srcElement.url}`);
|
||||||
writeToScreen("DISCONNECTED");
|
writeToScreen("DISCONNECTED");
|
||||||
|
|
||||||
|
if(websocket.readyState==1) return;
|
||||||
|
const switchMyWS = new backupSupernodesWebSocketObject();
|
||||||
|
switchMyWS.switchToBackupWS(evt.srcElement.url);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function onMessage(evt) {
|
async function onMessage(evt) {
|
||||||
@ -14892,11 +15020,18 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function onError(evt) {
|
function onError(evt) {
|
||||||
writeToScreen('<span style="color: red;">ERROR:</span> ' + evt.data);
|
showMessage(`ERROR: ${evt.srcElement.url} WS CONNECTION ERROR`);
|
||||||
|
// if(websocket.readyState==1) return;
|
||||||
|
// const switchMyWS = new backupSupernodesWebSocketObject();
|
||||||
|
// switchMyWS.switchToBackupWS(evt.srcElement.url);
|
||||||
}
|
}
|
||||||
|
|
||||||
function doSend(message) {
|
function doSend(message) {
|
||||||
|
|
||||||
|
if(websocket.readyState!==1) {
|
||||||
|
console.warn("Websocket not ready to broadcast messages.");
|
||||||
|
//return;
|
||||||
|
}
|
||||||
const request_array = ['send_back_shamirs_secret_supernode_pvtkey',
|
const request_array = ['send_back_shamirs_secret_supernode_pvtkey',
|
||||||
'retrieve_shamirs_secret_supernode_pvtkey',
|
'retrieve_shamirs_secret_supernode_pvtkey',
|
||||||
'store_shamirs_secret_pvtkey_shares'];
|
'store_shamirs_secret_pvtkey_shares'];
|
||||||
@ -14978,38 +15113,6 @@
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// function doSendToBackupServers(message) {
|
|
||||||
// try {
|
|
||||||
// const supernodesFloAddrList = localbitcoinplusplus.master_configurations.supernodesPubKeys
|
|
||||||
// .map(fid=>bitjs.FLO_TEST.pubkey2address(fid));
|
|
||||||
|
|
||||||
// const messageObject = JSON.parse(message)
|
|
||||||
|
|
||||||
// if(!supernodesFloAddrList.includes(messageObject.globalParams.senderFloId)) return;
|
|
||||||
|
|
||||||
// if(typeof localbitcoinplusplus.wallets.MY_SUPERNODE_PRIVATE_KEY !== "string")
|
|
||||||
// throw new Error(`Private key could not be found.`);
|
|
||||||
|
|
||||||
// const RM_WALLET = localbitcoinplusplus.wallets;
|
|
||||||
|
|
||||||
// const supernodeSignedMessage = RM_WALLET.sign(message, localbitcoinplusplus.wallets.MY_SUPERNODE_PRIVATE_KEY);
|
|
||||||
|
|
||||||
// messageObject.supernodeSignedMessage = supernodeSignedMessage;
|
|
||||||
// messageObject.supernodePubKey = localbitcoinplusplus.wallets.my_local_flo_public_key;
|
|
||||||
// messageObject.messageForOnlySupernodes = true;
|
|
||||||
// messageObject.method = `backup_${messageObject.method}`;
|
|
||||||
|
|
||||||
// const messageString = JSON.stringify(messageObject);
|
|
||||||
|
|
||||||
// supernodesFloAddrList.map(flo_id=>localbitcoinplusplus.encrypt
|
|
||||||
// .messageBroadcasting(messageString, flo_id, messageObject.method));
|
|
||||||
|
|
||||||
// } catch (error) {
|
|
||||||
// console.error(error);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// }
|
|
||||||
|
|
||||||
function writeToScreen(message) {
|
function writeToScreen(message) {
|
||||||
// var pre = document.createElement("p");
|
// var pre = document.createElement("p");
|
||||||
// pre.style.wordWrap = "break-word";
|
// pre.style.wordWrap = "break-word";
|
||||||
@ -15377,6 +15480,7 @@
|
|||||||
|
|
||||||
async function addDB(tablename, dbObject) {
|
async function addDB(tablename, dbObject) {
|
||||||
try {
|
try {
|
||||||
|
if(typeof dbObject.vectorClock == "undefined") dbObject.vectorClock = 0;
|
||||||
let request = db.transaction([tablename], "readwrite")
|
let request = db.transaction([tablename], "readwrite")
|
||||||
let store = request.objectStore(tablename)
|
let store = request.objectStore(tablename)
|
||||||
await store.add(dbObject);
|
await store.add(dbObject);
|
||||||
@ -15390,6 +15494,11 @@
|
|||||||
|
|
||||||
async function updateinDB(tablename, Obj, key) {
|
async function updateinDB(tablename, Obj, key) {
|
||||||
try {
|
try {
|
||||||
|
if(typeof Obj.vectorClock == "undefined") {
|
||||||
|
Obj.vectorClock = 0;
|
||||||
|
} else {
|
||||||
|
Obj.vectorClock += 1;
|
||||||
|
}
|
||||||
var request = db.transaction([tablename], "readwrite")
|
var request = db.transaction([tablename], "readwrite")
|
||||||
let store = request.objectStore(tablename)
|
let store = request.objectStore(tablename)
|
||||||
await store.put(Obj);
|
await store.put(Obj);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user