Skip to content

Commit

Permalink
node-rpc: add compacttree
Browse files Browse the repository at this point in the history
  • Loading branch information
pinheadmz committed Dec 8, 2021
1 parent 28e9806 commit 72adee4
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions lib/node/rpc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 72adee4

Please sign in to comment.