fix: xt set_operational @ init
@@ -14,14 +14,30 @@ const keyring = createTestPairs({ type: 'sr25519' })
export default class Relayer {
static debug = createDebug('relayer')
+ circuit: ApiPromise
endpoint: string = process.env.CIRCUIT_WS_URL as string
- circuitPromise: Promise<ApiPromise> = ApiPromise.create({
+ // gateway id for given chain
+ gatewayId: Buffer = Buffer.from(process.env.GATEWAY_ID as string, 'utf8')
+
+ async init() {
+ this.circuit = await ApiPromise.create({
provider: new WsProvider(this.endpoint),
types: {
/*3*/
},
})
+ await this.circuit.tx.multiFinalityVerifierSubstrateLike
+ .setOperational(true, this.gatewayId)
+ .signAndSend(keyring.alice, result => {
+ if (result.isError) {
+ Relayer.debug(`error: ${result.status.toString()}`)
+ } else if (result.isFinalized) {
+ Relayer.debug(`gateway ${this.gatewayId.toString()} operational`)
+ }
+ })
+ }
+
async submit(
range: Header[],
justification: JustificationNotification,
@@ -29,17 +45,15 @@ export default class Relayer {
) {
Relayer.debug('submitting finality proof...')
- const circuit: ApiPromise = await this.circuitPromise
-
const anchor: Header = range[range.length - 1]
- await circuit.tx.multiFinalityVerifierSubstrateLike
+ await this.circuit.tx.multiFinalityVerifierSubstrateLike
.submitFinalityProof(anchor, justification, gatewayId)
.signAndSend(keyring.alice, result => {
if (result.isError) {
Relayer.debug(`error: ${result.status.toString()}`)
} else if (result.isInBlock) {
- Relayer.debug('in block')
+ Relayer.debug('submitted finality proof')
}
})
}
