Skip to content

Commit

Permalink
Support starknet_getMessagesStatus
Browse files Browse the repository at this point in the history
  • Loading branch information
franciszekjob committed Oct 24, 2024
1 parent d73d3e0 commit fe40311
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 0 deletions.
17 changes: 17 additions & 0 deletions Sources/Starknet/Data/MessageStatus.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
public struct MessageStatus: Decodable, Equatable {
public let transactionHash: Felt
public let finalityStatus: StarknetTransactionStatus
public let failureReason: String?

enum CodingKeys: String, CodingKey {
case transactionHash = "transaction_hash"
case finalityStatus = "finality_status"
case failureReason = "failure_reason"
}

// public static func == (lhs: MessageStatus, rhs: MessageStatus) -> Bool {
// lhs.transactionHash == rhs.transactionHash &&
// lhs.finalityStatus == rhs.finalityStatus &&
// lhs.failureReason == rhs.failureReason
// }
}
12 changes: 12 additions & 0 deletions Sources/Starknet/Network/StarknetRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,18 @@ public enum RequestBuilder {
return StarknetRequest(method: .getTransactionStatus, params: .getTransactionStatus(params))
}

/// Get L1 handler transaction data for all L1 → L2 messages sent by the given L1 transaction.
///
/// - Parameters:
/// - l1TransactionHash: The hash of the L1 transaction
///
/// - Returns: The status of the messages
public static func getMessagesStatus(l1TransactionHash: NumAsHex) -> StarknetRequest<[MessageStatus]> {
let params = GetMessagesStatusPayload(l1TransactionHash: l1TransactionHash)

return StarknetRequest(method: .getMessagesStatus, params: .getMessagesStatus(params))
}

/// Get the currently configured Starknet chain id
///
/// - Returns: The Starknet chain id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ enum JsonRpcMethod: String, Encodable {
case getTransactionByBlockIdAndIndex = "starknet_getTransactionByBlockIdAndIndex"
case getTransactionReceipt = "starknet_getTransactionReceipt"
case getTransactionStatus = "starknet_getTransactionStatus"
case getMessagesStatus = "starknet_getMessagesStatus"
case getChainId = "starknet_chainId"
case simulateTransactions = "starknet_simulateTransactions"
case estimateMessageFee = "starknet_estimateMessageFee"
Expand Down
11 changes: 11 additions & 0 deletions Sources/Starknet/Providers/StarknetProvider/JsonRpcParams.swift
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,14 @@ struct GetTransactionStatusPayload: Encodable {
}
}

struct GetMessagesStatusPayload: Encodable {
let l1TransactionHash: NumAsHex

enum CodingKeys: String, CodingKey {
case l1TransactionHash = "l1_transaction_hash"
}
}

struct SimulateTransactionsParams: Encodable {
let transactions: [any StarknetExecutableTransaction]
let blockId: StarknetBlockId
Expand Down Expand Up @@ -193,6 +201,7 @@ enum JsonRpcParams {
case getTransactionByBlockIdAndIndex(GetTransactionByBlockIdAndIndex)
case getTransactionReceipt(GetTransactionReceiptPayload)
case getTransactionStatus(GetTransactionStatusPayload)
case getMessagesStatus(GetMessagesStatusPayload)
case simulateTransactions(SimulateTransactionsParams)
}

Expand Down Expand Up @@ -229,6 +238,8 @@ extension JsonRpcParams: Encodable {
try params.encode(to: encoder)
case let .getTransactionStatus(params):
try params.encode(to: encoder)
case let .getMessagesStatus(params):
try params.encode(to: encoder)
case let .simulateTransactions(params):
try params.encode(to: encoder)
}
Expand Down

0 comments on commit fe40311

Please sign in to comment.