This repository was archived by the owner on Aug 6, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
refactor: migrate publishIntent(s) function #552
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
f88ad62
refactor: migrate publishIntent utils
jobotics 283586e
fix: correct publish intent legacy reasons
jobotics 75c76c0
refactor: migrate publishIntents utils
jobotics 06c1f2b
chore: remove legacy function publishIntent
jobotics 1a89c3f
Merge branch 'beta' into refactor/migrate-publish-intent
cawabunga-bytes File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 was deleted.
Oops, something went wrong.
This file contains hidden or 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 |
|---|---|---|
| @@ -1,62 +1,54 @@ | ||
| import { retry } from "@lifeomic/attempt" | ||
| import type { solverRelay } from "@defuse-protocol/internal-utils" | ||
| import { Err, Ok, type Result } from "@thames/monads" | ||
| import { logger } from "../../logger" | ||
| import * as solverRelayClient from "./solverRelayHttpClient" | ||
| import { | ||
| type ParsedPublishErrors, | ||
| parseFailedPublishError, | ||
| } from "./utils/parseFailedPublishError" | ||
|
|
||
| export async function publishIntents( | ||
| ...args: Parameters<typeof solverRelayClient.publishIntents> | ||
| ): Promise<Result<PublishIntentsOk, PublishIntentsErr>> { | ||
| const [params, requestConfig] = args | ||
| return retry( | ||
| () => | ||
| solverRelayClient.publishIntents(params, { | ||
| timeout: 30000, | ||
| ...requestConfig, | ||
| }), | ||
| { | ||
| delay: 1000, | ||
| factor: 1.5, | ||
| maxAttempts: 7, | ||
| jitter: true, | ||
| minDelay: 1000, | ||
| } | ||
| ) | ||
| .then(parsePublishIntentsResponse, (err) => { | ||
| logger.error(new Error("Failed to publish intents", { cause: err })) | ||
| return Err<PublishIntentsOk, PublishIntentsErr>({ | ||
| reason: "RELAY_PUBLISH_NETWORK_ERROR", | ||
| }) | ||
| }) | ||
| .then((result) => { | ||
| if (result.isErr()) { | ||
| const err = result.unwrapErr() | ||
| if (err.reason === "RELAY_PUBLISH_UNKNOWN_ERROR") { | ||
| logger.error(err.serverReason) | ||
| } | ||
| } | ||
| return result | ||
| }) | ||
| } | ||
| import type { ParsedPublishErrors } from "./utils/parseFailedPublishError" | ||
|
|
||
| export type PublishIntentsOk = string[] | ||
| export type PublishIntentsErr = | ||
| | ParsedPublishErrors | ||
| | { reason: "RELAY_PUBLISH_NETWORK_ERROR" } | ||
|
|
||
| function parsePublishIntentsResponse( | ||
| response: Awaited<ReturnType<typeof solverRelayClient.publishIntents>> | ||
| ): Result<PublishIntentsOk, PublishIntentsErr> { | ||
| if (response.status === "OK") { | ||
| return Ok(response.intent_hashes) | ||
| export function convertPublishIntentsToLegacyFormat( | ||
| result: Result< | ||
| solverRelay.PublishIntentsReturnType, | ||
| solverRelay.PublishIntentsErrorType | ||
| > | ||
| ): Promise<Result<PublishIntentsOk, PublishIntentsErr>> { | ||
| if (result.isOk()) { | ||
| return Promise.resolve(Ok(result.unwrap())) | ||
| } | ||
|
|
||
| if (response.reason === "already processed") { | ||
| return Ok(response.intent_hashes) | ||
| const error = result.unwrapErr() | ||
| const errorCode = error.code | ||
|
|
||
| // Map new PublishErrorCode to old ParsedPublishErrors format | ||
| let reason: ParsedPublishErrors["reason"] | ||
| switch (errorCode) { | ||
| case "SIGNATURE_EXPIRED": | ||
| reason = "RELAY_PUBLISH_SIGNATURE_EXPIRED" | ||
| break | ||
| case "INTERNAL_ERROR": | ||
| reason = "RELAY_PUBLISH_INTERNAL_ERROR" | ||
| break | ||
| case "SIGNATURE_INVALID": | ||
| reason = "RELAY_PUBLISH_SIGNATURE_INVALID" | ||
| break | ||
| case "NONCE_USED": | ||
| reason = "RELAY_PUBLISH_NONCE_USED" | ||
| break | ||
| case "INSUFFICIENT_BALANCE": | ||
| reason = "RELAY_PUBLISH_INSUFFICIENT_BALANCE" | ||
| break | ||
| case "PUBLIC_KEY_NOT_EXIST": | ||
| reason = "RELAY_PUBLISH_PUBLIC_NOT_EXIST" | ||
| break | ||
| default: | ||
| reason = "RELAY_PUBLISH_UNKNOWN_ERROR" | ||
| } | ||
|
|
||
| return Err(parseFailedPublishError(response)) | ||
| return Promise.resolve( | ||
| Err({ | ||
| reason, | ||
| serverReason: errorCode, | ||
| }) | ||
| ) | ||
| } | ||
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Fix typo in error reason
The reason should be
RELAY_PUBLISH_PUBLIC_KEY_NOT_EXISTto match the pattern and be more descriptive.📝 Committable suggestion
🤖 Prompt for AI Agents