diff --git a/lib/node/rpc.js b/lib/node/rpc.js index 72b3c78daa..e2d3ca9d4f 100644 --- a/lib/node/rpc.js +++ b/lib/node/rpc.js @@ -177,6 +177,7 @@ class RPC extends RPCBase { this.add('gettxout', this.getTXOut); this.add('gettxoutsetinfo', this.getTXOutSetInfo); this.add('pruneblockchain', this.pruneBlockchain); + this.add('compacttree', this.compactTree); this.add('verifychain', this.verifyChain); this.add('invalidateblock', this.invalidateBlock); @@ -1104,6 +1105,23 @@ class RPC extends RPCBase { } } + async compactTree(args, help) { + if (help || args.length !== 0) + throw new RPCError(errs.MISC_ERROR, 'compacttree'); + + if (this.chain.options.spv) + throw new RPCError(errs.MISC_ERROR, 'Cannot compact tree in SPV mode.'); + + if (this.chain.height < this.network.block.pruneAfterHeight) + throw new RPCError(errs.MISC_ERROR, 'Chain is too short for compacting.'); + + try { + await this.chain.compactTree(); + } catch (e) { + throw new RPCError(errs.DATABASE_ERROR, e.message); + } + } + async verifyChain(args, help) { if (help || args.length > 2) { throw new RPCError(errs.MISC_ERROR,