diff --git a/package-lock.json b/package-lock.json index c397f56..a27cdf9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,7 +8,7 @@ "version": "1.16.0", "license": "MIT", "dependencies": { - "@psf/bch-js": "^4.15.7", + "@psf/bch-js": "^4.15.8", "apidoc": "^0.26.0", "axios": "^0.21.1", "bitcore-lib-cash": "^8.23.1", @@ -458,9 +458,9 @@ } }, "node_modules/@psf/bch-js": { - "version": "4.15.7", - "resolved": "https://registry.npmjs.org/@psf/bch-js/-/bch-js-4.15.7.tgz", - "integrity": "sha512-8PuPlAksbBiEG4UnLBp7uyPW+EM+qv/T9CQcEiQa66FtXndECEFLCsx0eMC+keVSzVUiwBGzGERK1JPFqd8euw==", + "version": "4.15.8", + "resolved": "https://registry.npmjs.org/@psf/bch-js/-/bch-js-4.15.8.tgz", + "integrity": "sha512-NLWuoTj6jWOYZruvOAXKtFqeNA3QvZgvHj3UI4jwjuw4VKBuv2llhTSSeLvqM+J2tuvJ2Th4w16u66b6eRUAew==", "dependencies": { "@psf/bip21": "^2.0.1", "@psf/bip32-utils": "^0.13.1", @@ -18627,9 +18627,9 @@ } }, "@psf/bch-js": { - "version": "4.15.7", - "resolved": "https://registry.npmjs.org/@psf/bch-js/-/bch-js-4.15.7.tgz", - "integrity": "sha512-8PuPlAksbBiEG4UnLBp7uyPW+EM+qv/T9CQcEiQa66FtXndECEFLCsx0eMC+keVSzVUiwBGzGERK1JPFqd8euw==", + "version": "4.15.8", + "resolved": "https://registry.npmjs.org/@psf/bch-js/-/bch-js-4.15.8.tgz", + "integrity": "sha512-NLWuoTj6jWOYZruvOAXKtFqeNA3QvZgvHj3UI4jwjuw4VKBuv2llhTSSeLvqM+J2tuvJ2Th4w16u66b6eRUAew==", "requires": { "@psf/bip21": "^2.0.1", "@psf/bip32-utils": "^0.13.1", diff --git a/package.json b/package.json index f183dda..98d5d92 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,7 @@ "node": ">=10.15.1" }, "dependencies": { - "@psf/bch-js": "^4.15.7", + "@psf/bch-js": "^4.15.8", "apidoc": "^0.26.0", "axios": "^0.21.1", "bitcore-lib-cash": "^8.23.1", diff --git a/src/middleware/route-ratelimit.js b/src/middleware/route-ratelimit.js index 06c5052..8b2310a 100644 --- a/src/middleware/route-ratelimit.js +++ b/src/middleware/route-ratelimit.js @@ -116,7 +116,7 @@ class RateLimits { // } else if (req.body && req.body.usrObj) { // Same as above, but this code path is activated from internal calls to - // bch-js, like hydrateUtxo() which passes the user object from the + // bch-js, like hydrateUtxo(), which passes the user object from the // original API call. try { @@ -153,23 +153,7 @@ class RateLimits { // Key will be the JWT ID if it exists, otherwise the IP address of the caller. let key = userId || req.ip res.locals.key = key // Feedback for tests. - - // For internal calls that make a lot of internal calls, like - // hydrateUtxoDetails(), the origin of the caller will be passed in - // via the POST body. - const keyIsLocal = - key.includes('172.17.0.1') || key.includes('127.0.0.1') - if (req.body && req.body.usrObj && keyIsLocal) { - // key = req.body.ip - console.log( - `route-ratelimit usrObj: ${JSON.stringify( - req.body.usrObj, - null, - 2 - )}` - ) - } - console.log(`key: ${key}`) + // console.log(`key: ${key}`) // const pointsToConsume = userId ? 1 : 30 decoded.resource = resource diff --git a/src/routes/v4/encryption.js b/src/routes/v4/encryption.js index cd0efe1..827e6b2 100644 --- a/src/routes/v4/encryption.js +++ b/src/routes/v4/encryption.js @@ -92,6 +92,15 @@ class Encryption { }) } + // Generate a user object that can be passed along with internal calls + // from bch-js. + const usrObj = { + ip: req._remoteAddress, + jwtToken: req.locals.jwtToken, + proLimit: req.locals.proLimit, + apiLevel: req.locals.apiLevel + } + const cashAddr = _this.bchjs.Address.toCashAddress(address) // Prevent a common user error. Ensure they are using the correct network address. @@ -110,7 +119,7 @@ class Encryption { cashAddr ) - const rawTxData = await _this.bchjs.Electrumx.transactions(cashAddr) + const rawTxData = await _this.bchjs.Electrumx.transactions(cashAddr, usrObj) // console.log(`rawTxData: ${JSON.stringify(rawTxData, null, 2)}`) // Extract just the TXIDs @@ -126,9 +135,12 @@ class Encryption { for (let i = 0; i < txids.length; i++) { const thisTx = txids[i] + // CT 2/24/21: I might want to convert this to the POST call, to take + // advantage of the usrObj. It does not get passed in a GET call. const txDetails = await _this.bchjs.RawTransactions.getRawTransaction( thisTx, - true + true, + usrObj ) // console.log(`txDetails: ${JSON.stringify(txDetails, null, 2)}`) diff --git a/src/routes/v4/slp.js b/src/routes/v4/slp.js index 5b1aa50..d6559c8 100644 --- a/src/routes/v4/slp.js +++ b/src/routes/v4/slp.js @@ -1980,9 +1980,10 @@ class Slp { const utxos = req.body.utxos // console.log('req: ', req) - console.log(`req._remoteAddress: ${req._remoteAddress}`) - // const ip = req._remoteAddress + // console.log(`req._remoteAddress: ${req._remoteAddress}`) + // Generate a user object that can be passed along with internal calls + // from bch-js. const usrObj = { ip: req._remoteAddress, jwtToken: req.locals.jwtToken,