Skip to content

Commit

Permalink
fix: transaction receipt
Browse files Browse the repository at this point in the history
  • Loading branch information
janek26 committed May 4, 2022
1 parent 5a40cd6 commit 806eb7d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 24 deletions.
20 changes: 5 additions & 15 deletions src/provider/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ import {
GetTransactionStatusResponse,
GetTransactionTraceResponse,
Invocation,
TransactionReceipt,
TransactionReceiptResponse,
} from '../types';
import { getSelectorFromName } from '../utils/hash';
import { parse, stringify } from '../utils/json';
import { BigNumberish, bigNumberishArrayToDecimalStringArray, toBN, toHex } from '../utils/number';
import { compressProgram, randomAddress } from '../utils/stark';
import { ProviderInterface } from './interface';
import { BlockIdentifier, getFormattedBlockIdentifier, txIdentifier } from './utils';
import { BlockIdentifier, getFormattedBlockIdentifier } from './utils';

type NetworkName = 'mainnet-alpha' | 'goerli-alpha';

Expand Down Expand Up @@ -272,22 +272,12 @@ export class Provider implements ProviderInterface {
* [Reference] (https://github.com/starkware-libs/cairo-lang/blob/master/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L104-L111)
*
* @param txHash
* @param txId
* @returns the transaction receipt object
*/

public async getTransactionReceipt({
txHash,
txId,
}: {
txHash?: BigNumberish;
txId?: BigNumberish;
}): Promise<TransactionReceipt> {
const { data } = await axios.get<TransactionReceipt>(
urljoin(this.feederGatewayUrl, 'get_transaction_receipt', `?${txIdentifier(txHash, txId)}`)
);

return data;
public async getTransactionReceipt(txHash: BigNumberish): Promise<TransactionReceiptResponse> {
const txHashHex = toHex(toBN(txHash));
return this.fetchEndpoint('get_transaction_receipt', { transactionHash: txHashHex });
}

/**
Expand Down
10 changes: 2 additions & 8 deletions src/provider/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type {
GetTransactionResponse,
GetTransactionStatusResponse,
Invocation,
TransactionReceipt,
TransactionReceiptResponse,
} from '../types';
import type { BigNumberish } from '../utils/number';
import { BlockIdentifier } from './utils';
Expand Down Expand Up @@ -109,13 +109,7 @@ export abstract class ProviderInterface {
*/
public abstract getTransaction(txHash: BigNumberish): Promise<GetTransactionResponse>;

public abstract getTransactionReceipt({
txHash,
txId,
}: {
txHash?: BigNumberish;
txId?: BigNumberish;
}): Promise<TransactionReceipt>;
public abstract getTransactionReceipt(txHash: BigNumberish): Promise<TransactionReceiptResponse>;

/**
* Deploys a given compiled contract (json) to starknet
Expand Down
9 changes: 8 additions & 1 deletion src/types/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ export type Endpoints = {
REQUEST: never;
RESPONSE: GetTransactionTraceResponse;
};
get_transaction_receipt: {
QUERY: {
transactionHash: string;
};
REQUEST: never;
RESPONSE: TransactionReceiptResponse;
};
get_storage_at: {
QUERY: {
contractAddress: string;
Expand Down Expand Up @@ -217,7 +224,7 @@ export type AddTransactionResponse = {
address?: string;
};

export type TransactionReceipt = {
export type TransactionReceiptResponse = {
status: Status;
transaction_hash: string;
transaction_index: number;
Expand Down

0 comments on commit 806eb7d

Please sign in to comment.