Skip to content

Commit

Permalink
chore(btc): btc processBlock (#984)
Browse files Browse the repository at this point in the history
  • Loading branch information
spacedragon authored Sep 26, 2024
1 parent 0d7374a commit 541d51e
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions packages/sdk/src/btc/btc-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ export class BTCPlugin extends Plugin {
switch (request.handlerType) {
case HandlerType.BTC_TRANSACTION:
return this.processTransaction(request)
case HandlerType.BTC_BLOCK:
return this.processBlock(request)
default:
throw new ServerError(Status.INVALID_ARGUMENT, 'No handle type registered ' + request.handlerType)
}
Expand Down Expand Up @@ -130,6 +132,29 @@ export class BTCPlugin extends Plugin {
}
return mergeProcessResults(await Promise.all(promises))
}

private async processBlock(request: DataBinding) {
if (!request.data?.btcBlock) {
throw new ServerError(Status.INVALID_ARGUMENT, "Block can't be empty")
}

const block = request.data.btcBlock

const promises: Promise<ProcessResult>[] = []
for (const handlerId of request.handlerIds) {
const promise = this.handlers.blockHandlers[handlerId](block).catch((e) => {
throw new ServerError(
Status.INTERNAL,
'error processing block: ' + JSON.stringify(block) + '\n' + errorString(e)
)
})
if (GLOBAL_CONFIG.execution.sequential) {
await promise
}
promises.push(promise)
}
return mergeProcessResults(await Promise.all(promises))
}
}

PluginManager.INSTANCE.register(new BTCPlugin())

0 comments on commit 541d51e

Please sign in to comment.