From cf4cff9f2a4445db8570d1a39dc2cc63bef0b7b0 Mon Sep 17 00:00:00 2001 From: Amir Date: Thu, 5 Dec 2024 11:29:24 -0700 Subject: [PATCH] Implement debug_setHead --- packages/client/src/rpc/modules/debug.ts | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/packages/client/src/rpc/modules/debug.ts b/packages/client/src/rpc/modules/debug.ts index c99331957c..48e4d0aa4c 100644 --- a/packages/client/src/rpc/modules/debug.ts +++ b/packages/client/src/rpc/modules/debug.ts @@ -148,6 +148,9 @@ export class Debug { 1, [[validators.hex]], ) + this.setHead = middleware(callWithStackTrace(this.setHead.bind(this), this._rpcDebug), 1, [ + [validators.blockOption], + ]) this.verbosity = middleware(callWithStackTrace(this.verbosity.bind(this), this._rpcDebug), 1, [ [validators.unsignedInteger], ]) @@ -457,4 +460,25 @@ export class Debug { this.client.config.logger.configure({ level: logLevels[level] }) return `level: ${this.client.config.logger.level}` } + + /** + * Returns an RLP-encoded block + * @param blockOpt Block number or tag + */ + async setHead(params: [string]) { + const [blockOpt] = params + if (blockOpt === 'pending') { + throw { + code: INVALID_PARAMS, + message: `"pending" is not yet supported`, + } + } + const block = await getBlockByOption(blockOpt, this.chain) + let res + try { + res = await this.service.skeleton?.setHead(block) + } catch (e) { + console.log(e) + } + } }