-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Santiago Giaccobasso <santigiacco@192.168.0.100> Co-authored-by: Santiago Giaccobasso <santigiacco@MacBook-Pro.local>
- Loading branch information
1 parent
1f59883
commit 37245c8
Showing
5 changed files
with
171 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@axelarjs/maestro": patch | ||
--- | ||
|
||
create a trpc to recover deployment message ids and use it in token details page to automatically check and recover the missing ids. |
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
95 changes: 95 additions & 0 deletions
95
apps/maestro/src/server/routers/interchainToken/recoverDeploymentMessageIdByTokenId.ts
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,95 @@ | ||
import { z } from "zod"; | ||
|
||
import { hex64Literal } from "~/lib/utils/validation"; | ||
import { protectedProcedure } from "~/server/trpc"; | ||
|
||
export const recoverDeploymentMessageIdByTokenId = protectedProcedure | ||
.input( | ||
z.object({ | ||
tokenId: hex64Literal(), | ||
}) | ||
) | ||
.mutation(async ({ ctx, input }) => { | ||
// constraint: token must be in db | ||
const { postgres } = ctx.persistence; | ||
|
||
const token = await postgres.getInterchainTokenByTokenId(input.tokenId); | ||
|
||
if (!token) { | ||
throw new Error("Token not found"); | ||
} | ||
|
||
// is missing deploymentMessageId? | ||
if (!token.deploymentMessageId) { | ||
// try to find deployment tx hash from indexed events limiting by the token deployment timestamp | ||
|
||
const fromTime = (token.createdAt as Date).getTime() / 1000; | ||
const bufferLength = 60 * 60 * 8; // 8 hours | ||
const toTime = fromTime + bufferLength; | ||
|
||
const deployments = await ctx.services.gmp.searchGMP({ | ||
contractMethod: ["InterchainTokenDeploymentStarted"], | ||
_source: { | ||
excludes: [ | ||
"refunded", | ||
"refund_nonce", | ||
"receipt", | ||
"gas", | ||
"approved", | ||
"gas_price_rate", | ||
"fees", | ||
"gas_paid", | ||
"to_refund", | ||
"confirm", | ||
"command_id", | ||
"time_spent", | ||
"executed.receipt", | ||
"executed.transaction", | ||
], | ||
includes: [ | ||
"status", | ||
"call.transactionHash", | ||
"call.returnValues.destinationChain", | ||
"interchain_token_deployment_started.tokenId", | ||
], | ||
}, | ||
fromTime: fromTime, | ||
toTime: toTime, | ||
size: 1000, | ||
}); | ||
|
||
const validEntries = deployments.filter( | ||
(x) => | ||
x.interchain_token_deployment_started && | ||
x.interchain_token_deployment_started.tokenId === input.tokenId | ||
); | ||
|
||
const results = validEntries.map((x) => { | ||
const logIndex = x.call.logIndex ?? x.call._logIndex ?? 0; | ||
return { | ||
status: x.status, | ||
destinationChain: x.call.returnValues.destinationChain, | ||
txHash: x.call.transactionHash, | ||
logIndex, | ||
deploymentMessageId: `${x.call.transactionHash}-${logIndex}`, | ||
}; | ||
}); | ||
|
||
if (results.length) { | ||
await postgres.updateInterchainTokenDeploymentMessageId( | ||
input.tokenId, | ||
results[0].deploymentMessageId | ||
); | ||
|
||
for (const result of results) { | ||
await postgres.updateRemoteInterchainTokenDeploymentMessageId( | ||
input.tokenId, | ||
result.destinationChain, | ||
result.deploymentMessageId | ||
); | ||
} | ||
|
||
return "updated"; | ||
} | ||
} | ||
}); |
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