-
Notifications
You must be signed in to change notification settings - Fork 441
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
feat: improve decode error #831
feat: improve decode error #831
Conversation
return "\(name)(\(inputs.map { $0.type.abiRepresentation }.joined(separator: ",")))" | ||
} | ||
|
||
public var methodString: String { |
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 looks like this could be named selector
as this is the terminology used in Solidity.
I see that methodString
should be rather something like ErrorXyz(uint256,...)
and signature
should be 0xcafe1234
. The same applies for all other types e.g. Function
, Event
etc.
For now, no action here is required. I'll take a look at the terminology used in Solidity and then we can think about renaming some of our variables.
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.
or leave the signature
unchanged, add a new signatureHash
for hash, mark methodEncoding
and methodString
as deprecated
public var methodEncoding: Data { | ||
return signature.data(using: .ascii)!.sha3(.keccak256)[0...3] | ||
} |
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.
What is the methodEncoding
? Maybe I'm forgetting something but it looks unusual.
Any links to docs about it would be appreciated!
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.
Hmm, you borrowed it from Function
, I guess.
Oh, methodEncoding
of Function
is from 2018. We need documentation for it for sure.
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.
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.
So it's the same just raw bytes instead of a string.
@zhangliugang just in case you didn't know: you're able to run all tests locally since all of them are stored in |
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.
I'll try to answer to all comments and push some changes into this PR to lead it to closure until December 3rd.
Sources/Web3Core/EthereumNetwork/Request/APIRequest+Methods.swift
Outdated
Show resolved
Hide resolved
Sources/Web3Core/EthereumNetwork/Request/APIRequest+Methods.swift
Outdated
Show resolved
Hide resolved
Sources/Web3Core/EthereumNetwork/Request/APIRequest+Methods.swift
Outdated
Show resolved
Hide resolved
Sources/Web3Core/EthereumNetwork/Request/APIRequest+Methods.swift
Outdated
Show resolved
Hide resolved
Sources/Web3Core/EthereumNetwork/Request/APIRequest+UtilityTypes.swift
Outdated
Show resolved
Hide resolved
@zhangliugang Please approve this PR zhangliugang#1 |
fix: decode error PR update
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.
Looks like a great improvement over error decoding.
Can this be merged? Not having |
Although I didn't reviewed it appropriately, I'll merge it tomorrow if @JeneaVranceanu has no objections on this. |
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.
Double checking in progress.
Sources/Web3Core/EthereumNetwork/Request/APIRequest+Methods.swift
Outdated
Show resolved
Hide resolved
Sources/Web3Core/EthereumNetwork/Request/APIRequest+Methods.swift
Outdated
Show resolved
Hide resolved
@JeneaVranceanu are we there yet? |
@yaroslavyaroslav Ready to be merged once CI finishes successfully. Will need approval from you because the last commits are authored by me. |
Summary of Changes
Handle revert exception
When a contract call reverted, we may get different data format of response data from different chains, for example:
As so far we can only handle the first condition, So in
APIRequest+Method.swift
, I add a new function to handle the second one, and return theerror.data
field asresult
Seems ethers.js has a complex logic about this, I am not sure which chain will return a revert error in more deeper nesting object.
RequestBody
RequestBody
now accept any object conforms toEncodable
as params, maybe we can removeAPIRequestParameterType
safely.Break changes
Refactor
ContractProtocol.decodeReturnData(_ method: String, data: Data) -> [String: Any]?
to
ContractProtocol.decodeReturnData(_ method: String, data: Data) throws -> [String: Any]
This function will throw
Web3Error.revert(String, reason: String?)
orWeb3Error.revertCustom(String, [String: Any])
whendata
parameter contains an error.Removed fields with
_
prefix from return Dictionary, it only return fields that decoded from given Function.This also effects
ReadOperation.callContractMethod
Refactor
ABI.Element.Function.decodeReturnData(_ data: Data, errors: [String: ABI.Element.EthError]? = nil) -> [String: Any]
to
ABI.Element.Function.decodeReturnData(_ data: Data) throws -> [String: Any]
Add decode error method to
ABI.Element.EthError
, error decode is moved fromFunction
toEthError
many test data in
ABIElementErrorDecodingTest.swfit
has wrong byte length, i have no idea why those tests were passed.Test Data or Screenshots
By submitting this pull request, you are confirming the following:
develop
branch.