-
Notifications
You must be signed in to change notification settings - Fork 16
Support starknet_getBlockWithTxs
#242
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
Merged
Merged
Changes from 25 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
1bd2629
Reflect spec changes
franciszekjob d409c41
Add tip support
franciszekjob 95dc6bb
Simplify constructors for fee estimate structs
franciszekjob 45bf10f
Fix `testSimulateTransactionsV3`
franciszekjob 7f74704
Fix newline
franciszekjob 74a2b09
Merge branch 'feat/rpc-0.9.0' of https://github.com/software-mansion/…
franciszekjob 3879956
Fix tests
franciszekjob 44dbd3b
Fix tip value in constructor
franciszekjob d4d91b9
Remove unused variables
franciszekjob b45ae20
Restore `ethErc20ContractAddress`
franciszekjob 64a4d62
Apply code review suggestions
franciszekjob 66d81f9
Add comment
franciszekjob 496f776
Merge branch 'main' of https://github.com/software-mansion/starknet.s…
franciszekjob bd822ea
Merge branch 'feat/rpc-0.9.0' of https://github.com/software-mansion/…
franciszekjob ba6c958
Merge branch 'main' of https://github.com/software-mansion/starknet.s…
franciszekjob 281bd7c
Support `starknet_getBlockWithTxs`
franciszekjob 529a31f
Merge branch 'main' into get-block-with-txs
franciszekjob ebf9ecf
Formatting
franciszekjob 5bbe0d6
Merge branch 'get-block-with-txs' of https://github.com/software-mans…
franciszekjob 30e281b
Add network tests
franciszekjob db95e96
Fix commas
franciszekjob 1e5ad3b
Add comma
franciszekjob 042c85b
Remove tests for getting block from regular test suite
franciszekjob 78a0f72
Add todo
franciszekjob 61805c0
Add pre-confirmed coding key in `BlockTag`
franciszekjob 956a0f9
Update todo
franciszekjob File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| public enum BlockStatus: String, Codable { | ||
| case preConfirmed = "PRE_CONFIRMED" | ||
| case acceptedOnL1 = "ACCEPTED_ON_L1" | ||
| case acceptedOnL2 = "ACCEPTED_ON_L2" | ||
| case rejected = "REJECTED" | ||
| } | ||
|
|
||
| public protocol StarknetBlock: Codable { | ||
| var timestamp: Int { get } | ||
| var sequencerAddress: Felt { get } | ||
| var blockNumber: Int { get } | ||
| var l1GasPrice: StarknetResourcePrice { get } | ||
| var l2GasPrice: StarknetResourcePrice { get } | ||
| var l1DataGasPrice: StarknetResourcePrice { get } | ||
| var l1DataAvailabilityMode: StarknetL1DAMode { get } | ||
| var starknetVersion: String { get } | ||
| } | ||
|
|
||
| public protocol StarknetProcessedBlock: StarknetBlock { | ||
| var status: BlockStatus { get } | ||
| var blockHash: Felt { get } | ||
| var parentHash: Felt { get } | ||
| var newRoot: Felt { get } | ||
| } | ||
|
|
||
| public protocol StarknetPreConfirmedBlock: StarknetBlock {} | ||
|
|
||
| public protocol StarknetBlockWithTxs: StarknetBlock { | ||
| var transactions: [TransactionWrapper] { get } | ||
| } | ||
|
|
||
| public struct StarknetProcessedBlockWithTxs: StarknetProcessedBlock, StarknetBlockWithTxs, Encodable { | ||
| public let status: BlockStatus | ||
| public let transactions: [TransactionWrapper] | ||
| public let blockHash: Felt | ||
| public let parentHash: Felt | ||
| public let blockNumber: Int | ||
| public let newRoot: Felt | ||
| public let timestamp: Int | ||
| public let sequencerAddress: Felt | ||
| public let l1GasPrice: StarknetResourcePrice | ||
| public let l2GasPrice: StarknetResourcePrice | ||
| public let l1DataGasPrice: StarknetResourcePrice | ||
| public let l1DataAvailabilityMode: StarknetL1DAMode | ||
| public let starknetVersion: String | ||
|
|
||
| enum CodingKeys: String, CodingKey { | ||
| case status | ||
| case transactions | ||
| case blockHash = "block_hash" | ||
| case parentHash = "parent_hash" | ||
| case blockNumber = "block_number" | ||
| case newRoot = "new_root" | ||
| case timestamp | ||
| case sequencerAddress = "sequencer_address" | ||
| case l1GasPrice = "l1_gas_price" | ||
| case l2GasPrice = "l2_gas_price" | ||
| case l1DataGasPrice = "l1_data_gas_price" | ||
| case l1DataAvailabilityMode = "l1_da_mode" | ||
| case starknetVersion = "starknet_version" | ||
| } | ||
| } | ||
|
|
||
| public struct StarknetPreConfirmedBlockWithTxs: StarknetPreConfirmedBlock, StarknetBlockWithTxs, Codable { | ||
| public let transactions: [TransactionWrapper] | ||
| public let blockNumber: Int | ||
| public let timestamp: Int | ||
| public let sequencerAddress: Felt | ||
| public let l1GasPrice: StarknetResourcePrice | ||
| public let l2GasPrice: StarknetResourcePrice | ||
| public let l1DataGasPrice: StarknetResourcePrice | ||
| public let l1DataAvailabilityMode: StarknetL1DAMode | ||
| public let starknetVersion: String | ||
|
|
||
| enum CodingKeys: String, CodingKey { | ||
| case transactions | ||
| case blockNumber = "block_number" | ||
| case timestamp | ||
| case sequencerAddress = "sequencer_address" | ||
| case l1GasPrice = "l1_gas_price" | ||
| case l2GasPrice = "l2_gas_price" | ||
| case l1DataGasPrice = "l1_data_gas_price" | ||
| case l1DataAvailabilityMode = "l1_da_mode" | ||
| case starknetVersion = "starknet_version" | ||
| } | ||
| } | ||
|
|
||
| public enum StarknetBlockWithTxsWrapper: Codable { | ||
| case processed(StarknetProcessedBlockWithTxs) | ||
| case preConfirmed(StarknetPreConfirmedBlockWithTxs) | ||
|
|
||
| public init(from decoder: Decoder) throws { | ||
| let container = try decoder.container(keyedBy: CodingKeys.self) | ||
| if container.contains(.parentHash) { | ||
| let block = try StarknetProcessedBlockWithTxs(from: decoder) | ||
| self = .processed(block) | ||
| } else { | ||
| let block = try StarknetPreConfirmedBlockWithTxs(from: decoder) | ||
| self = .preConfirmed(block) | ||
| } | ||
| } | ||
|
|
||
| public func encode(to encoder: Encoder) throws { | ||
| switch self { | ||
| case let .processed(block): try block.encode(to: encoder) | ||
| case let .preConfirmed(block): try block.encode(to: encoder) | ||
| } | ||
| } | ||
|
|
||
| private enum CodingKeys: String, CodingKey { | ||
| case parentHash = "parent_hash" | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| public enum StarknetL1DAMode: String, Codable { | ||
| case blob = "BLOB" | ||
| case calldata = "CALLDATA" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| public struct StarknetResourcePrice: Codable, Equatable { | ||
| public let priceInWei: Felt | ||
| public let priceInFri: Felt | ||
|
|
||
| enum CodingKeys: String, CodingKey { | ||
| case priceInWei = "price_in_wei" | ||
| case priceInFri = "price_in_fri" | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cptartur marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| import XCTest | ||
|
|
||
| @testable import Starknet | ||
|
|
||
| final class ProviderTests: XCTestCase { | ||
| var provider: StarknetProviderProtocol! | ||
|
|
||
| override class func setUp() { | ||
| super.setUp() | ||
| } | ||
|
|
||
| override func setUp() async throws { | ||
| try await super.setUp() | ||
|
|
||
| // TODO: Change this to internal node | ||
cptartur marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| provider = StarknetProvider(url: "https://rpc.pathfinder.equilibrium.co/testnet-sepolia/rpc/v0_9") | ||
| } | ||
|
|
||
| func testGetBlockWithTxsWithLatestBlockTag() async throws { | ||
| let result = try await provider.send(request: RequestBuilder.getBlockWithTxs(StarknetBlockId.BlockTag.latest)) | ||
|
|
||
| if case .preConfirmed = result { | ||
| XCTFail("Expected .processed") | ||
| } | ||
| } | ||
|
|
||
| func testGetBlockWithTxsWithPreConfirmedBlockTag() async throws { | ||
| let result = try await provider.send(request: RequestBuilder.getBlockWithTxs(StarknetBlockId.BlockTag.preConfirmed)) | ||
|
|
||
| if case .processed = result { | ||
| XCTFail("Expected .preConfirmed") | ||
| } | ||
| } | ||
|
|
||
| func testGetBlockWithTxsWithBlockHash() async throws { | ||
| let blockHash = Felt(fromHex: "0x05d95c778dad488e15f6a279c77c59322ad61eabf085cd8624ff5b39ca5ae8d8")! | ||
| let result = try await provider.send(request: RequestBuilder.getBlockWithTxs(blockHash)) | ||
|
|
||
| if case let .processed(processedBlock) = result { | ||
| XCTAssertEqual(processedBlock.transactions.count, 7) | ||
| } else { | ||
| XCTFail("Expected .processed") | ||
| } | ||
| } | ||
|
|
||
| func testGetBlockWithTxsWithBlockNumber() async throws { | ||
| let blockNumber = 1_210_000 | ||
| let result = try await provider.send(request: RequestBuilder.getBlockWithTxs(blockNumber)) | ||
|
|
||
| if case let .processed(processedBlock) = result { | ||
| XCTAssertEqual(processedBlock.transactions.count, 8) | ||
| } else { | ||
| XCTFail("Expected .processed") | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.