-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
89 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { transactionFeePriorities } from "./transaction-fee-priorities.js"; | ||
export type * as TransactionFeePriorities from "./transaction-fee-priorities.js"; | ||
|
||
export const mempool = { | ||
transactionFeePriorities, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import { | ||
error, | ||
safePromise, | ||
success, | ||
type Result, | ||
type SafeError, | ||
} from "../../utils/safe.js"; | ||
import type { ApiRequestOptions } from "../types.js"; | ||
|
||
export type FeePrioritiesResponse = { | ||
all: { | ||
no_priority: number; | ||
low_priority: number; | ||
medium_priority: number; | ||
high_priority: number; | ||
}; | ||
token_transfer: { | ||
no_priority: number; | ||
low_priority: number; | ||
medium_priority: number; | ||
high_priority: number; | ||
}; | ||
smart_contract: { | ||
no_priority: number; | ||
low_priority: number; | ||
medium_priority: number; | ||
high_priority: number; | ||
}; | ||
contract_call: { | ||
no_priority: number; | ||
low_priority: number; | ||
medium_priority: number; | ||
high_priority: number; | ||
}; | ||
}; | ||
|
||
export async function transactionFeePriorities( | ||
opts: ApiRequestOptions, | ||
): Promise< | ||
Result< | ||
FeePrioritiesResponse, | ||
SafeError< | ||
"FetchFeePrioritiesError" | "ParseBodyError" | "ValidateDataError" | ||
> | ||
> | ||
> { | ||
const init: RequestInit = {}; | ||
if (opts.apiKeyConfig) { | ||
init.headers = { | ||
[opts.apiKeyConfig.header]: opts.apiKeyConfig.key, | ||
}; | ||
} | ||
|
||
const endpoint = `${opts.baseUrl}/extended/v2/mempool/fees`; | ||
const res = await fetch(endpoint, init); | ||
|
||
if (!res.ok) { | ||
return error({ | ||
name: "FetchFeePrioritiesError", | ||
message: "Failed to fetch transaction fee priorities.", | ||
data: { | ||
status: res.status, | ||
statusText: res.statusText, | ||
bodyParseResult: await safePromise(res.text()), | ||
}, | ||
}); | ||
} | ||
|
||
const [jsonError, data] = await safePromise(res.json()); | ||
if (jsonError) { | ||
return error({ | ||
name: "ParseBodyError", | ||
message: "Failed to parse response body as JSON.", | ||
data: jsonError, | ||
}); | ||
} | ||
|
||
return success(data as FeePrioritiesResponse); | ||
} |