Skip to content

Commit

Permalink
feat(provider): provider expanded with getTransactionTrace
Browse files Browse the repository at this point in the history
  • Loading branch information
MilGard91 committed Mar 15, 2022
1 parent fbaf4ba commit b67361a
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 0 deletions.
8 changes: 8 additions & 0 deletions __tests__/provider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,14 @@ describe('defaultProvider', () => {
})
).resolves.not.toThrow();
});

test('transaction trace', async () => {
const transactionTrace = await defaultProvider.getTransactionTrace(
'0x37013e1cb9c133e6fe51b4b371b76b317a480f56d80576730754c1662582348'
);
expect(transactionTrace).toHaveProperty('function_invocation');
expect(transactionTrace).toHaveProperty('signature');
});
});

describe('addTransaction()', () => {
Expand Down
13 changes: 13 additions & 0 deletions src/provider/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
GetContractAddressesResponse,
GetTransactionResponse,
GetTransactionStatusResponse,
GetTransactionTraceResponse,
Invocation,
TransactionReceipt,
} from '../types';
Expand Down Expand Up @@ -277,6 +278,18 @@ export class Provider implements ProviderInterface {
return this.fetchEndpoint('get_transaction', { transactionHash: txHashHex });
}

/**
* Gets the transaction trace from a tx id.
*
*
* @param txHash
* @returns the transaction trace
*/
public async getTransactionTrace(txHash: BigNumberish): Promise<GetTransactionTraceResponse> {
const txHashHex = toHex(toBN(txHash));
return this.fetchEndpoint('get_transaction_trace', { transactionHash: txHashHex });
}

/**
* Deploys a given compiled contract (json) to starknet
*
Expand Down
49 changes: 49 additions & 0 deletions src/types/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ export type Endpoints = {
REQUEST: never;
RESPONSE: GetTransactionStatusResponse;
};
get_transaction_trace: {
QUERY: {
transactionHash: string;
};
REQUEST: never;
RESPONSE: GetTransactionTraceResponse;
};
get_storage_at: {
QUERY: {
contractAddress: string;
Expand Down Expand Up @@ -97,6 +104,32 @@ export type InvokeFunctionTransaction = {
nonce?: BigNumberish;
};

export type InvokeFunctionTrace = {
caller_address: string;
contract_address: string;
code_address: string;
selector: string;
calldata: RawCalldata;
result: Array<any>;
execution_resources: ExecutionResources;
internal_call: Array<InvokeFunctionTrace>;
events: Array<any>;
messages: Array<any>;
};

export type ExecutionResources = {
n_steps: number;
builtin_instance_counter: {
pedersen_builtin: number;
range_check_builtin: number;
bitwise_builtin: number;
output_builtin: number;
ecdsa_builtin: number;
ec_op_builtin: number;
};
n_memory_holes: number;
};

export type CallContractTransaction = Omit<
InvokeFunctionTransaction,
'type' | 'entry_point_type' | 'nonce'
Expand Down Expand Up @@ -149,6 +182,22 @@ export type GetTransactionStatusResponse = {
};
};

export type GetTransactionTraceResponse = {
function_invocation: {
caller_address: string;
contract_address: string;
code_address: string;
selector: string;
calldata: RawArgs;
result: Array<any>;
execution_resources: any;
internal_call: Array<any>;
events: Array<any>;
messages: Array<any>;
};
signature: Signature;
};

export type GetTransactionResponse = {
status: Status;
transaction: Transaction;
Expand Down

0 comments on commit b67361a

Please sign in to comment.