@@ -5,7 +5,7 @@ import type { ApiPromise } from "@polkadot/api"
55import { Option as PolkadotOption } from "@polkadot/types"
66import { logger } from "ethers"
77import { TextEncoder } from "util"
8- import { CHAINS_BY_ISMP_HOST } from "@/constants"
8+ import { CHAINS_BY_ISMP_HOST , TRON_CHAIN_IDS } from "@/constants"
99import { providers } from "ethers"
1010import { Codec } from "@polkadot/types/types"
1111
@@ -146,12 +146,26 @@ export async function fetchStateCommitmentsEVM(params: {
146146 // Generate keys for timestamp, overlay, and state root
147147 const [ timestampKey , overlayKey , stateRootKey ] = generateStateCommitmentKeys ( paraId , height )
148148
149- // For all other EVM chains, use SubQuery's api provider which correctly
150- // queries storage at the specific block height being indexed.
151- const provider = api as providers . Provider
152- const timestampValue = await provider . getStorageAt ( hostContract , bytesToHex ( timestampKey ) )
153- const overlayRootValue = await provider . getStorageAt ( hostContract , bytesToHex ( overlayKey ) )
154- const stateRootValue = await provider . getStorageAt ( hostContract , bytesToHex ( stateRootKey ) )
149+ const isTron = TRON_CHAIN_IDS . has ( chainId )
150+ if ( isTron && ! unsafeApi ) {
151+ logger . warn ( "unsafeApi is not available for Tron chain, cannot fetch state commitments" )
152+ return null
153+ }
154+ const provider = ( isTron ? unsafeApi ! : api ) as providers . Provider
155+
156+ let timestampValue : string | null
157+ let overlayRootValue : string | null
158+ let stateRootValue : string | null
159+
160+ if ( isTron ) {
161+ timestampValue = await provider . getStorageAt ( hostContract , bytesToHex ( timestampKey ) , "latest" )
162+ overlayRootValue = await provider . getStorageAt ( hostContract , bytesToHex ( overlayKey ) , "latest" )
163+ stateRootValue = await provider . getStorageAt ( hostContract , bytesToHex ( stateRootKey ) , "latest" )
164+ } else {
165+ timestampValue = await provider . getStorageAt ( hostContract , bytesToHex ( timestampKey ) )
166+ overlayRootValue = await provider . getStorageAt ( hostContract , bytesToHex ( overlayKey ) )
167+ stateRootValue = await provider . getStorageAt ( hostContract , bytesToHex ( stateRootKey ) )
168+ }
155169
156170 if ( ! timestampValue ) {
157171 return null
0 commit comments