diff --git a/CHANGELOG.md b/CHANGELOG.md index 673027221..abb255613 100644 --- a/CHANGELOG.md +++ b/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 diff --git a/lib/node/rpc.js b/lib/node/rpc.js index b8ee8309a..a0a1e41ea 100644 --- a/lib/node/rpc.js +++ b/lib/node/rpc.js @@ -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); @@ -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, diff --git a/test/node-rpc-test.js b/test/node-rpc-test.js index 9f6fbd69f..1bc8c7937 100644 --- a/test/node-rpc-test.js +++ b/test/node-rpc-test.js @@ -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' + } + ] + } + ); + }); + }); });