Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion headers/csps/chains/zcash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,9 @@ const mode = process.env.MODE ?? process.env.NODE_ENV ?? 'development'
const env = loadEnv(mode, process.cwd(), '')

export const csp: Csp = {
'connect-src': [env.VITE_UNCHAINED_ZCASH_HTTP_URL, env.VITE_UNCHAINED_ZCASH_WS_URL],
'connect-src': [
env.VITE_UNCHAINED_ZCASH_HTTP_URL,
env.VITE_UNCHAINED_ZCASH_WS_URL,
'https://api.blockchair.com',
],
}
38 changes: 36 additions & 2 deletions packages/chain-adapters/src/utxo/UtxoBaseAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,23 @@ export abstract class UtxoBaseAdapter<T extends UtxoChainId> implements IChainAd

const signTxInputs: BTCSignTxInput[] = []
for (const input of inputs) {
const data = await this.providers.http.getTransaction({ txid: input.txid })
const data = await (async () => {
try {
return await this.providers.http.getTransaction({ txid: input.txid })
} catch (error) {
if (this.chainId === KnownChainIds.ZcashMainnet) {
const response = await fetch(
`https://api.blockchair.com/zcash/raw/transaction/${input.txid}`,
)
const data = await response.json()
if (!response.ok || data.error) {
throw new Error(`Blockchair API error: ${data.error || response.statusText}`)
}
return { hex: data.data[input.txid].raw_transaction }
}
throw error
}
})()

signTxInputs.push({
// UTXO inputs are not guaranteed to have paths.
Expand Down Expand Up @@ -544,7 +560,25 @@ export abstract class UtxoBaseAdapter<T extends UtxoChainId> implements IChainAd

async broadcastTransaction({ hex }: Pick<BroadcastTransactionInput, 'hex'>): Promise<string> {
try {
const txHash = await this.providers.http.sendTx({ sendTxBody: { hex } })
const txHash = await (async () => {
try {
return await this.providers.http.sendTx({ sendTxBody: { hex } })
} catch (error) {
if (this.chainId === KnownChainIds.ZcashMainnet) {
const response = await fetch('https://api.blockchair.com/zcash/push/transaction', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ data: hex }),
})
const data = await response.json()
if (!response.ok || data.error) {
throw new Error(`Blockchair API error: ${data.error || response.statusText}`)
}
return data.data.transaction_hash
}
throw error
}
})()

return txHash
} catch (err) {
Expand Down