Skip to content
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
4 changes: 2 additions & 2 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
"host": "localhost",
"rpcUrls": ["https://starknet-sepolia.public.blastapi.io"],
"chainId": "0x52535453",
"accountClass": "0x004dd9ef00a3db7107fd77c013bccef90dfcf3d970fb791ee741eb32a67e9e6c",
"accountClass": "0x526ea91bc2a91b94795d1e4333ca03d8f5ae9d172908e2d473e780700d44350",
"ethAddress": "0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7",
"strkAddress": "0x04718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d",
"rosettanet": "0x00b77a0dd0400c9d0a49832b3d5d53682b2d1f1bff1eabe46b72dce9aff0bc8a",
"rosettanet": "0x0738a28eda7041678adcfc7f01468b34828dd857937252c4054eb579f15c3489",
"featureTarget": "0x0000000000000000000000004645415455524553",
"validateFeeEstimator": "0x03eaf353b4e78e3c4daaf0bbf81a58171be1bbe13924a4ac07522ae60bdcd85e",
"logging": {
Expand Down
205 changes: 109 additions & 96 deletions src/rpc/calls/getTransactionReceipt.ts
Original file line number Diff line number Diff line change
@@ -1,104 +1,105 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { Transaction } from "ethers";
import { ethers, Transaction } from "ethers";

Check failure on line 2 in src/rpc/calls/getTransactionReceipt.ts

View workflow job for this annotation

GitHub Actions / node

'ethers' is defined but never used
import { writeLog } from "../../logger";
import { isStarknetRPCError } from "../../types/typeGuards";
import { RosettanetRawCalldata, RPCError, RPCRequest, RPCResponse, StarknetRPCError } from "../../types/types";
import { callStarknet } from "../../utils/callHelper";
import { sumHexStrings } from "../../utils/converters/integer";
import { padHashTo64, padTo256Byte } from "../../utils/padding";
import { parseRosettanetRawCalldata } from "../../utils/rosettanet";
import { getEthersTransactionFromRosettanetCall } from "../../utils/signature";
import { parseRosettanetRawCalldata, isRosettaAccountDeployed } from "../../utils/rosettanet";
import { getEthersTransactionFromRosettanetCall, getEthersTransactionFromStarknetCall } from "../../utils/signature";
import { getConfigurationProperty } from "../../utils/configReader";

export async function getTransactionReceiptHandler(request: RPCRequest): Promise<RPCResponse | RPCError> {
if(!Array.isArray(request.params)) {
return {
jsonrpc: request.jsonrpc,
id: request.id,
error: {
code: -32602,
message: 'Invalid argument, Parameter must be array',
},
}
if (!Array.isArray(request.params)) {
return {
jsonrpc: request.jsonrpc,
id: request.id,
error: {
code: -32602,
message: 'Invalid argument, Parameter must be array',
},
}
if(request.params.length != 1) {
return {
jsonrpc: request.jsonrpc,
id: request.id,
error: {
code: -32602,
message: 'Arguments must be length of 1',
},
}
}
if (request.params.length != 1) {
return {
jsonrpc: request.jsonrpc,
id: request.id,
error: {
code: -32602,
message: 'Arguments must be length of 1',
},
}
}

const txHash = request.params[0] as string

const starknetTxReceipt: RPCResponse | StarknetRPCError = await callStarknet({
jsonrpc: request.jsonrpc,
method: 'starknet_getTransactionReceipt',
params: {
transaction_hash: txHash,
},
id: request.id,
})

const txHash = request.params[0] as string

const starknetTxReceipt: RPCResponse | StarknetRPCError = await callStarknet({
jsonrpc: request.jsonrpc,
method: 'starknet_getTransactionReceipt',
params: {
transaction_hash: txHash,
},
id: request.id,
})

if(isStarknetRPCError(starknetTxReceipt)) {
return <RPCError>{
jsonrpc: request.jsonrpc,
id: request.id,
error: starknetTxReceipt,
}
if (isStarknetRPCError(starknetTxReceipt)) {
return <RPCError>{
jsonrpc: request.jsonrpc,
id: request.id,
error: starknetTxReceipt,
}
}

const starknetTxDetails: RPCResponse | StarknetRPCError = await callStarknet({
jsonrpc: request.jsonrpc,
method: 'starknet_getTransactionByHash',
params: {
transaction_hash: txHash,
},
id: request.id,
})


const starknetTxDetails: RPCResponse | StarknetRPCError = await callStarknet({
jsonrpc: request.jsonrpc,
method: 'starknet_getTransactionByHash',
params: {
transaction_hash: txHash,
},
id: request.id,
})



if(isStarknetRPCError(starknetTxDetails)) {
return <RPCError>{
jsonrpc: request.jsonrpc,
id: request.id,
error: starknetTxDetails,
}

if (isStarknetRPCError(starknetTxDetails)) {
return <RPCError>{
jsonrpc: request.jsonrpc,
id: request.id,
error: starknetTxDetails,
}
}

writeLog(0, JSON.stringify(starknetTxReceipt.result))
writeLog(0, JSON.stringify(starknetTxDetails.result))
writeLog(0, JSON.stringify(starknetTxReceipt.result))
writeLog(0, JSON.stringify(starknetTxDetails.result))

const { blockHash, blockNumber, status } = parseTxReceipt(starknetTxReceipt.result);
const { from, to, gasUsed, cumulativeGasUsed, effectiveGasPrice } = parseTxDetails(starknetTxDetails.result);
const { blockHash, blockNumber, status } = parseTxReceipt(starknetTxReceipt.result);
const { from, to, gasUsed, cumulativeGasUsed, effectiveGasPrice } = await parseTxDetails(starknetTxDetails.result);

const txType = getTransactionType(starknetTxDetails.result)
const txType = getTransactionType(starknetTxDetails.result)



// Notice: In latest version we do not return deploy account tx hash to wallets. So we dont need to check for tx type
// Todo: assert starknet response
const receiptResponse = {
blockHash,
blockNumber,
transactionHash: padHashTo64(txHash),
status,
type: txType,
contractAddress: null,
logs : [],
logsBloom: padTo256Byte('0x0'), // Belki bu 256 bytelik 0 olmasi gerekiyordur ?
from, to, gasUsed, cumulativeGasUsed, effectiveGasPrice, transactionIndex: '0x1'
}

return {
jsonrpc: '2.0',
id: request.id,
result: receiptResponse
}
}
// Notice: In latest version we do not return deploy account tx hash to wallets. So we dont need to check for tx type
// Todo: assert starknet response
const receiptResponse = {
blockHash,
blockNumber,
transactionHash: padHashTo64(txHash),
status,
type: txType,
contractAddress: null,
logs: [],
logsBloom: padTo256Byte('0x0'), // Belki bu 256 bytelik 0 olmasi gerekiyordur ?
from, to, gasUsed, cumulativeGasUsed, effectiveGasPrice, transactionIndex: '0x1'
}

return {
jsonrpc: '2.0',
id: request.id,
result: receiptResponse
}
}

/*
+ "blockHash": "0x0a79eca9f5ca58a1d5d5030a0fabfdd8e815b8b77a9f223f74d59aa39596e1c7",
Expand All @@ -117,44 +118,56 @@
+ "type": "0x2"
*/
// Inputs starknet_getTransactionByHash result
function parseTxDetails(result:any): {from:string; to:string; gasUsed:string; cumulativeGasUsed: string; type:string; effectiveGasPrice:string} {
async function parseTxDetails(result: any): Promise<{ from: string; to: string; gasUsed: string; cumulativeGasUsed: string; type: string; effectiveGasPrice: string }> {
// from address await ile eth adres cekilmeli ama??
const accountClass = getConfigurationProperty("accountClass")

let ethersTx: Transaction | undefined

const isRosettanetAccount = await isRosettaAccountDeployed(result.sender_address, accountClass)


if (isRosettanetAccount) {
ethersTx = getEthersTransactionFromRosettanetCall(result.signature, result.calldata)
} else {
console.log("123")

Check failure on line 133 in src/rpc/calls/getTransactionReceipt.ts

View workflow job for this annotation

GitHub Actions / node

Unexpected console statement
ethersTx = getEthersTransactionFromStarknetCall(result)
}

const ethersTx: Transaction = getEthersTransactionFromRosettanetCall(result.signature, result.calldata)
const parsedCalldata: RosettanetRawCalldata | undefined = parseRosettanetRawCalldata(result.calldata)

if(typeof parsedCalldata === 'undefined') {
if (typeof parsedCalldata === 'undefined' && isRosettanetAccount) {
writeLog(2, 'Error at parsing RawCalldata')
writeLog(2, result.calldata)
return {
gasUsed: '0x0', from: '0x0', to: '0x0', cumulativeGasUsed: '0x0', type: '0x0', effectiveGasPrice: '0x0'
};
}

const type = parsedCalldata.txType;
const to = parsedCalldata.to;
const gasUsed = parsedCalldata.gasLimit;
const type = parsedCalldata?.txType ? parsedCalldata.txType : (ethersTx?.type?.toString() ?? '0x0');
const to = parsedCalldata?.to ? parsedCalldata.to : (ethersTx?.to ?? '0x0');
const gasUsed = parsedCalldata?.gasLimit ? parsedCalldata.gasLimit : (ethersTx?.gasLimit ? '0x' + ethersTx.gasLimit.toString(16) : '0x0');
const cumulativeGasUsed = sumHexStrings(gasUsed, gasUsed);
const from = ethersTx.from ? ethersTx.from : '0x0';
const from = ethersTx?.from ?? '0x0'
// Calculate gas price from calldata
return {
gasUsed, cumulativeGasUsed, from, to, type, effectiveGasPrice: getEffectiveGasPrice(ethersTx)
gasUsed, cumulativeGasUsed, from, to, type, effectiveGasPrice: ethersTx ? getEffectiveGasPrice(ethersTx) : '0x0'
}
}

function getEffectiveGasPrice(tx: Transaction): string {
if(tx.type == 2) {
if (tx.type == 2) {
// EIP-1559
const price = tx.maxFeePerGas;
if(price) {
if (price) {
return '0x' + price.toString(16)
} else {
return '0x0'
}
} else {
// Legacy
const price = tx.gasPrice;
if(price) {
if (price) {
return '0x' + price.toString(16)
} else {
return '0x0'
Expand All @@ -163,7 +176,7 @@
}

// Inputs starknet_getTransactionReceipt result
function parseTxReceipt(result: any): {blockHash:string; blockNumber:string; transactionHash: string; status:string; events:any;} {
function parseTxReceipt(result: any): { blockHash: string; blockNumber: string; transactionHash: string; status: string; events: any; } {
const blockHash = typeof result.block_hash === 'string' ? padHashTo64(result.block_hash) : padHashTo64('0x0');
const blockNumber = typeof result.block_number === 'number' ? '0x' + result.block_number.toString(16) : '0x0';
const transactionHash = typeof result.transaction_hash === 'string' ? padHashTo64(result.transaction_hash) : padHashTo64('0x0');
Expand All @@ -177,7 +190,7 @@
}

function getTransactionStatus(exec_status: string): string {
if(exec_status === 'REVERTED') {
if (exec_status === 'REVERTED') {
return '0x0'
}

Expand All @@ -187,14 +200,14 @@
// Inputs starknet_getTransactionByHash result
function getTransactionType(txDetailsResult: any): string {
const calldata = txDetailsResult?.calldata;
if(!Array.isArray(calldata)) {
if (!Array.isArray(calldata)) {
return '0x0'
}
if(calldata.length == 0) {
if (calldata.length == 0) {
return '0x0'
}

if(calldata[0] === '0x0') {
if (calldata[0] === '0x0') {
return '0x0'
} else {
return '0x2'
Expand Down
Loading
Loading