From 41eb1dc4524bff40320b826d1135812ae87df96b Mon Sep 17 00:00:00 2001 From: sairaj mote Date: Sun, 20 Oct 2019 01:07:28 +0530 Subject: [PATCH 1/6] added description for floBlockchainAPI and compact IDB operations --- README.md | 112 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 112 insertions(+) diff --git a/README.md b/README.md index 0115093..fd7a439 100644 --- a/README.md +++ b/README.md @@ -78,3 +78,115 @@ This template contains standard operations that can be used for the following: 1. data - data of the given signature 2. signature - signature of the data 3. publicKey - public key of the signer + +## FLO Blockchain API Operations +`floBlockchainAPI` object method can be used to send/recieve data to/from blockchain.These functions are asynchronous and return a promise. Contains the following functions. + +#### promisedAJAX + floBlockchainAPI.promisedAJAX(method, uri) +`promisedAJAX` resolves a responce from server on success or rejects the responce on failure. +1. method - GET/POST + a. GET - Requests data from a specified resource. + b. POST - Submits data to be processed to a specified resource. +2. uri(Uniform Resource Identifier) - identifier for AJAX resource. It is used to create URL(Uniform Resource Locator) for further operations. + +#### getBalalnce + floBlockchainAPI.getBalance(addr) +`getBalance` resolves balance for specified FLO address. +1. addr - FLO address for which balance has to be retrieved. + +#### writeData + floBlockchainAPI.writeData(senderAddr, Data, PrivKey, receiverAddr = floGlobals.adminID) +`writeData` writes data into blockchain. +1. senderAddr - FLO address from which the data and amount has to be sent. +2. Data - Actual FLO data that will be sent as string of 1040 characters. +3. receiverAddr - FLO address to which has to be sent. Default is specified in floGlobals.adminID. +4. PrivKey - Private key of sender to verify sender. + +#### sendTx + floBlockchainAPI.sendTx(senderAddr, receiverAddr, sendAmt, PrivKey, floData = '') +`sendTx` sends a transaction to blockchain, resolves transaction id if the transacation was succsessful. +1. senderAddr - FLO address from which the data and amount has to be sent. +2. receiverAddr - FLO address to which has to be sent. +3. sendAmt - Amount of FLO coins to be sent to receiver. +4. PrivKey - Private key of sender to verify sender. +5. floData - Actual FLO data that will be sent as string of 1040 characters. + +#### readTxs + floBlockchainAPI.readTxs(addr, from, to) +`readTxs` reads transactions of specified address between from and to. +1. addr - FLO address for which the transactions has to be read. +2. from - Reading transactions starts from 'from'. +3. to - Reading transactions ends on 'to'. + +#### readAllTxs + floBlockchainAPI.readTxs(addr) +`readAllTxs` reads all transactions of specified address(newest first). +1. addr - FLO address for which the transactions has to be read. + +#### readData + floBlockchainAPI.readData(addr, options = {}) +`readData` reads FLO data from transactions of specified address +1. addr - FLO address for which the transactions data has to be read. +2. options - Contains options for filter data from transactions. + a. limit : maximum number of filtered data (default = 1000, negative = no limit) + b. ignoreOld : ignore old transactions (default = 0) + c. sentOnly : filters only sent data + d. pattern : filters data that starts with a pattern + e. contains : filters data that contains a string + f. filter : custom filter funtion for floData (eg . filter: d => {return d[0] == '$'}) + +## Compact IndexedDB operations +`compactIDB` operations can be used to perform basic IndexedDB operations such as add, read/write, modify and remove.Contains following operations. + +#### setDefaultDB + compactIDB.setDefaultDB(dbName) +`setDefaultDB` sets the database on which further operations will be performed. +1. dbName - This is the name of default database to be used. + +#### initDB + compactIDB.initDB(dbName, objectStores = {}) +`initDB` initializes new IndexedDB. +1. dbName - Specifies database to be initialized. +2. objectStores - This is an object containing various objectStores to be initiazed when creating an IDB. + +#### openDB + compactIDB.openDB(dbName) +`openDB` returns a promise that resolves to a default database object. + +#### deleteDB + compactIDB.deleteDB(dbName) +`deleteDB` deletes the specified database. + +#### writeData + compactIDB.writeData(obsName, data) +`writeData` writes specified data into the database if data doesn't exists or replaces it when data is already present. +1. obsName - object store name in which the data is to be written. +2. data - data that has to be written in specified object store. + +#### addData + compactIDB.addData(obsName, data) +`addData` writes new data into object store. If data already exists, it will return an error. +1. obsName - Object store name in which has to be stored. +2. data - The data which has to be added to obeject store. + +#### removeData + compactDB.removeData(obsName, key) +`removeData` deletes data from specified object store using primary key. +1. obsName - Name of object store from which the data has to be removed. +2. key - Primary key of the specified object store. + +#### readData + compactDB.readData(obsName, key) +`readData` reads the data from object store associated with specified key. +1. obsName - Name of object store from which the data has to be retrieved. +2. key - 2.key - Primary key of the specified object store. + +#### readAllData + compactDB.readAllData(obsName) +`readAllData` reads all the data from specified object store using IndexedDB openCursor method. +1. obsName - Name of object store from which the data has to be retrieved. +`signData` signs the data using the private key +1. data - data to sign +2. privateKey - private key of the signer + From 10a539337388417032702584730565fdbc6eb009 Mon Sep 17 00:00:00 2001 From: sairaj mote Date: Sun, 20 Oct 2019 01:15:39 +0530 Subject: [PATCH 2/6] Update README.md --- README.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index fd7a439..17fb054 100644 --- a/README.md +++ b/README.md @@ -86,8 +86,8 @@ This template contains standard operations that can be used for the following: floBlockchainAPI.promisedAJAX(method, uri) `promisedAJAX` resolves a responce from server on success or rejects the responce on failure. 1. method - GET/POST - a. GET - Requests data from a specified resource. - b. POST - Submits data to be processed to a specified resource. + - GET - Requests data from a specified resource. + - POST - Submits data to be processed to a specified resource. 2. uri(Uniform Resource Identifier) - identifier for AJAX resource. It is used to create URL(Uniform Resource Locator) for further operations. #### getBalalnce @@ -129,12 +129,12 @@ This template contains standard operations that can be used for the following: `readData` reads FLO data from transactions of specified address 1. addr - FLO address for which the transactions data has to be read. 2. options - Contains options for filter data from transactions. - a. limit : maximum number of filtered data (default = 1000, negative = no limit) - b. ignoreOld : ignore old transactions (default = 0) - c. sentOnly : filters only sent data - d. pattern : filters data that starts with a pattern - e. contains : filters data that contains a string - f. filter : custom filter funtion for floData (eg . filter: d => {return d[0] == '$'}) + - limit : maximum number of filtered data (default = 1000, negative = no limit) + - ignoreOld : ignore old transactions (default = 0) + - sentOnly : filters only sent data + - pattern : filters data that starts with a pattern + - contains : filters data that contains a string + - filter : custom filter funtion for floData (eg . filter: d => {return d[0] == '$'}) ## Compact IndexedDB operations `compactIDB` operations can be used to perform basic IndexedDB operations such as add, read/write, modify and remove.Contains following operations. From d79d54b400b3853732cddfa2b829d47aeb578f02 Mon Sep 17 00:00:00 2001 From: sairajzero Date: Tue, 19 Nov 2019 20:09:15 +0530 Subject: [PATCH 3/6] Updating to match the backup node feature of SN --- index.html | 124 +++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 102 insertions(+), 22 deletions(-) diff --git a/index.html b/index.html index 2f93325..6b155e3 100644 --- a/index.html +++ b/index.html @@ -5218,6 +5218,50 @@ } }); }, + getPrevSupernode: function(flo_addr, n = 1, KB = this.supernodeKBucket){ + return new Promise((resolve, reject) => { + try { + let isFloIdUint8 = flo_addr instanceof Uint8Array; + if (!isFloIdUint8) + flo_addr = this.floIdToKbucketId(flo_addr); + const KA = KB.toArray(); + let pos = KB._indexOf(KB.root,flo_addr) + var prevSupernode = [] + for(var i = 1; i <= n; i++){ + if(pos - i < 0) + var prev = pos - i + KA.length + else + var prev = pos - i + prevSupernode.push(KA[prev]) + } + resolve(prevSupernode); + } catch (error) { + reject(error); + } + }); + }, + getNextSupernode: function(flo_addr, n = 1, KB = this.supernodeKBucket){ + return new Promise((resolve, reject) => { + try { + let isFloIdUint8 = flo_addr instanceof Uint8Array; + if (!isFloIdUint8) + flo_addr = this.floIdToKbucketId(flo_addr); + const KA = KB.toArray(); + let pos = KB._indexOf(KB.root,flo_addr) + var nextSupernode = [] + for(var i = 1; i <= n; i++){ + if(pos + i >= KA.length) + var next = pos + i - KA.length + else + var next = pos + i + nextSupernode.push(KA[next]) + } + resolve(nextSupernode); + } catch (error) { + reject(error); + } + }); + }, determineClosestSupernode: function (flo_addr, n = 1, KB = this.supernodeKBucket) { return new Promise((resolve, reject) => { try { @@ -5233,42 +5277,78 @@ } }, + sendDataToSN(data, snfloID){ + return new Promise((resolve, reject) => { + console.log(snfloID) + var websocket = new WebSocket("wss://" + floGlobals.supernodes[snfloID].uri + "/ws"); + websocket.onmessage = (evt => { + if(evt.data == '$+'){ + websocket.send(data); + resolve(`Data sent to supernode : ${snfloID}`); + }else if(evt.data == '$-'){ + this.kBucket.getNextSupernode(snfloID) + .then(nextnode => this.sendDataToSN(data, nextnode[0].floID)) + .catch(error => reject(error)) + }else{ + console.log(evt.data) + reject(evt.data) + } + websocket.close(); + }) + websocket.onerror = (evt) => { + this.kBucket.getNextSupernode(snfloID) + .then(nextnode => this.sendDataToSN(data, nextnode[0].floID)) + .catch(error => reject(error)) + }; + }) + }, + //Sends data to the supernode sendData: function (data, floID) { return new Promise((resolve, reject) => { this.kBucket.determineClosestSupernode(floID).then(result => { - var websocket = new WebSocket("wss://" + floGlobals.supernodes[result[0].floID].uri + "/ws"); - websocket.onopen = (evt) => { - websocket.send(data); - resolve(`Data sent to ${floID}'s supernode`); - websocket.close(); - }; - websocket.onerror = (evt) => { - reject(evt); - }; + this.sendDataToSN(data, result[0].floID) + .then(result => resolve(result)) + .catch(error => reject(error)) }).catch(error => { - reject(error); + reject(error); }); }); }, + requestDataFromSN(request, snfloID){ + return new Promise((resolve, reject) => { + var websocket = new WebSocket("wss://" + floGlobals.supernodes[snfloID].uri + "/ws"); + websocket.onmessage = (evt => { + if(evt.data == '$+'){ + websocket.send(`?${request}`); + }else if(evt.data == '$-'){ + this.kBucket.getNextSupernode(snfloID) + .then(nextnode => this.requestDataFromSN(request, nextnode[0].floID)) + .catch(error => reject(error)) + websocket.close() + }else{ + resolve(evt.data); + websocket.close(); + } + }) + websocket.onerror = (evt) => { + this.kBucket.getNextSupernode(snfloID) + .then(nextnode => this.requestDataFromSN(request, nextnode[0].floID)) + .catch(error => reject(error)) + }; + }) + }, + //Request data from supernode requestData: function (request, floID) { return new Promise((resolve, reject) => { this.kBucket.determineClosestSupernode(floID).then(result => { - var websocket = new WebSocket("wss://" + floGlobals.supernodes[result[0].floID].uri + "/ws"); - websocket.onopen = (evt) => { - websocket.send(`?${request}`); - }; - websocket.onmessage = (evt) => { - resolve(evt.data); - websocket.close(); - }; - websocket.onerror = (evt) => { - reject(evt); - }; + this.requestDataFromSN(request, result[0].floID) + .then(result => resolve(result)) + .catch(error => reject(error)) }).catch(error => { - reject(error); + reject(error); }); }); } From 289089d972836056b65b3e58eb3965f4f7c88591 Mon Sep 17 00:00:00 2001 From: sairajzero Date: Tue, 19 Nov 2019 20:11:32 +0530 Subject: [PATCH 4/6] Adding floCloudAPI floCloudAPI has methods to send application data, request application data, reset or update object data. --- index.html | 407 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 407 insertions(+) diff --git a/index.html b/index.html index 6b155e3..8fa934a 100644 --- a/index.html +++ b/index.html @@ -5914,5 +5914,412 @@ } } + + From ce28df68344c626b94b871410ab774b40d732256 Mon Sep 17 00:00:00 2001 From: sairajzero Date: Wed, 20 Nov 2019 02:07:35 +0530 Subject: [PATCH 5/6] adding automatic fetch for flosight API --- index.html | 133 ++++++++++++++++++++++++++++++----------------------- 1 file changed, 75 insertions(+), 58 deletions(-) diff --git a/index.html b/index.html index 8fa934a..7a809f9 100644 --- a/index.html +++ b/index.html @@ -10,12 +10,12 @@ const floGlobals = { //Required for all - blockchain: "FLO_TEST", + blockchain: "FLO", //Required for blockchain API operators apiURL: { - FLO: 'https://flosight.duckdns.org', - FLO_TEST: 'https://testnet-flosight.duckdns.org' + FLO: ['https://explorer.mediciland.com/', 'https://livenet.flocha.in/', 'https://flosight.duckdns.org/', 'http://livenet-explorer.floexperiments.com', 'http://ec2-13-233-133-128.ap-south-1.compute.amazonaws.com/', 'http://ec2-13-233-131-136.ap-south-1.compute.amazonaws.com/', 'http://ec2-13-233-194-1.ap-south-1.compute.amazonaws.com/'], + FLO_TEST: ['https://testnet-flosight.duckdns.org', 'https://testnet.flocha.in/'] }, adminID: "oTZw3ydCRKDhcYC5Bp6mRJMGTTVv9JHtg8", sendAmt: 0.001, @@ -4692,7 +4692,6 @@ }; - From 5ae3214a67b72e00dca58199444f893ec77f9785 Mon Sep 17 00:00:00 2001 From: Sai Raj <39055732+sairajzero@users.noreply.github.com> Date: Wed, 20 Nov 2019 18:15:34 +0530 Subject: [PATCH 6/6] Rename index.html to standard_Operations.html --- index.html => standard_Operations.html | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename index.html => standard_Operations.html (100%) diff --git a/index.html b/standard_Operations.html similarity index 100% rename from index.html rename to standard_Operations.html