Skip to content

Commit

Permalink
add option to define signed extensions and pass registry to future bl…
Browse files Browse the repository at this point in the history
…ock (#49)
  • Loading branch information
ermalkaleci authored Nov 14, 2022
1 parent cc0d42f commit c5c0694
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
12 changes: 10 additions & 2 deletions e2e/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const env = {

const setupAll = async ({ endpoint, blockHash, mockSignatureHost }: SetupOption) => {
const wsProvider = new WsProvider(endpoint)
const api = new Api(wsProvider)
const api = new Api(wsProvider, { SetEvmOrigin: { payload: {}, extrinsic: {} } })

await api.isReady

Expand Down Expand Up @@ -67,7 +67,15 @@ const setupAll = async ({ endpoint, blockHash, mockSignatureHost }: SetupOption)
tasks.updateListeningPort(listeningPort)

const wsProvider2 = new WsProvider(`ws://localhost:${listeningPort}`)
const api2 = await ApiPromise.create({ provider: wsProvider2 })
const api2 = await ApiPromise.create({
provider: wsProvider2,
signedExtensions: {
SetEvmOrigin: {
extrinsic: {},
payload: {},
},
},
})

return {
chain,
Expand Down
6 changes: 5 additions & 1 deletion src/api.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { ExtDef } from '@polkadot/types/extrinsic/signedExtensions/types'
import { HexString } from '@polkadot/util/types'
import { ProviderInterface } from '@polkadot/rpc-provider/types'

Expand Down Expand Up @@ -31,8 +32,11 @@ export class Api {
#chain: Promise<string>
#chainProperties: Promise<ChainProperties>

constructor(provider: ProviderInterface) {
readonly signedExtensions: ExtDef

constructor(provider: ProviderInterface, signedExtensions?: ExtDef) {
this.#provider = provider
this.signedExtensions = signedExtensions || {}
this.#isReady = new Promise((resolve, reject) => {
if (this.#provider.isConnected) {
setTimeout(resolve, 500)
Expand Down
7 changes: 6 additions & 1 deletion src/blockchain/block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export class Block {
this.#extrinsics = block?.extrinsics
this.#baseStorage = block?.storage ?? new RemoteStorageLayer(chain.api, hash, chain.db)
this.#storages = []
this.#registry = parentBlock?.registry
}

get header(): Header | Promise<Header> {
Expand Down Expand Up @@ -155,7 +156,11 @@ export class Block {
registry.setMetadata(
new Metadata(registry, data),
undefined,
objectSpread<ExtDef>({}, getSpecExtensions(registry, chain, version.specName), {})
objectSpread<ExtDef>(
{},
getSpecExtensions(registry, chain, version.specName),
this.#chain.api.signedExtensions
)
)
return registry
})
Expand Down

0 comments on commit c5c0694

Please sign in to comment.