-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cloud_function: solana uses acct instead of txhash
- Loading branch information
Showing
10 changed files
with
137 additions
and
44 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
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
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export * from './arrays'; | ||
export * from './consts'; | ||
export * from './utils'; | ||
export * from './explorer'; | ||
export * from './solana'; | ||
export * from './utils'; |
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,62 @@ | ||
import { | ||
CompiledInstruction, | ||
Message, | ||
MessageCompiledInstruction, | ||
MessageV0, | ||
} from '@solana/web3.js'; | ||
import { decode } from 'bs58'; | ||
import { Connection } from '@solana/web3.js'; | ||
import { RPCS_BY_CHAIN } from '@certusone/wormhole-sdk/lib/cjs/relayer'; | ||
import { CONTRACTS } from '@certusone/wormhole-sdk'; | ||
|
||
export const isLegacyMessage = (message: Message | MessageV0): message is Message => { | ||
return message.version === 'legacy'; | ||
}; | ||
|
||
export const normalizeCompileInstruction = ( | ||
instruction: CompiledInstruction | MessageCompiledInstruction | ||
): MessageCompiledInstruction => { | ||
if ('accounts' in instruction) { | ||
return { | ||
accountKeyIndexes: instruction.accounts, | ||
data: decode(instruction.data), | ||
programIdIndex: instruction.programIdIndex, | ||
}; | ||
} else { | ||
return instruction; | ||
} | ||
}; | ||
|
||
export async function convertSolanaTxToAccts(txHash: string): Promise<string[]> { | ||
const POST_MESSAGE_IX_ID = 0x01; | ||
let accounts: string[] = []; | ||
const connection = new Connection(RPCS_BY_CHAIN.MAINNET.solana!, 'finalized'); | ||
const txs = await connection.getTransactions([txHash], { | ||
maxSupportedTransactionVersion: 0, | ||
}); | ||
for (const tx of txs) { | ||
if (!tx) { | ||
continue; | ||
} | ||
const message = tx.transaction.message; | ||
const accountKeys = isLegacyMessage(message) ? message.accountKeys : message.staticAccountKeys; | ||
const programIdIndex = accountKeys.findIndex( | ||
(i) => i.toBase58() === CONTRACTS.MAINNET.solana.core | ||
); | ||
const instructions = message.compiledInstructions; | ||
const innerInstructions = | ||
tx.meta?.innerInstructions?.flatMap((i) => i.instructions.map(normalizeCompileInstruction)) || | ||
[]; | ||
const whInstructions = innerInstructions | ||
.concat(instructions) | ||
.filter((i) => i.programIdIndex === programIdIndex); | ||
for (const instruction of whInstructions) { | ||
// skip if not postMessage instruction | ||
const instructionId = instruction.data; | ||
if (instructionId[0] !== POST_MESSAGE_IX_ID) continue; | ||
|
||
accounts.push(accountKeys[instruction.accountKeyIndexes[1]].toBase58()); | ||
} | ||
} | ||
return accounts; | ||
} |
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 was deleted.
Oops, something went wrong.
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