Skip to content

Commit

Permalink
Merge PR #719 from 'pinheadmz/decoderesource'
Browse files Browse the repository at this point in the history
  • Loading branch information
pinheadmz committed Jul 5, 2022
2 parents 959fb8d + 8d6ddd7 commit 5a23a5b
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 0 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,13 @@
# HSD Release Notes & Changelog

## unreleased

### Node changes

- New RPC methods:
- `decoderesource` like `decodescript` accepts hex string as input and returns
JSON formatted DNS records resource.

## v4.0.0

**When upgrading to this version of hsd you must pass
Expand Down
12 changes: 12 additions & 0 deletions lib/node/rpc.js
Expand Up @@ -229,6 +229,7 @@ class RPC extends RPCBase {
this.add('createrawtransaction', this.createRawTransaction);
this.add('decoderawtransaction', this.decodeRawTransaction);
this.add('decodescript', this.decodeScript);
this.add('decoderesource', this.decodeResource);
this.add('sendrawtransaction', this.sendRawTransaction);
this.add('signrawtransaction', this.signRawTransaction);

Expand Down Expand Up @@ -1905,6 +1906,17 @@ class RPC extends RPCBase {
return json;
}

async decodeResource(args, help) {
if (help || args.length !== 1)
throw new RPCError(errs.MISC_ERROR, 'decoderesource "hex"');

const valid = new Validator(args);
const data = valid.buf(0);

const res = Resource.decode(data);
return res.toJSON();
}

async getRawTransaction(args, help) {
if (help || args.length < 1 || args.length > 2) {
throw new RPCError(errs.MISC_ERROR,
Expand Down
59 changes: 59 additions & 0 deletions test/node-rpc-test.js
Expand Up @@ -617,4 +617,63 @@ describe('RPC', function() {
assert.deepEqual(result.localservicenames, ['NETWORK', 'BLOOM']);
});
});

describe('utility', function() {
const node = new FullNode({...nodeOptions});
const nclient = new NodeClient(clientOptions);

before(async () => {
await node.open();
await nclient.open();
});

after(async () => {
await nclient.close();
await node.close();
});

it('should decode resource', async () => {
// .p resource at mainnet height 118700
const result = await nclient.execute(
'decoderesource',
[
'0002036e733101700022858d9e01c00200c625080220d96' +
'65e9952988fc27b1d4098491b37d83a3b6fb2cdf5fc9787' +
'd4dda67f1408ed001383080220ae8ea2f2800727f9ad3b6' +
'd7c802dac2a0790bdc8ea717bf5f6dc21f83fb8cc4e'
]
);

assert.deepEqual(
result,
{
records: [
{
type: 'GLUE4',
ns: 'ns1.p.',
address: '34.133.141.158'
},
{
type: 'NS',
ns: 'ns1.p.'
},
{
type: 'DS',
keyTag: 50725,
algorithm: 8,
digestType: 2,
digest: 'd9665e9952988fc27b1d4098491b37d83a3b6fb2cdf5fc9787d4dda67f1408ed'
},
{
type: 'DS',
keyTag: 4995,
algorithm: 8,
digestType: 2,
digest: 'ae8ea2f2800727f9ad3b6d7c802dac2a0790bdc8ea717bf5f6dc21f83fb8cc4e'
}
]
}
);
});
});
});

0 comments on commit 5a23a5b

Please sign in to comment.