I'm trying to make my very first indexer. I want to pull the caller
(initiator's address) of a runtime system.remark, as well as the block number
.
What is the best way to do this via hooking into the runtime modules.
Substrate and Polkadot Stack Exchange is a question and answer site for developers building blockchains with the Substrate SDK. It only takes a minute to sign up.
Sign up to join this communityI'm trying to make my very first indexer. I want to pull the caller
(initiator's address) of a runtime system.remark, as well as the block number
.
What is the best way to do this via hooking into the runtime modules.
the ID of the account that triggered the extrinsic is present in the
ExtrinsicHandlerContext
, under extrinsic.signer
. You can simply do this to obtain it:
ctx.extrinsic.signer
the block number is available in the block
field of the ExtrinsicHandlerContext
as height
:
ctx.block.height
You could also hook to the system.Remarked
event, instead of the system.remark
call.
https://polkadot.subscan.io/event?module=System&event=Remarked
The Event should follow the call, if I am not mistaken, and, as a bonus, it reports the sender
field as one of the Event's arguments. Subsquid's typegen generates this wrapper for it:
export class SystemRemarkedEvent {
constructor(private ctx: EventContext) {
assert(this.ctx.event.name === 'system.Remarked')
}
/**
* On on-chain remark happened. \[origin, remark_hash\]
*/
get isV2030(): boolean {
return this.ctx._chain.getEventHash('system.Remarked') === 'e54ae910805a8a9413af1a7f5885a5d0ba5f4e105175cd6b0ce2a8702ddf1861'
}
/**
* On on-chain remark happened. \[origin, remark_hash\]
*/
get asV2030(): [Uint8Array, Uint8Array] {
assert(this.isV2030)
return this.ctx._chain.decodeEvent(this.ctx.event)
}
/**
* On on-chain remark happened.
*/
get isV9160(): boolean {
return this.ctx._chain.getEventHash('system.Remarked') === 'c58b73482fe762a6dcca2f35266f0d1739333312cf7a50eea55c666d0cda6101'
}
/**
* On on-chain remark happened.
*/
get asV9160(): {sender: v9160.AccountId32, hash: v9160.H256} {
assert(this.isV9160)
return this.ctx._chain.decodeEvent(this.ctx.event)
}
get isLatest(): boolean {
deprecateLatest()
return this.isV9160
}
get asLatest(): {sender: v9160.AccountId32, hash: v9160.H256} {
deprecateLatest()
return this.asV9160
}
}
As for the block number, it's even easier, you can get it like this:
ctx.event.blockNumber