Skip to content

Commit bccab33

Browse files
committed
PR tweaks for Tynes. Use getJSON util method, variable renaming
1 parent 5fd20d5 commit bccab33

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

lib/node/http.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -474,11 +474,13 @@ class HTTP extends Server {
474474
throw new Error('Invalid hash.');
475475

476476
const ns = await this.chain.db.getNameState(hash);
477+
const height = this.chain.tip.height;
478+
const network = this.network;
477479

478480
if (!ns)
479481
return res.json(404);
480482

481-
return res.json(200, { name: ns.name.toString('binary') });
483+
return res.json(200, ns.getJSON(height,network));
482484
});
483485

484486
this.get('/resource/name/:name', async (req, res) => {
@@ -496,7 +498,7 @@ class HTTP extends Server {
496498

497499
const resource = Resource.decode(ns.data);
498500

499-
return res.json(200, resource.toJSON());
501+
return res.json(200, resource.getJSON(name));
500502
});
501503

502504
this.get('/proof/name/:name', async (req, res) => {
@@ -506,18 +508,18 @@ class HTTP extends Server {
506508
if (!name || !rules.verifyName(name))
507509
throw new Error('Invalid name.');
508510

509-
const hash = this.chain.tip.hash;
511+
const tip = this.chain.tip.hash;
510512
const height = this.chain.tip.height;
511513
const root = this.chain.tip.treeRoot;
512-
const key = rules.hashName(name);
513-
const proof = await this.chain.db.prove(root, key);
514+
const nameHash = rules.hashName(name);
515+
const proof = await this.chain.db.prove(root, nameHash);
514516

515517
return res.json(200, {
516-
hash: hash.toString('hex'),
518+
hash: tip.toString('hex'),
517519
height: height,
518520
root: root.toString('hex'),
519521
name: name,
520-
key: key.toString('hex'),
522+
key: nameHash.toString('hex'),
521523
proof: proof.toJSON()
522524
});
523525
});

test/node-http-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ describe('Node http', function() {
169169
await wclient.execute('sendupdate', [NAME0, records]);
170170
await mineBlocks(1);
171171
const resource = await nclient.get(`/resource/name/${NAME0}`);
172-
assert.deepEqual(resource, records);
172+
assert.deepEqual(resource, { ...records, name: NAME0, version: 0 });
173173
});
174174
});
175175
});

0 commit comments

Comments
 (0)