Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix provider call method #382

Merged
merged 2 commits into from
Jan 9, 2025
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
2 changes: 1 addition & 1 deletion src/_version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
*
* @ignore
*/
export const version: string = '1.0.0-alpha.32';
export const version: string = '1.0.0-alpha.33';
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
Loading