Skip to content

Commit

Permalink
Apply suggestions from review
Browse files Browse the repository at this point in the history
  • Loading branch information
ntn-x2 committed Nov 22, 2023
1 parent 4c3615b commit 3f8224b
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 50 deletions.
39 changes: 12 additions & 27 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,11 @@ export async function generateProviderStateRootProof({
// Optional
providerBlockHeight,
}: ProviderStateRootProofOpts): Promise<ProviderStateRootProofRes> {
const providerChainId = await providerApi.query.parachainInfo.parachainId()
const [providerBlockNumber, providerBlockHash] = await (async () => {
if (providerBlockHeight !== undefined) {
const blockHash = await providerApi.derive.chain
.getBlockByNumber(providerBlockHeight)
.then((b) => b.hash)
const blockHash = (
await providerApi.derive.chain.getBlockByNumber(providerBlockHeight)
).hash
return [providerBlockHeight, blockHash]
}
const providerLastFinalizedBlockHash =
Expand All @@ -72,6 +71,9 @@ export async function generateProviderStateRootProof({
.then((h) => h.number.toNumber())
return [providerLastFinalizedBlockHeight, providerLastFinalizedBlockHash]
})()
const providerApiAtBlock = await providerApi.at(providerBlockHash)
const providerChainId =
await providerApiAtBlock.query.parachainInfo.parachainId()
const relayParentBlockNumber = await providerApi
.at(providerBlockHash)
.then((api) => api.query.parachainSystem.lastRelayChainBlockNumber())
Expand Down Expand Up @@ -238,29 +240,12 @@ export async function generateDipDidSignature({
genesisHash,
},
}: DipDidSignatureOpts): Promise<DipDidSignatureRes> {
const blockNumber = await (async () => {
if (blockHeight !== undefined) {
return blockHeight
}
const n = await api.query.system.number()
return n.toNumber()
})()
const genesis = await (async () => {
if (genesisHash !== undefined) {
return genesisHash
}
return api.query.system.blockHash(0)
})()
const identityDetails = await (async () => {
const maybeIdentityDetails = (await api.query.dipConsumer.identityEntries(
toChain(didUri),
)) as Option<Codec>
try {
return maybeIdentityDetails.unwrap()
} catch {
return api.createType(identityDetailsRuntimeType, null)
}
})()
const blockNumber =
blockHeight ?? (await api.query.system.number()).toNumber()
const genesis = genesisHash ?? (await api.query.system.blockHash(0))
const identityDetails = (
await api.query.dipConsumer.identityEntries<Option<Codec>>(toChain(didUri))
).unwrapOr(api.createType(identityDetailsRuntimeType, null))

const signaturePayload = api
.createType(
Expand Down
8 changes: 2 additions & 6 deletions tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,5 @@
"esModuleInterop": false,
"skipLibCheck": true
},
"exclude": [
"node_modules",
"**/*.test.ts",
"**/*.d.ts"
]
}
"exclude": ["node_modules", "**/*.test.ts", "**/*.d.ts"]
}
7 changes: 2 additions & 5 deletions tsconfig.check.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,5 @@
"compilerOptions": {
"noEmit": true
},
"include": [
"tests/**/*.ts",
"src/**/*.ts"
],
}
"include": ["tests/**/*.ts", "src/**/*.ts"]
}
9 changes: 3 additions & 6 deletions tsconfig.cjs.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
"compilerOptions": {
"outDir": "dist/cjs",
"module": "CommonJS",
"declaration": true,
"declarationDir": "dist/cjs"
"declaration": true
},
"include": [
"src"
]
}
"include": ["src"]
}
9 changes: 3 additions & 6 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
"outDir": "dist/esm",
"module": "Node16",
"moduleResolution": "Node16",
"declaration": true,
"declarationDir": "dist/esm"
"declaration": true
},
"include": [
"src"
]
}
"include": ["src"]
}

0 comments on commit 3f8224b

Please sign in to comment.