diff --git a/src/_version.ts b/src/_version.ts index dbdc3ae5..dc9e12ab 100644 --- a/src/_version.ts +++ b/src/_version.ts @@ -5,4 +5,4 @@ * * @ignore */ -export const version: string = '1.0.0-alpha.32'; +export const version: string = '1.0.0-alpha.33'; diff --git a/src/providers/abstract-provider.ts b/src/providers/abstract-provider.ts index f524bd39..6baca077 100644 --- a/src/providers/abstract-provider.ts +++ b/src/providers/abstract-provider.ts @@ -1403,16 +1403,20 @@ export class AbstractProvider implements Provider { }); if (request.blockTag != null) { - const blockTag = this._getBlockTag(toShard(request.chainId!.toString()), request.blockTag); - if (isPromise(blockTag)) { - promises.push( - (async function () { - request.blockTag = await blockTag; - })(), - ); - } else { - request.blockTag = blockTag; - } + const getBlockTag = async () => { + const zone = await this.zoneFromAddress(addressFromTransactionRequest(_request)); + const shard = toShard(zone); + const blockTag = this._getBlockTag(shard, request.blockTag); + if (isPromise(blockTag)) { + return await blockTag; + } + return blockTag; + }; + promises.push( + (async function () { + request.blockTag = await getBlockTag(); + })(), + ); } if (promises.length) { diff --git a/src/providers/provider.ts b/src/providers/provider.ts index 0c0c0c72..a487eef4 100644 --- a/src/providers/provider.ts +++ b/src/providers/provider.ts @@ -54,7 +54,7 @@ import { import { WorkObjectLike } from '../transaction/work-object.js'; import { QiTransactionLike } from '../transaction/qi-transaction.js'; import { QuaiTransactionLike } from '../transaction/quai-transaction.js'; -import { toShard, toZone } from '../constants/index.js'; +import { toShard, toZone, ZeroAddress } from '../constants/index.js'; import { getZoneFromNodeLocation, getZoneForAddress } from '../utils/shards.js'; import { QiPerformActionTransaction } from './abstract-provider.js'; @@ -144,8 +144,16 @@ export class FeeData { */ export function addressFromTransactionRequest(tx: TransactionRequest): AddressLike { if ('from' in tx && !!tx.from) { - return tx.from; + if (tx.from !== ZeroAddress) { + return tx.from; + } + } + if ('to' in tx && !!tx.to) { + if (tx.to !== ZeroAddress) { + return tx.to as AddressLike; + } } + if ('txInputs' in tx && !!tx.txInputs) { const inputs = tx.txInputs as TxInput[]; return computeAddress(inputs[0].pubkey); @@ -154,9 +162,6 @@ export function addressFromTransactionRequest(tx: TransactionRequest): AddressLi const inputs = tx.txIn as TxInputJson[]; return computeAddress(inputs[0].pubkey); } - if ('to' in tx && !!tx.to) { - return tx.to as AddressLike; - } throw new Error('Unable to determine address from transaction inputs, from or to field'); }