From 2285ab4577567a4e4f797cf501fb2ae159746eff Mon Sep 17 00:00:00 2001 From: sairajzero Date: Sun, 18 Apr 2021 02:10:55 +0530 Subject: [PATCH 1/7] update stdop --- floBank.html | 2694 ++++++++++++++++++++++++++------------------------ 1 file changed, 1391 insertions(+), 1303 deletions(-) diff --git a/floBank.html b/floBank.html index ff8afbf..7b41db6 100644 --- a/floBank.html +++ b/floBank.html @@ -5,36 +5,36 @@ FLO Standard Operators @@ -43,7 +43,7 @@ TEST_MODE (use console) - - - - - - - + - - + From cfcc92f9bd28eef621bf3e5bf4a2f1c8d46a39d0 Mon Sep 17 00:00:00 2001 From: sairajzero Date: Sun, 18 Apr 2021 02:12:52 +0530 Subject: [PATCH 3/7] updating bank module --- floBank.html | 790 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 790 insertions(+) diff --git a/floBank.html b/floBank.html index e79f869..16aae75 100644 --- a/floBank.html +++ b/floBank.html @@ -9318,6 +9318,796 @@ Bitcoin.Util = { + From be8329e8768b4e362397757966335d73776a014b Mon Sep 17 00:00:00 2001 From: sairajzero Date: Sun, 18 Apr 2021 02:15:15 +0530 Subject: [PATCH 4/7] updating startup fn --- floBank.html | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/floBank.html b/floBank.html index 16aae75..9d88c5f 100644 --- a/floBank.html +++ b/floBank.html @@ -36,7 +36,23 @@ lastVC: {} } + @@ -9298,23 +9314,6 @@ Bitcoin.Util = { } - From ef327a322268fb7481498ed53807b7927eda0e2e Mon Sep 17 00:00:00 2001 From: sairajzero Date: Tue, 20 Apr 2021 03:40:51 +0530 Subject: [PATCH 5/7] updates and bug fixes --- floBank.html | 381 ++++++++++++++++++++++++++++++++++----------------- 1 file changed, 257 insertions(+), 124 deletions(-) diff --git a/floBank.html b/floBank.html index 9d88c5f..d1bd4a8 100644 --- a/floBank.html +++ b/floBank.html @@ -2,7 +2,7 @@ - FLO Standard Operators + FLO Bank - - From 08268d97c796565956e5c6b1fa3a4655f2f5426c Mon Sep 17 00:00:00 2001 From: sairajzero Date: Tue, 20 Apr 2021 04:26:22 +0530 Subject: [PATCH 6/7] bug fixes --- floBank.html | 39 +++++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/floBank.html b/floBank.html index d1bd4a8..887231c 100644 --- a/floBank.html +++ b/floBank.html @@ -9413,7 +9413,6 @@ Bitcoin.Util = { this.readDataFromBlockchain().then(result => { if (reset) { compactIDB.readAllData('accounts').then(accounts => { - console.info(this) this.util.lastUpdate = null; this.accMap = {}; this.accounts = []; @@ -9528,14 +9527,13 @@ Bitcoin.Util = { floID: data[2], type: "deposit", amount: data[4], - txid: data[7], pubKey: data[5], sign: data[6], - }, data[1]); + }, data[1], data[7]); break; case "close-deposit": if (floCrypto.verifySign(this.istr + `close-deposit#${data[3]}`, data[5], data[4])) - this.closeAccount(data[2], data[3], data[1]); + this.closeAccount(data[2], data[3], data[1], data[6]); break; case "open-loan": if (floCrypto.verifySign(this.istr + `open#${data[3]}:loan${data[4]}`, data[6], data[5])) @@ -9543,14 +9541,13 @@ Bitcoin.Util = { floID: data[2], type: "loan", amount: data[4], - txid: data[7], pubKey: data[5], sign: data[6], - }, data[1]); + }, data[1], data[7]); break; case "close-loan": if (floCrypto.verifySign(this.istr + `close-loan#${data[3]}:${data[6]}`, data[5], data[4])) - this.closeAccount(data[2], data[3], data[1]); + this.closeAccount(data[2], data[3], data[1], data[6]); break; } }, @@ -9621,11 +9618,24 @@ Bitcoin.Util = { }, - addAccount: function(floID, account, time) { + checkTxDuplicate: function(txid, floID = null) { + let accounts = []; + if (!floID) + accounts = this.accounts; + else + this.accMap[floID].forEach(i => accounts.push(this.accounts[i])); + for (let acc of accounts) + if (acc.openTx === txid || acc.closeTx === txid) + return true; + return false; + }, + + addAccount: function(floID, account, time, txid) { this.updateAccountNetValues(time); account.netAmt = account.amount; account.status = "active"; account.openTime = time; + account.openTx = txid; let index = this.accounts.push(account); index -= 1; if (!this.accMap[floID]) @@ -9634,7 +9644,7 @@ Bitcoin.Util = { this.updateRates(); }, - closeAccount: function(floID, index, time) { + closeAccount: function(floID, index, time, txid) { accIndex = this.accMap[floID][index]; if (!accIndex) throw Error("Invalid Account index"); @@ -9646,13 +9656,14 @@ Bitcoin.Util = { this.updateAccountNetValues(time); account.status = "closed"; account.closeTime = time; + account.closeTx = txid; this.updateRates(); }, updateAccountNetValues: function(time = Date.now()) { if (this.util.lastUpdate > time) throw Error("update time is already passed"); - let t, rates; + let t, rates = {}; rates["loan"] = this.rates["I_b"]; rates["deposit"] = this.rates["I_s"]; t = Decimal.sub(time, this.util.lastUpdate || time); //if lastUpdate is null, t becomes 0 ie, no update to values @@ -9907,6 +9918,8 @@ Bitcoin.Util = { throw Error('Invalid request: Request-type is not openDeposit') if (req.status !== "pending") throw Error("Request already processed"); + if (this.checkTxDuplicate(req.txid, req.floID)) + throw Error("R>Invalid deposit: Token transaction already used") let tx = await this.tokenAPI.getTx(req.txid); if (!this.tokenAPI.validateToken(tx, req.floID, floGlobals.adminID, req.amount)) throw Error("R>Invalid deposit: Invalid token transaction"); @@ -10052,7 +10065,7 @@ Bitcoin.Util = { }, requestLoan: function(amount) { - return new Promise((resolve, reject) => { + return new Promise(async (resolve, reject) => { await this.refreshData() let index = this.util.myIndex + 1; //check for validity of loan (ie, check if enough deposit is present) @@ -10177,6 +10190,8 @@ Bitcoin.Util = { if (!floCrypto.verifySign(this.istr + `close-loan#${req.index}:${req.txid}`, req.sign, req.pubKey)) throw Error("R>Invalid signature: Re-signing required"); //verify token tx + if (this.checkTxDuplicate(req.txid, req.floID)) + throw Error("R>Invalid deposit: Token transaction already used") let tx = await this.tokenAPI.getTx(req.txid); await this.refreshData() let acc = this.getAccount(req.floID, req.index); @@ -10188,7 +10203,7 @@ Bitcoin.Util = { throw Error("R>Invalid request: Invalid token transaction") let timestamp = this.util.lastUpdate; //close loan via blockchain - let data = ["close-loan", timestamp, req.floID, req.index, req.pubKey, req, sign, req.txid].join('|') + let data = ["close-loan", timestamp, req.floID, req.index, req.pubKey, req.sign, req.txid].join('|') txid = await floBlockchainAPI.writeData(myFloID, this.util.istr + data, myPrivKey, floGlobals.adminID) let response = { requestID: reqID, From b907d0e3bb8dace2193d804342626f51938ed174 Mon Sep 17 00:00:00 2001 From: sairajzero Date: Tue, 10 Aug 2021 02:23:11 +0530 Subject: [PATCH 7/7] Bug fixes - Updated floBlockchainAPI - Fixed various bugs - Added some improvements in handling the requests from user --- floBank.html | 714 ++++++++++++++++++++++++++++++++------------------- 1 file changed, 451 insertions(+), 263 deletions(-) diff --git a/floBank.html b/floBank.html index 887231c..a76cba5 100644 --- a/floBank.html +++ b/floBank.html @@ -27,11 +27,7 @@ supernodes: {}, //each supnernode must be stored as floID : {uri:,pubKey:} //for cloud apps - subAdmins: [], - application: "bank", - appObjects: {}, - generalData: {}, - lastVC: {} + application: "test_bank", } @@ -7302,17 +7306,18 @@ Bitcoin.Util = { } } - - -