Standard operations required for FLO Crypto, Blockchain API, Supernode WS, IndexedDB
This template contains standard operations that can be used for the following:
- FLO Globals
- FLO Crypto Operations
- FLO Blockchain API Operations
- FLO SuperNode Websocket Operations
- compact IndexedDB Operations
floGlobals
object contains the global variables and constants required for the operations. Make sure to add this object before any other scripts.
floGlobals
contains the following properties :
-
blockchain
: Indicates the blockchain ("FLO"
or"FLO_TEST"
). -
apiURL
: Indicates the URL for blockchain API calls. -
adminID
: Indicates the master admin FLO ID for the project. -
sendAmt
: Indicates the default flo amount to be sent while sending transactions into the blockchain -
fee
: Indicates the default fee amount to be deduced while sending transactions into the blockchain -
supernodes
: Holder for the supernode list. Can be updated in runtime while retriving data from blockchain using API. Stored in the Object format,{ <supernodeFLOID> : { uri : <supernodeURI> ...(otherProperties) } ...(Other Supernodes) }
floCrypto
operations can be used to perform blockchain-cryptography methods. floCrypto
operations are synchronized and return a value. Contains the following Operations.
floCrypto.generateNewID()
generateNewID
generates a new flo ID and returns private-key, public-key and floID
getPubKeyHex
returns public-key from given private-key
floCrypto.getPubKeyHex(privateKey)
- privateKey - private key in WIF format (Hex)
floCrypto.getFloIDfromPubkeyHex(publicKey)
getFloIDfromPubkeyHex
returns flo-ID from public-key
- publicKey - public key hex value
floCrypto.verifyPrivKey(privateKey, pubKey_floID, *isfloID)
verifyPrivKey
verify the private-key for the given public-key or flo-ID
- privateKey - private key in WIF format (Hex)
- pubKey_floID - public Key or flo ID
- isfloID - boolean value (true - compare as flo ID, false - compare as public key) (optional, default is true)
floCrypto.validateAddr(floID)
validateAddr
check if the given Address is valid or not
- floID - flo ID to validate
floCrypto.encryptData(data, publicKey)
encryptData
encrypts the given data using public-key
- data - data to encrypt
- publicKey - public key of the recipient
floCrypto.decryptData(data, privateKey)
decryptData
decrypts the given data using private-key
- data - encrypted data to decrypt (Object that was returned from encryptData)
- privateKey - private key of the recipient
floCrypto.signData(data, privateKey)
signData
signs the data using the private key
- data - data to sign
- privateKey - private key of the signer
floCrypto.verifySign(data, signature, publicKey)
verifySign
verifies signatue of the data using public-key
- data - data of the given signature
- signature - signature of the data
- publicKey - public key of the signer
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.
floBlockchainAPI.promisedAJAX(method, uri)
promisedAJAX
resolves a responce from server on success or rejects the responce on failure.
- method - GET/POST
- GET - Requests data from a specified resource.
- POST - Submits data to be processed to a specified resource.
- uri(Uniform Resource Identifier) - identifier for AJAX resource. It is used to create URL(Uniform Resource Locator) for further operations.
floBlockchainAPI.getBalance(addr)
getBalance
resolves balance for specified FLO address.
- addr - FLO address for which balance has to be retrieved.
floBlockchainAPI.writeData(senderAddr, Data, PrivKey, receiverAddr = floGlobals.adminID)
writeData
writes data into blockchain.
- senderAddr - FLO address from which the data and amount has to be sent.
- Data - Actual FLO data that will be sent as string of 1040 characters.
- receiverAddr - FLO address to which has to be sent. Default is specified in floGlobals.adminID.
- PrivKey - Private key of sender to verify sender.
floBlockchainAPI.sendTx(senderAddr, receiverAddr, sendAmt, PrivKey, floData = '')
sendTx
sends a transaction to blockchain, resolves transaction id if the transacation was succsessful.
- senderAddr - FLO address from which the data and amount has to be sent.
- receiverAddr - FLO address to which has to be sent.
- sendAmt - Amount of FLO coins to be sent to receiver.
- PrivKey - Private key of sender to verify sender.
- floData - Actual FLO data that will be sent as string of 1040 characters.
floBlockchainAPI.readTxs(addr, from, to)
readTxs
reads transactions of specified address between from and to.
- addr - FLO address for which the transactions has to be read.
- from - Reading transactions starts from 'from'.
- to - Reading transactions ends on 'to'.
floBlockchainAPI.readTxs(addr)
readAllTxs
reads all transactions of specified address(newest first).
- addr - FLO address for which the transactions has to be read.
floBlockchainAPI.readData(addr, options = {})
readData
reads FLO data from transactions of specified address
- addr - FLO address for which the transactions data has to be read.
- options - Contains options for filter data from transactions.
- 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] == '$'})
compactIDB
operations can be used to perform basic IndexedDB operations such as add, read/write, modify and remove.Contains following operations.
compactIDB.setDefaultDB(dbName)
setDefaultDB
sets the database on which further operations will be performed.
- dbName - This is the name of default database to be used.
compactIDB.initDB(dbName, objectStores = {})
initDB
initializes new IndexedDB.
- dbName - Specifies database to be initialized.
- objectStores - This is an object containing various objectStores to be initiazed when creating an IDB.
compactIDB.openDB(dbName)
openDB
returns a promise that resolves to a default database object.
compactIDB.deleteDB(dbName)
deleteDB
deletes the specified database.
compactIDB.writeData(obsName, data)
writeData
writes specified data into the database if data doesn't exists or replaces it when data is already present.
- obsName - object store name in which the data is to be written.
- data - data that has to be written in specified object store.
compactIDB.addData(obsName, data)
addData
writes new data into object store. If data already exists, it will return an error.
- obsName - Object store name in which has to be stored.
- data - The data which has to be added to obeject store.
compactDB.removeData(obsName, key)
removeData
deletes data from specified object store using primary key.
- obsName - Name of object store from which the data has to be removed.
- key - Primary key of the specified object store.
compactDB.readData(obsName, key)
readData
reads the data from object store associated with specified key.
- obsName - Name of object store from which the data has to be retrieved.
- key - 2.key - Primary key of the specified object store.
compactDB.readAllData(obsName)
readAllData
reads all the data from specified object store using IndexedDB openCursor method.
- obsName - Name of object store from which the data has to be retrieved.
signData
signs the data using the private key - data - data to sign
- privateKey - private key of the signer