Skip to content

Commit bdf186f

Browse files
committed
Adds new gateway' status fn retrieving a PeerId from HTTP /node/status API.
Updates to version 0.22.0
1 parent b7395d5 commit bdf186f

File tree

9 files changed

+111
-7
lines changed

9 files changed

+111
-7
lines changed

build/src/gateway/storage.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ var ADD_RAW_WITH_ACL_PATH = "/storage/add-raw-with-acl";
2020
var FETCH_FILE_PATH = "/storage/fetch";
2121
var STREAM_FILE_PATH = "/storage/stream";
2222
var META_PATH = "/storage/meta";
23+
var STATUS_PATH = "/storage/status";
2324

2425
var request = require('../http/request');
2526

@@ -251,6 +252,19 @@ module.exports = function (gwDomain) {
251252
'Content-Type': 'application/json'
252253
}
253254
});
255+
},
256+
257+
/**
258+
* Fetch information about the Smart Vault node.
259+
*
260+
* @returns {Promise<{ peer_id: <string>, }>}
261+
*/
262+
status: function status() {
263+
return request.get("".concat(gwDomain).concat(STATUS_PATH), {}, {
264+
headers: {
265+
'Content-Type': 'application/json'
266+
}
267+
});
254268
}
255269
};
256270
};

build/src/gsn/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@ function () {
157157
throw new Error("Invalid \"amountInPht\" value ".concat(amountInPht, ". Expected a float number"));
158158

159159
case 11:
160+
// IMPORTANT: Amount cannot be higher than 10% relay server address balance
161+
// @TODO: Verify assumption and implement validation
160162
maxFundingValueInPht = 100;
161163

162164
if (!(parseFloat(amountInPht) > maxFundingValueInPht)) {
@@ -173,7 +175,6 @@ function () {
173175
from: from,
174176
recipient: recipient,
175177
relayHubAddress: relayHub,
176-
// IMPORTANT: Amount cannot be higher than relay server address balance (@TODO: Implement validation)
177178
amount: web3Utils.toWei(amountInPht, "ether")
178179
});
179180

build/src/leth/storage.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"use strict";
22

3+
function _objectDestructuringEmpty(obj) { if (obj == null) throw new TypeError("Cannot destructure undefined"); }
4+
35
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
46

57
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
@@ -67,4 +69,41 @@ function () {
6769
return function (_x, _x2, _x3) {
6870
return _ref.apply(this, arguments);
6971
};
72+
}();
73+
/**
74+
* Fetch information about the Smart Vault node.
75+
*
76+
* @returns {Promise<{ peer_id: <string>, }>}
77+
*/
78+
79+
80+
module.exports.status =
81+
/*#__PURE__*/
82+
function () {
83+
var _ref3 = _asyncToGenerator(
84+
/*#__PURE__*/
85+
regeneratorRuntime.mark(function _callee2(web3, gatewayStorage, _ref4) {
86+
return regeneratorRuntime.wrap(function _callee2$(_context2) {
87+
while (1) {
88+
switch (_context2.prev = _context2.next) {
89+
case 0:
90+
_objectDestructuringEmpty(_ref4);
91+
92+
_context2.next = 3;
93+
return gatewayStorage.status();
94+
95+
case 3:
96+
return _context2.abrupt("return", _context2.sent);
97+
98+
case 4:
99+
case "end":
100+
return _context2.stop();
101+
}
102+
}
103+
}, _callee2);
104+
}));
105+
106+
return function (_x4, _x5, _x6) {
107+
return _ref3.apply(this, arguments);
108+
};
70109
}();

build/src/leth/token.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ function () {
1717
var _ref = _asyncToGenerator(
1818
/*#__PURE__*/
1919
regeneratorRuntime.mark(function _callee2(web3, _ref2) {
20-
var address, tokenBlocksLifespan;
20+
var address, tokenBlocksLifespan, peerId;
2121
return regeneratorRuntime.wrap(function _callee2$(_context2) {
2222
while (1) {
2323
switch (_context2.prev = _context2.next) {
2424
case 0:
25-
address = _ref2.address, tokenBlocksLifespan = _ref2.tokenBlocksLifespan;
25+
address = _ref2.address, tokenBlocksLifespan = _ref2.tokenBlocksLifespan, peerId = _ref2.peerId;
2626
return _context2.abrupt("return", new Promise(
2727
/*#__PURE__*/
2828
function () {
@@ -42,7 +42,8 @@ function () {
4242
currentBlock = _context.sent;
4343
expirationBlock = currentBlock + tokenBlocksLifespan;
4444
claims = {
45-
blockchain: "ETH",
45+
blockchain: "PHT",
46+
peer_id: peerId,
4647
eth_address: address,
4748
iat: currentBlock,
4849
eat: expirationBlock

example/gateway-browser/src/index.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const root = document.getElementById('root');
2020
// AWFUL HACK caused of a unknown issue with Webpack-dotenv
2121
window.process = {
2222
'env': {
23-
WEB3_PROVIDER: 'http://localhost:8545'
23+
WEB3_PROVIDER: 'http://localhost:8645'
2424
// WEB3_PROVIDER: 'ws://localhost:8546'
2525
}
2626
};

example/gateway-browser/src/pages/Storage.jsx

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class SimpleReactFileUpload extends Component {
2121
this.onStorageFormFileChange = this.onStorageFormFileChange.bind(this);
2222

2323
this.onACLFormSubmit = this.onACLFormSubmit.bind(this);
24+
this.onStatusFormSubmit = this.onStatusFormSubmit.bind(this);
2425

2526
this.onACLGrantRead = this.onACLGrantRead.bind(this);
2627
this.onACLGrantWrite = this.onACLGrantWrite.bind(this);
@@ -32,6 +33,7 @@ class SimpleReactFileUpload extends Component {
3233
this.onHasRead = this.onHasRead.bind(this);
3334
this.onHasAdmin = this.onHasAdmin.bind(this);
3435
this.onGetOwner = this.onGetOwner.bind(this);
36+
this.onGetStatus = this.onGetStatus.bind(this);
3537
}
3638

3739
componentDidMount() {
@@ -74,6 +76,10 @@ class SimpleReactFileUpload extends Component {
7476
e.preventDefault();
7577
}
7678

79+
onStatusFormSubmit(e) {
80+
e.preventDefault();
81+
}
82+
7783
onACLGrantRead() {
7884
const { web3, owner, account, acl } = this.state;
7985

@@ -164,12 +170,24 @@ class SimpleReactFileUpload extends Component {
164170
.catch(console.log)
165171
}
166172

173+
onGetStatus() {
174+
const { peerId } = this.state;
175+
176+
Leth.Storage.status(web3, this.gateway.storage)
177+
.then((res) => {
178+
console.log(res);
179+
180+
this.setState({ peerId: res.peer_id });
181+
})
182+
.catch(console.log)
183+
}
184+
167185
onStorageFormFileChange(e) {
168186
this.setState({ file: e.target.files[0] })
169187
}
170188

171189
render() {
172-
const {owner, account, gatewayUrl, meta, acl, grantReadMsg } = this.state;
190+
const {owner, account, gatewayUrl, meta, peerId, acl, grantReadMsg } = this.state;
173191

174192
return (
175193
<div>
@@ -207,6 +225,14 @@ class SimpleReactFileUpload extends Component {
207225
<p>
208226
<strong>{grantReadMsg}</strong>
209227
</p>
228+
229+
<h3>Status:</h3>
230+
<p>PeerId: {peerId}</p>
231+
<p>
232+
<form onSubmit={this.onStatusFormSubmit}>
233+
<button type="submit" onClick={this.onGetStatus}>What's the node's status?</button>
234+
</form>
235+
</p>
210236
</p>
211237
</div>
212238
)

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.20.0",
3+
"version": "0.22.0",
44
"description": "Lightstreams JS SDK for building mainstream DApps with support for Programmable Decentralized Private Storage.",
55
"author": "Gabriel Garrido",
66
"contributors": [

src/gateway/storage.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const ADD_RAW_WITH_ACL_PATH = `/storage/add-raw-with-acl`;
1212
const FETCH_FILE_PATH = `/storage/fetch`;
1313
const STREAM_FILE_PATH = `/storage/stream`;
1414
const META_PATH = `/storage/meta`;
15+
const STATUS_PATH = `/storage/status`;
1516

1617
const request = require('../http/request');
1718
const {validateCid} = require('../leth/cid');
@@ -230,5 +231,18 @@ module.exports = (gwDomain) => ({
230231
},
231232
});
232233
},
234+
235+
/**
236+
* Fetch information about the Smart Vault node.
237+
*
238+
* @returns {Promise<{ peer_id: <string>, }>}
239+
*/
240+
status: () => {
241+
return request.get(`${gwDomain}${STATUS_PATH}`, {
242+
headers: {
243+
'Content-Type': 'application/json',
244+
},
245+
});
246+
},
233247
});
234248

src/leth/storage.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,12 @@ module.exports.add = async (web3, gatewayStorage, { from, owner, file, isPublic
2727

2828
return await gatewayStorage.addWithAcl(owner, receipt.contractAddress, file);
2929
};
30+
31+
/**
32+
* Fetch information about the Smart Vault node.
33+
*
34+
* @returns {Promise<{ peer_id: <string>, }>}
35+
*/
36+
module.exports.status = async (web3, gatewayStorage) => {
37+
return await gatewayStorage.status();
38+
};

0 commit comments

Comments
 (0)