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 various issue relate with dictionary #12

Merged
merged 1 commit into from
Jan 15, 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 packages/node/src/starknet/api.starknet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ describe('Api.starknet', () => {
expect(typeof blockData.logs[0].transaction.transactionIndex).toBe(
'number',
);
expect(blockData.logs[0].transaction.callData.length).toBeGreaterThan(1);
expect(blockData.logs[0].transaction.calldata.length).toBeGreaterThan(1);
});

it('should have the ability to get receipts via transactions from all types', async () => {
Expand Down
6 changes: 3 additions & 3 deletions packages/node/src/starknet/block.starknet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export function filterTransactionsProcessor(
// In case decode calls failed, we try to look into raw calldata
else {
if (filter.function) {
const index = transaction.callData?.findIndex(
const index = transaction.calldata?.findIndex(
(call) =>
call === filter.function ||
call === encodeSelectorToHex(filter.function!),
Expand All @@ -123,7 +123,7 @@ export function filterTransactionsProcessor(
}
}
if (filter.to) {
const index = transaction.callData?.findIndex((call) =>
const index = transaction.calldata?.findIndex((call) =>
hexEq(call, filter.to!),
);
if (index === -1) {
Expand Down Expand Up @@ -171,7 +171,7 @@ function topicsHaveNoCommonElements(array1, array2) {

export function isFullBlock(block: BlockContent): block is StarknetBlock {
if ((block as any).transactions.length) {
return (block as any).transactions[0].type && (block as any).logs.length;
return (block as any).transactions[0].type;
}
return false;
}
25 changes: 19 additions & 6 deletions packages/node/src/starknet/utils.starknet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,14 @@ export function formatTransaction(
txIndex: number,
): Omit<StarknetTransaction, 'receipt'> {
const transaction = {
...tx,
hash: tx.transaction_hash,
type: tx.type,
version: tx.version,
nonce: tx.nonce,
maxFee: tx.max_fee,
from: tx.sender_address,
callData: tx.calldata,
from: getTxContractAddress(tx),
calldata: tx.calldata,
blockHash: block.blockHash,
blockNumber: block.blockNumber,
blockTimestamp: block.timestamp,
Expand All @@ -114,19 +115,19 @@ export function formatTransaction(
transaction.type === 'INVOKE' &&
transaction.version !== ('0x0' || '0x100000000000000000000000000000000')
) {
return decodeInvokeCalldata(transaction.callData);
return decodeInvokeCalldata(transaction.calldata);
}
// Handle "L1_HANDLER" and "INVOKE V0"
else if (
transaction.contractAddress &&
transaction.entryPointSelector &&
transaction.callData
transaction.calldata
) {
return [
decodeGenericCalldata(
transaction.contractAddress,
transaction.entryPointSelector,
transaction.callData,
transaction.calldata,
),
];
}
Expand All @@ -136,10 +137,22 @@ export function formatTransaction(
return JSON.stringify(omit(this, ['receipt', 'toJSON']));
},
} as Omit<StarknetTransaction, 'receipt'>;

return transaction;
}

export function getTxContractAddress(tx: Record<string, any>): string {
if (tx.type === 'DEPLOY' || tx.type === 'DEPLOY_ACCOUNT') {
const result = hash.calculateContractAddressFromHash(
tx.contract_address_salt,
tx.class_hash,
tx.constructor_calldata,
0,
);
return result;
}
return tx.contract_address ?? tx.sender_address;
}

export function formatReceipt(
receipt: Record<string, any>,
): TransactionReceipt {
Expand Down
3 changes: 2 additions & 1 deletion packages/types/src/starknet/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,13 @@ export interface StarknetContractCall<DA = Record<string, any>> {
export type StarknetTransaction = {
type: SPEC.TXN_TYPE;
hash: string;
// This is sender_address or contract_address
from: string;
blockHash: string;
blockNumber: number;
blockTimestamp: number;
transactionIndex: number;
callData: string[];
calldata: string[];
// entryPointSelector and contractAddress been used in L1Handler and V0 Invoke call
entryPointSelector?: string;
contractAddress?: string;
Expand Down
Loading