-
-
Notifications
You must be signed in to change notification settings - Fork 851
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
refactor: use getAction internally #2627
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,7 +30,6 @@ export type EstimateMaxPriorityFeePerGasErrorType = | |
| GetBlockErrorType | ||
| HexToBigIntErrorType | ||
| RequestErrorType | ||
| GetBlockErrorType | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this was already in the union a few lines above |
||
| GetGasPriceErrorType | ||
| Eip1559FeesNotSupportedErrorType | ||
| ErrorType | ||
|
@@ -87,7 +86,7 @@ export async function internal_estimateMaxPriorityFeePerGas< | |
): Promise<EstimateMaxPriorityFeePerGasReturnType> { | ||
const { block: block_, chain = client.chain, request } = args || {} | ||
if (typeof chain?.fees?.defaultPriorityFee === 'function') { | ||
const block = block_ || (await getAction(client, getBlock, 'getBlock')({})) | ||
const block = block_ || (await getBlock(client)) | ||
return chain.fees.defaultPriorityFee({ | ||
block, | ||
client, | ||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -20,6 +20,7 @@ import { | |||||||||||||||||||||||||
type FormattedBlock, | ||||||||||||||||||||||||||
formatBlock, | ||||||||||||||||||||||||||
} from '../../utils/formatters/block.js' | ||||||||||||||||||||||||||
import { getAction } from '../../utils/getAction.js' | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
export type GetBlockParameters< | ||||||||||||||||||||||||||
includeTransactions extends boolean = false, | ||||||||||||||||||||||||||
|
@@ -92,6 +93,18 @@ export async function getBlock< | |||||||||||||||||||||||||
account extends Account | undefined, | ||||||||||||||||||||||||||
includeTransactions extends boolean = false, | ||||||||||||||||||||||||||
blockTag extends BlockTag = 'latest', | ||||||||||||||||||||||||||
>( | ||||||||||||||||||||||||||
client: Client<Transport, chain, account>, | ||||||||||||||||||||||||||
params: GetBlockParameters<includeTransactions, blockTag> = {}, | ||||||||||||||||||||||||||
): Promise<GetBlockReturnType<chain, includeTransactions, blockTag>> { | ||||||||||||||||||||||||||
return getAction(client, _getBlock, 'getBlock')(params) | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
Comment on lines
+96
to
+101
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Might be able to do this just to save some boilerplate const withGetAction = <TAction>(action: TAction, name: string): TAction => {
return ((client, params) => {
return getAction(client, action, name)(params)
}) as unknown as TAction
}
export const getBlock = withGetAction(_getBlock, 'getBlock') There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. DOn't do this it's convenient but will make stack traces suck |
||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
export async function _getBlock< | ||||||||||||||||||||||||||
chain extends Chain | undefined, | ||||||||||||||||||||||||||
account extends Account | undefined, | ||||||||||||||||||||||||||
includeTransactions extends boolean = false, | ||||||||||||||||||||||||||
blockTag extends BlockTag = 'latest', | ||||||||||||||||||||||||||
>( | ||||||||||||||||||||||||||
client: Client<Transport, chain, account>, | ||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ import type { Transport } from '../../clients/transports/createTransport.js' | |
import type { ErrorType } from '../../errors/utils.js' | ||
import type { Chain } from '../../types/chain.js' | ||
import type { RequestErrorType } from '../../utils/buildRequest.js' | ||
import { getAction } from '../../utils/getAction.js' | ||
import { | ||
type GetCacheErrorType, | ||
getCache, | ||
|
@@ -52,6 +53,13 @@ export function getBlockNumberCache(id: string) { | |
* // 69420n | ||
*/ | ||
export async function getBlockNumber<chain extends Chain | undefined>( | ||
client: Client<Transport, chain>, | ||
params: GetBlockNumberParameters = {}, | ||
): Promise<GetBlockNumberReturnType> { | ||
return getAction(client, _getBlockNumber, 'getBlockNumber')(params) | ||
} | ||
|
||
export async function _getBlockNumber<chain extends Chain | undefined>( | ||
Comment on lines
+59
to
+62
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it actually necessary to export both? Shouldn't getBlockNumber always "just work"? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My understanding is if I override That points to a potentially deeper issue though - would this result in an infinite loop? |
||
client: Client<Transport, chain>, | ||
{ cacheTime = client.cacheTime }: GetBlockNumberParameters = {}, | ||
): Promise<GetBlockNumberReturnType> { | ||
|
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.
we call
getBlock
here, so this error type should also be included here?