-
Notifications
You must be signed in to change notification settings - Fork 15
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
Support RPC 0.8.0 #220
base: main
Are you sure you want to change the base?
Support RPC 0.8.0 #220
Changes from all commits
a778a82
d73d3e0
fe40311
4b56a9f
d24a76f
34dcb78
34ab541
b41e8fc
fe432f1
032e7fa
3fd0189
cf88930
009f27f
3d0393b
39283b7
1fa6003
9e02d86
f66140b
e1185e6
f758824
18a907a
fac3657
a27bff3
3933cb5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
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" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
public struct ContractStorageKeys: Encodable { | ||
let contractAddress: Felt | ||
let storageKeys: [Felt] | ||
|
||
enum CodingKeys: String, CodingKey { | ||
case contractAddress = "contract_address" | ||
case storageKeys = "storage_keys" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,29 @@ | ||||||||
public struct ContractsProof: Decodable, Equatable { | ||||||||
public let nodes: NodeHashToNodeMapping | ||||||||
public let contractLeavesData: [ContractLeafData] | ||||||||
|
||||||||
enum CodingKeys: String, CodingKey { | ||||||||
case nodes | ||||||||
case contractLeavesData = "contract_leaves_data" | ||||||||
} | ||||||||
|
||||||||
public init(from decoder: Decoder) throws { | ||||||||
let container = try decoder.container(keyedBy: CodingKeys.self) | ||||||||
nodes = try container.decode(NodeHashToNodeMapping.self, forKey: .nodes) | ||||||||
contractLeavesData = try container.decode([ContractLeafData].self, forKey: .contractLeavesData) | ||||||||
} | ||||||||
|
||||||||
public static func == (lhs: ContractsProof, rhs: ContractsProof) -> Bool { | ||||||||
lhs.nodes == rhs.nodes && lhs.contractLeavesData == rhs.contractLeavesData | ||||||||
} | ||||||||
|
||||||||
Comment on lines
+16
to
+19
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
public struct ContractLeafData: Decodable, Equatable { | ||||||||
public let nonce: Felt | ||||||||
public let classHash: Felt | ||||||||
|
||||||||
enum CodingKeys: String, CodingKey { | ||||||||
case nonce | ||||||||
case classHash = "class_hash" | ||||||||
} | ||||||||
} | ||||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
public struct GlobalRoots: Decodable, Equatable { | ||
public let contractsTreeRoot: Felt | ||
public let classesTreeRoot: Felt | ||
public let blockHash: Felt | ||
|
||
enum CodingKeys: String, CodingKey { | ||
case contractsTreeRoot = "contracts_tree_root" | ||
case classesTreeRoot = "classes_tree_root" | ||
case blockHash = "block_hash" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,74 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import Foundation | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
public enum MerkleNode: Codable, Equatable { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
case binaryNode(BinaryNode) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
case edgeNode(EdgeNode) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
public init(from decoder: Decoder) throws { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
let binaryNodeKeys = Set(BinaryNode.CodingKeys.allCases.map(\.stringValue)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
let edgeNodeKeys = Set(EdgeNode.CodingKeys.allCases.map(\.stringValue)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
let binaryNodeContainer = try decoder.container(keyedBy: BinaryNode.CodingKeys.self) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if Set(binaryNodeContainer.allKeys.map(\.stringValue)) == binaryNodeKeys { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
let binaryNode = try BinaryNode(from: decoder) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
self = .binaryNode(binaryNode) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} else if let edgeNodeContainer = try? decoder.container(keyedBy: EdgeNode.CodingKeys.self), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Set(edgeNodeContainer.allKeys.map(\.stringValue)) == edgeNodeKeys | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
let edgeNode = try EdgeNode(from: decoder) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
self = .edgeNode(edgeNode) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
let context = DecodingError.Context( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
codingPath: decoder.codingPath, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// TODO: Improve error message. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
debugDescription: "Failed to decode MerkleNode from the given data." | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
throw DecodingError.dataCorrupted(context) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+8
to
+28
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems to me this is slightly overcomplicated:
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And while the spec is not merged yet, do you think maybe it's worth it to reach out to starknet-specs maintainers and ask "type" field to be added? "Type" fields are used heavily in the spec overall, so this might be a reasonable ask. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
public func encode(to encoder: Encoder) throws { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
var container = encoder.singleValueContainer() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
switch self { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
case let .binaryNode(binaryNode): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
try container.encode(binaryNode) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
case let .edgeNode(edgeNode): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
try container.encode(edgeNode) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
public static func == (lhs: MerkleNode, rhs: MerkleNode) -> Bool { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
switch (lhs, rhs) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
case let (.binaryNode(lhsBinaryNode), .binaryNode(rhsBinaryNode)): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
lhsBinaryNode == rhsBinaryNode | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
case let (.edgeNode(lhsEdgeNode), .edgeNode(rhsEdgeNode)): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
lhsEdgeNode == rhsEdgeNode | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
default: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
false | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+42
to
+51
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This shouldn't be necessary? 🤔 The advantage of the enum approach is that
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
public struct BinaryNode: Codable, Equatable { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
let left: Felt | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
let right: Felt | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
enum CodingKeys: String, CodingKey, CaseIterable { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
case left | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
case right | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
public struct EdgeNode: Codable, Equatable { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
let path: NumAsHex | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
let length: Int | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
let child: Felt | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
enum CodingKeys: String, CodingKey, CaseIterable { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
case path | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
case length | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
case child | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.