-
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
Conversation
Sources/Starknet/Data/StorageProof/NodeHashToNodeMappingItem.swift
Outdated
Show resolved
Hide resolved
Sources/Starknet/Data/StorageProof/NodeHashToNodeMappingItem.swift
Outdated
Show resolved
Hide resolved
Co-authored-by: Maksim Zdobnikau <[email protected]>
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) | ||
} |
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.
It seems to me this is slightly overcomplicated:
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) | |
} | |
if let binaryNode = try? BinaryNode(from: decoder) { | |
self = .binaryNode(binaryNode) | |
} else if let edgeNode = try? EdgeNode(from: decoder) { | |
self = .edgeNode(edgeNode) | |
} else { | |
throw DecodingError.dataCorrupted(DecodingError.Context(codingPath: decoder.codingPath, debugDescription: "Failed to decode MerkleNode.")) | |
} |
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.
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 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 | ||
} | ||
} |
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.
This shouldn't be necessary? 🤔
The advantage of the enum approach is that Equatable
conformance should be synthesized automatically.
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 | |
} | |
} |
|
||
let node = try decoder.decode(MerkleNode.self, from: json) | ||
if case let .edgeNode(edgeNode) = node { | ||
XCTAssertEqual(edgeNode.path, 123) |
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.
0x123
!= 123
😅
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) | ||
} | ||
|
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.
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 | ||
} | ||
|
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.
public static func == (lhs: ContractsProof, rhs: ContractsProof) -> Bool { | |
lhs.nodes == rhs.nodes && lhs.contractLeavesData == rhs.contractLeavesData | |
} |
|
||
public init(from decoder: Decoder) throws { | ||
let container = try decoder.container(keyedBy: CodingKeys.self) | ||
|
||
nodeHash = try container.decode(Felt.self, forKey: .nodeHash) | ||
node = try container.decode(MerkleNode.self, forKey: .node) | ||
} | ||
|
||
public static func == (lhs: NodeHashToNodeMappingItem, rhs: NodeHashToNodeMappingItem) -> Bool { | ||
lhs.nodeHash == rhs.nodeHash && lhs.node == rhs.node | ||
} |
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.
public init(from decoder: Decoder) throws { | |
let container = try decoder.container(keyedBy: CodingKeys.self) | |
nodeHash = try container.decode(Felt.self, forKey: .nodeHash) | |
node = try container.decode(MerkleNode.self, forKey: .node) | |
} | |
public static func == (lhs: NodeHashToNodeMappingItem, rhs: NodeHashToNodeMappingItem) -> Bool { | |
lhs.nodeHash == rhs.nodeHash && lhs.node == rhs.node | |
} |
Describe your changes
Add support for RPC 0.8.0
starknet_getStorageProof
StarknetGetStorageProofResponse
,GlobalRoots
,ContractsProof
,ContractLeafData
,NodeHashToNodeMappingItem
,BinaryNode
,EdgeNode
,ContractStorageKey
structsgetStorageProof
method inStarknetRequest
starknet_getMessagesStatus
MessageStatus
structgetMessagesStatus
method inStarknetRequest
StarknetAccountProtocol
:signDeployAccountV3
has nowresourceBounds
param instead ofl1ResourceBounds
StarknetInvokeParamsV3
,StarknetDeployAccountParamsV3
,StarknetOptionalInvokeParamsV3
:l1ResourceBounds
param toresourceBounds
in constructorsStarknetFeeEstimate
:gasConsumed
tol1GasConsumed
gasPrice
tol1GasPrice
dataGasPrice
tol1DataGasPrice
dataGasConsumed
tol1DataGasConsumed
l2GasConsumed
,l2GasPrice
fieldsStarknetResources
protocol to have onlyl1Gas
andl2Gas
fieldsStarknetExecutionResources
fieldsStarknetDataAvailability
andStarknetComputationResources
StarknetInnerCallExecutionResources
l1Gas
inStarknetResourceBoundsMapping
computationResources
toexecutionResources
inStarknetFunctionInvocation
and change its type toStarknetInnerCallExecutionResources
instead ofStarknetComputationResources
failureReason
toStarknetGetTransactionStatusResponse
Linked issues
Closes #219
Breaking changes
resourceBounds
instead ofl1ResourceBounds
paramStarknetComputationResources
has been removed;StarknetExecutionResources
andStarknetFeeEstimate
have been updated