Skip to content

Commit

Permalink
node-rpc: spv can use urkel for namebyhash and verifywithname
Browse files Browse the repository at this point in the history
  • Loading branch information
pinheadmz committed Oct 18, 2021
1 parent 9a2081d commit 162dda0
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions lib/node/rpc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2212,7 +2212,21 @@ class RPC extends RPCBase {
throw new RPCError(errs.TYPE_ERROR, 'Invalid name.');

const nameHash = rules.hashName(name);
const ns = await this.chain.db.getNameState(nameHash);

let ns;
if (this.chain.options.spv) {
// This root is "unsafe" (might have less than 12 confirmations).
const root = this.chain.tip.treeRoot;
// This data may be outdated, if a namestate has been updated
// since the last tree interval.
const data = await this.pool.resolveAtRoot(nameHash, root);
if (data) {
ns = NameState.decode(data);
ns.nameHash = nameHash;
}
} else {
ns = await this.chain.db.getNameState(nameHash);
}

if (!ns || !ns.owner)
throw new RPCError(errs.MISC_ERROR, 'Cannot find the name owner.');
Expand Down Expand Up @@ -2552,7 +2566,20 @@ class RPC extends RPCBase {
if (!hash)
throw new RPCError(errs.TYPE_ERROR, 'Invalid name hash.');

const ns = await this.chain.db.getNameState(hash);
let ns;
if (this.chain.options.spv) {
// This root is "unsafe" (might have less than 12 confirmations).
const root = this.chain.tip.treeRoot;
// This data may be outdated, if a namestate has been updated
// since the last tree interval.
const data = await this.pool.resolveAtRoot(hash, root);
if (data) {
ns = NameState.decode(data);
ns.nameHash = hash;
}
} else {
ns = await this.chain.db.getNameState(hash);
}

if (!ns)
return null;
Expand Down

0 comments on commit 162dda0

Please sign in to comment.