added actions object in localbitcoinplusplus

This commit is contained in:
Abhishek Sinha 2018-11-04 15:11:00 +05:30
parent b5581a8526
commit 13a6d7e76a

View File

@ -7200,7 +7200,7 @@
configurable: false,
enumerable: false
});
Object.defineProperty(localbitcoinplusplus, 'MASTER_NODE', {
value: "023B9F60692A17FAC805D012C5C8ADA3DD19A980A3C5F0D8A5B3500CC54D6E8B75",
writable: false,
@ -7604,6 +7604,64 @@
return pubHexUncompressed;
}
};
localbitcoinplusplus.actions = {
parse_flo_comments: function (callback) {
if (this.floAddress == null) {
return false;
}
var request = new XMLHttpRequest();
request.open('GET', `${localbitcoinplusplus.flocha}/api/txs/?address=${this.floAddress}`, true);
request.onload = function () {
// Begin accessing JSON data here
var data = JSON.parse(this.response);
if (request.status >= 200 && request.status < 400) {
data.txs.forEach(tx => {
callback(tx.floData);
});
} else {
console.log('error');
}
}
request.send();
},
fetch_configs: function (callback) {
this.floAddress = localbitcoinplusplus.RM_FLO_SENDING_ADDR;
this.parse_flo_comments(function (floData) {
let RMAssets = floData.slice(5);
// remove this line later
//'ValidAssets=BTC,FLO,INR#!#Supernode=oH6e6K8MhBG9VWeLEpTREqeL1YkfizSS22,oHsGVh6r682HxXNT21UXXC42TZatUcGvDB';
let floAssetsArray = RMAssets.split('#!#');
if (floAssetsArray.length > 0 && typeof floAssetsArray[0] != undefined &&
floAssetsArray[0].trim() !== "" && typeof floAssetsArray[1] !== undefined &&
floAssetsArray[1].trim() !== "") {
let validAssetsList = floAssetsArray[0].split('=');
let superNodesList = floAssetsArray[1].split('=');
if (validAssetsList[0] == "ValidAssets" && superNodesList[0].trim() ==
"Supernode" && superNodesList[0].trim().length > 0) {
try {
let fetchedAssestsResponseObject = {
validAssetsArray: validAssetsList[1].split(','),
superNodesArray: superNodesList[1].split(',')
}
callback(fetchedAssestsResponseObject);
} catch (error) {
console.error(error);
callback(error);
}
}
}
});
}
}
</script>
<!-- Keys Object Operations (Generate, Sign and Verify) -->
@ -7751,7 +7809,7 @@
this.product = null;
this.valid_assets = ["BTC", "INR"];
this.currency = null;
this.valid_currencies = ["BTC", "INR"],
this.valid_currencies = ["BTC", "INR"];
this.buy_price = null;
this.buyer_public_key = null;
this.buyer_key_signature = null;
@ -7759,36 +7817,6 @@
this.rpc_job = null;
this.floAddress = null;
this.super_nodes_array = null;
this.fetch_configs = function (callback) {
this.floAddress = localbitcoinplusplus.RM_FLO_SENDING_ADDR;
this.parse_flo_comments(function (floData) {
let RMAssets = floData.slice(5);
// remove this line later
//'ValidAssets=BTC,FLO,INR#!#Supernode=oH6e6K8MhBG9VWeLEpTREqeL1YkfizSS22,oHsGVh6r682HxXNT21UXXC42TZatUcGvDB';
let floAssetsArray = RMAssets.split('#!#');
if(floAssetsArray.length>0 && typeof floAssetsArray[0] != undefined && floAssetsArray[0].trim() !== "" && typeof floAssetsArray[1] !== undefined && floAssetsArray[1].trim() !== "") {
let validAssetsList = floAssetsArray[0].split('=');
let superNodesList = floAssetsArray[1].split('=');
if(validAssetsList[0]=="ValidAssets" && superNodesList[0].trim() == "Supernode" && superNodesList[0].trim().length > 0) {
try {
let fetchedAssestsResponseObject = {
validAssetsArray: validAssetsList[1].split(','),
superNodesArray: superNodesList[1].split(',')
}
callback(fetchedAssestsResponseObject);
} catch (error) {
console.error(error);
callback(error);
}
}
}
});
}
}
Trade.prototype = {
@ -7874,31 +7902,7 @@
},
trade_sell() {
console.log("sell is called");
},
/*Parse Flo Blockchain comments*/
parse_flo_comments(callback) {
if (this.floAddress == null) {
return false;
}
var request = new XMLHttpRequest();
request.open('GET', `${localbitcoinplusplus.flocha}/api/txs/?address=${this.floAddress}`, true);
request.onload = function () {
// Begin accessing JSON data here
var data = JSON.parse(this.response);
if (request.status >= 200 && request.status < 400) {
data.txs.forEach(tx => {
callback(tx.floData);
});
} else {
console.log('error');
}
}
request.send();
}
}
</script>
@ -8308,10 +8312,10 @@
var RM_RPC = new localbitcoinplusplus.rpc;
//Test: fetch flo comment
var rm_configs = RM_TRADE.fetch_configs(function(...fetch_configs_res) {
var rm_configs = localbitcoinplusplus.actions.fetch_configs(function (...fetch_configs_res) {
let local_btc_configs = fetch_configs_res[0];
RM_TRADE.super_nodes_array = local_btc_configs.superNodesArray;
RM_TRADE.valid_assets = local_btc_configs.validAssetsArray;
RM_TRADE.super_nodes_array = local_btc_configs.superNodesArray;
RM_TRADE.valid_assets = local_btc_configs.validAssetsArray;
});
// // Test: Trade functionality
@ -8323,11 +8327,10 @@
doSend(buytrade);
}
document.getElementById("output_div").appendChild(trade_btn);
</script>
<script>
window.onload = function() {
<script>
window.onload = function () {
let ask_flo_addr_btn = document.getElementById('ask_flo_addr_btn');
ask_flo_addr_btn.addEventListener('click', function () {
let ask_flo_addr = document.getElementById('ask_flo_addr');
@ -8338,15 +8341,17 @@
}
try {
readDB(function(idbData) {
readDB(function (idbData) {
//console.log(idbData);
if (typeof idbData.myLocalFLOPrivateKey == undefined || idbData.myLocalFLOPrivateKey.trim() == '') {
if (typeof idbData.myLocalFLOPrivateKey == undefined || idbData.myLocalFLOPrivateKey
.trim() == '') {
let user_pvt_key = prompt("Please Enter your private key");
if (user_pvt_key.trim() != null) {
let newKeys = RM_WALLET.generateFloKeys(user_pvt_key);
if (typeof newKeys == 'object' && typeof newKeys.address !== undefined) {
if (typeof newKeys == 'object' && typeof newKeys.address !==
undefined) {
localbitcoinplusplusObj.myLocalFLOAddress = newKeys.address;
localbitcoinplusplusObj.myLocalFLOPublicKey = newKeys.pubKeyHex;
localbitcoinplusplusObj.myLocalFLOPrivateKey = newKeys.privateKeyWIF;
@ -8354,7 +8359,7 @@
localbitcoinplusplusObj.mySelfDeclaredBalanceFLO = 0;
localbitcoinplusplusObj.mySelfdeclaredBalanceBitcoin = 0;
localbitcoinplusplusObj.mySelfDeclaredBalanceINR = 0;
updateinDB(localbitcoinplusplusObj, "00-01");
}
}
@ -8363,10 +8368,13 @@
} catch (e) {
console.log(e);
throw new Error(
"ERROR: Failed to initialise the database. You are unable to trade at the moment.");
"ERROR: Failed to initialise the database. You are unable to trade at the moment."
);
}
// Further operation here
// Further operation here
console.log("Hello! You are doing great.");
});
}
</script>