-
Notifications
You must be signed in to change notification settings - Fork 18
improve: implement a common interface in sdk providers #932
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Signed-off-by: bennett <[email protected]>
provider.getBlock(earliestBlockNumber), | ||
provider.getBlock(highBlock), | ||
]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unsafe cast here. Marking as need to change.
Signed-off-by: bennett <[email protected]>
@@ -0,0 +1,5 @@ | |||
export interface CrosschainProvider { | |||
getBlock(blockTag: number | string): Promise<unknown>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getTransactionCount
is another one that seems to be common.
async getBlock(blockNumber: string | number): Promise<unknown> { | ||
// TODO: Support other evm block tags. | ||
let slot; | ||
try { | ||
slot = BigInt(blockNumber); | ||
} catch { | ||
// Assume block tag = "latest"; | ||
slot = BigInt(await this.getBlockNumber()); | ||
} | ||
return this.rateLimitedRpcClient.getBlock(slot, {}); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be simplified by narrowing the string type.
async getBlock(blockNumber: string | number): Promise<unknown> { | |
// TODO: Support other evm block tags. | |
let slot; | |
try { | |
slot = BigInt(blockNumber); | |
} catch { | |
// Assume block tag = "latest"; | |
slot = BigInt(await this.getBlockNumber()); | |
} | |
return this.rateLimitedRpcClient.getBlock(slot, {}); | |
} | |
async getBlock(blockNumber: number | "latest"): Promise<unknown> { | |
const slot = blockNumber === "latest" | |
? BigInt(await this.getBlockNumber()) | |
: BigInt(blockNumber); | |
return this.rateLimitedRpcClient.getBlock(slot, {}); | |
} |
Ideally we can make custom implementations for our providers (e.g.
speedProvider
) and also make providers for other networks (e.g. a Solana provider) while still using a common utility type (e.g. BlockFinder). I think a good way to achieve this is to extend these providers from a common interface and start utilizing generic types more.