Skip to content

Commit

Permalink
Get blocktag using shard rather than chain id when invoking call
Browse files Browse the repository at this point in the history
  • Loading branch information
rileystephens28 committed Jan 9, 2025
1 parent bf21419 commit d5ea653
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 15 deletions.
24 changes: 14 additions & 10 deletions src/providers/abstract-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1403,16 +1403,20 @@ export class AbstractProvider<C = FetchRequest> 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) {
Expand Down
15 changes: 10 additions & 5 deletions src/providers/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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);
Expand All @@ -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');
}

Expand Down

0 comments on commit d5ea653

Please sign in to comment.