Skip to content

Commit ad182aa

Browse files
committed
Adding funding verification limit
1 parent 4a543c3 commit ad182aa

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

build/src/gsn/index.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ function () {
114114
var _ref4 = _asyncToGenerator(
115115
/*#__PURE__*/
116116
regeneratorRuntime.mark(function _callee2(web3, _ref5) {
117-
var from, recipient, relayHub, amountInPht, curBalance;
117+
var from, recipient, relayHub, amountInPht, maxFundingValueInPht, curBalance;
118118
return regeneratorRuntime.wrap(function _callee2$(_context2) {
119119
while (1) {
120120
switch (_context2.prev = _context2.next) {
@@ -157,8 +157,18 @@ function () {
157157
throw new Error("Invalid \"amountInPht\" value ".concat(amountInPht, ". Expected a float number"));
158158

159159
case 11:
160+
maxFundingValueInPht = 100;
161+
162+
if (!(parseFloat(amountInPht) > maxFundingValueInPht)) {
163+
_context2.next = 14;
164+
break;
165+
}
166+
167+
throw new Error("GSN deposits cannot exceed ".concat(maxFundingValueInPht, "PHT"));
168+
169+
case 14:
160170
logger("Account ".concat(from, " depositing ").concat(amountInPht, " PHT in relayhub ").concat(relayHub, " to fund recipient ").concat(recipient, " "));
161-
_context2.next = 14;
171+
_context2.next = 17;
162172
return fRecipient(web3, {
163173
from: from,
164174
recipient: recipient,
@@ -167,11 +177,11 @@ function () {
167177
amount: web3Utils.toWei(amountInPht, "ether")
168178
});
169179

170-
case 14:
180+
case 17:
171181
curBalance = _context2.sent;
172182
return _context2.abrupt("return", curBalance);
173183

174-
case 16:
184+
case 19:
175185
case "end":
176186
return _context2.stop();
177187
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "lightstreams-js-sdk",
3-
"version": "0.19.4",
3+
"version": "0.19.5",
44
"description": "Lightstreams JS SDK for building mainstream DApps with support for Programmable Decentralized Private Storage.",
55
"author": "Gabriel Garrido",
66
"contributors": [

src/gsn/index.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,18 @@ module.exports.fundRecipient = async (web3, { from, recipient, relayHub, amountI
7373
throw new Error(`Invalid "amountInPht" value ${amountInPht}. Expected a float number`);
7474
}
7575

76+
// IMPORTANT: Amount cannot be higher than 10% relay server address balance
77+
// @TODO: Verify assumption and implement validation
78+
const maxFundingValueInPht = 100;
79+
if(parseFloat(amountInPht) > maxFundingValueInPht) {
80+
throw new Error(`GSN deposits cannot exceed ${maxFundingValueInPht}PHT`);
81+
}
82+
7683
logger(`Account ${from} depositing ${amountInPht} PHT in relayhub ${relayHub} to fund recipient ${recipient} `);
7784
const curBalance = await fRecipient(web3, {
7885
from,
7986
recipient,
8087
relayHubAddress: relayHub,
81-
// IMPORTANT: Amount cannot be higher than relay server address balance (@TODO: Implement validation)
8288
amount: web3Utils.toWei(amountInPht, "ether")
8389
});
8490

0 commit comments

Comments
 (0)