Skip to content

Commit

Permalink
feat: add getNonce method on account
Browse files Browse the repository at this point in the history
  • Loading branch information
dhruvkelawala committed Sep 5, 2022
1 parent e928478 commit 8e935eb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/account/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,16 @@ export class Account extends Provider implements AccountInterface {
'getPubKey' in keyPairOrSigner ? keyPairOrSigner : new Signer(keyPairOrSigner as KeyPair);
}

public async getNonce(): Promise<BigNumberish> {
return super.getNonce(this.address);
}

public async estimateFee(
calls: Call | Call[],
{ nonce: providedNonce, blockIdentifier }: EstimateFeeDetails = {}
): Promise<EstimateFee> {
const transactions = Array.isArray(calls) ? calls : [calls];
const nonce = toBN(providedNonce ?? (await this.getNonce(this.address)));
const nonce = toBN(providedNonce ?? (await this.getNonce()));
const version = toBN(transactionVersion);

const signerDetails: InvocationsSignerDetails = {
Expand Down Expand Up @@ -81,7 +85,7 @@ export class Account extends Provider implements AccountInterface {
transactionsDetail: InvocationsDetails = {}
): Promise<InvokeFunctionResponse> {
const transactions = Array.isArray(calls) ? calls : [calls];
const nonce = toBN(transactionsDetail.nonce ?? (await this.getNonce(this.address)));
const nonce = toBN(transactionsDetail.nonce ?? (await this.getNonce()));
let maxFee: BigNumberish = '0';
if (transactionsDetail.maxFee || transactionsDetail.maxFee === 0) {
maxFee = transactionsDetail.maxFee;
Expand Down
2 changes: 2 additions & 0 deletions src/account/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,6 @@ export abstract class AccountInterface extends ProviderInterface {
* @throws {Error} if the signature is not a valid signature
*/
public abstract verifyMessageHash(hash: BigNumberish, signature: Signature): Promise<boolean>;

public abstract getNonce(): Promise<BigNumberish>;
}

0 comments on commit 8e935eb

Please sign in to comment.