@near-eth/utils
Advanced tools
Comparing version 2.4.0 to 2.4.1
import { ethers } from 'ethers'; | ||
export declare class SearchError extends Error { | ||
} | ||
export declare function findFinalizationTxOnNear({ proof, connectorAccount, eventRelayerAccount, finalizationMethod, callIndexer }: { | ||
proof: string; | ||
connectorAccount: string; | ||
eventRelayerAccount: string; | ||
finalizationMethod: string; | ||
callIndexer: (query: string) => Promise<Array<{ | ||
originated_from_transaction_hash: string; | ||
included_in_block_timestamp: string; | ||
}>>; | ||
export interface ExplorerIndexerResult { | ||
originated_from_transaction_hash: string; | ||
included_in_block_timestamp: string; | ||
} | ||
export declare function findFinalizationTxOnNear({ proof, connectorAccount, eventRelayerAccount, finalizationMethod, ethTxHash, callIndexer }: { | ||
proof?: string; | ||
connectorAccount?: string; | ||
eventRelayerAccount?: string; | ||
finalizationMethod?: string; | ||
ethTxHash?: string; | ||
callIndexer: (query: string) => Promise<ExplorerIndexerResult[] | string>; | ||
}): Promise<{ | ||
@@ -14,0 +16,0 @@ transactions: string[]; |
@@ -12,17 +12,26 @@ "use strict"; | ||
exports.SearchError = SearchError; | ||
async function findFinalizationTxOnNear({ proof, connectorAccount, eventRelayerAccount, finalizationMethod, callIndexer }) { | ||
const query = `SELECT public.receipts.originated_from_transaction_hash, public.receipts.included_in_block_timestamp | ||
FROM public.receipts | ||
JOIN public.action_receipt_actions | ||
ON public.action_receipt_actions.receipt_id = public.receipts.receipt_id | ||
WHERE (receipt_predecessor_account_id = '${eventRelayerAccount}' | ||
AND receipt_receiver_account_id = '${connectorAccount}' | ||
AND args ->> 'method_name' = '${finalizationMethod}' | ||
AND args ->> 'args_base64' = '${proof}' | ||
)`; | ||
// NOTE: Generally only 1 result is returned, but allow multiple in case finalization attempts are made. | ||
const results = await callIndexer(query); | ||
const transactions = results.map(tx => tx.originated_from_transaction_hash); | ||
const timestamps = results.map(tx => Number(tx.included_in_block_timestamp)); | ||
return { transactions, timestamps }; | ||
async function findFinalizationTxOnNear({ proof, connectorAccount, eventRelayerAccount, finalizationMethod, ethTxHash, callIndexer }) { | ||
if (ethTxHash) { | ||
const nearTxHash = await callIndexer(ethTxHash); | ||
return { transactions: [nearTxHash], timestamps: [] }; | ||
} | ||
else if (proof && connectorAccount && eventRelayerAccount && finalizationMethod) { | ||
const query = `SELECT public.receipts.originated_from_transaction_hash, public.receipts.included_in_block_timestamp | ||
FROM public.receipts | ||
JOIN public.action_receipt_actions | ||
ON public.action_receipt_actions.receipt_id = public.receipts.receipt_id | ||
WHERE (receipt_predecessor_account_id = '${eventRelayerAccount}' | ||
AND receipt_receiver_account_id = '${connectorAccount}' | ||
AND args ->> 'method_name' = '${finalizationMethod}' | ||
AND args ->> 'args_base64' = '${proof}' | ||
)`; | ||
// NOTE: Generally only 1 result is returned, but allow multiple in case finalization attempts are made. | ||
const results = await callIndexer(query); | ||
const transactions = results.map(tx => tx.originated_from_transaction_hash); | ||
const timestamps = results.map(tx => Number(tx.included_in_block_timestamp)); | ||
return { transactions, timestamps }; | ||
} | ||
else { | ||
throw new Error('Expected ethTxHash or sql query params'); | ||
} | ||
} | ||
@@ -29,0 +38,0 @@ exports.findFinalizationTxOnNear = findFinalizationTxOnNear; |
@@ -5,3 +5,3 @@ export * as urlParams from './url-params'; | ||
export * as aurora from './aurora'; | ||
export { findFinalizationTxOnEthereum, findFinalizationTxOnNear } from './findFinalizationTx'; | ||
export { findFinalizationTxOnEthereum, findFinalizationTxOnNear, ExplorerIndexerResult } from './findFinalizationTx'; | ||
export { borshifyOutcomeProof } from './borshify-proof'; | ||
@@ -8,0 +8,0 @@ export { ethOnNearSyncHeight } from './ethOnNearClient'; |
{ | ||
"name": "@near-eth/utils", | ||
"version": "2.4.0", | ||
"version": "2.4.1", | ||
"license": "(MIT AND Apache-2.0)", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
61106
696