-
Notifications
You must be signed in to change notification settings - Fork 1k
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
[Neo Core Exception] Create WalletException and use it to replace all exceptions in wallet #3434
base: master
Are you sure you want to change the base?
Conversation
Problem of this pr is that maybe its depencencies need to update there exception handling logic as the exception has being changed. |
@shargon any further suggestion? |
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 am reviewing the PR, @Jim8y. But there are many changes still to review and test here from my side.
blocked for vitor to review |
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.
You have to build 1st. |
And I also noticed it is a Partial Class, so they show differently later. Before I had dotnet restokre && dotnet build --no-restore |
@@ -90,78 +104,90 @@ internal static byte[] XOR(byte[] x, byte[] y) | |||
/// <returns>The network fee of the transaction.</returns> | |||
public static long CalculateNetworkFee(this Transaction tx, DataCache snapshot, ProtocolSettings settings, Func<UInt160, byte[]> accountScript, long maxExecutionCost = ApplicationEngine.TestModeGas) |
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 will make conflicts into my never ending pull request #3385 :'(
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.
Moved to #3539.
src/Neo/Wallets/Wallet.cs
Outdated
@@ -141,6 +141,7 @@ public WalletAccount CreateAccount() | |||
{ | |||
var privateKey = new byte[32]; | |||
using var rng = RandomNumberGenerator.Create(); | |||
var maxTry = 100; |
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.
how much time it spend in 100 ? maybe is few number?
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 is not likly t happen,,,,,but will do 10
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.
Before it was infinite...eahuehauea
Any number is good to me here, but 10 looks small but unlikely to happen.
Tests completed from my side here. I will just check the code here on github again. But no blocker. |
…ndardize-exception * 'standardize-exception' of github.com:Jim8y/neo: Clean using [Neo Core Add] add char support (neo-project#3441) [rpc] Extend `getversion` RPC response with additional protocol settings (neo-project#3443) update benchmark system (neo-project#3442) [`Optimization`] Parsing Smart Contract Script Analysis (neo-project#3420) `[Move]` Part-3 Classes into Different Library - `Neo.Extensions` (neo-project#3400)
I still reviewing this one |
@@ -90,78 +104,90 @@ internal static byte[] XOR(byte[] x, byte[] y) | |||
/// <returns>The network fee of the transaction.</returns> | |||
public static long CalculateNetworkFee(this Transaction tx, DataCache snapshot, ProtocolSettings settings, Func<UInt160, byte[]> accountScript, long maxExecutionCost = ApplicationEngine.TestModeGas) |
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.
catch (Exception ex) when (ex is not WalletException) | ||
{ | ||
sb.EmitDynamicCall(asset_id, "decimals", CallFlags.ReadOnly); | ||
sb.EmitDynamicCall(asset_id, "symbol", CallFlags.ReadOnly); | ||
script = sb.ToArray(); | ||
throw WalletException.FromException(ex); | ||
} |
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.
WalletException
constructor is able to create WalletException
from WalletException
, so we can safely remove when (ex is not WalletException)
.
} | ||
catch (Exception e) when (e is not WalletException) | ||
{ | ||
throw new WalletException(WalletErrorType.InvalidPrivateKey, "Invalid WIF format.", e); |
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.
"Invalid WIF format."
It may be something else, because invalid WIF format is handled earlier.
Description
We use general exceptions in the neo core that is hard to tell the exact exception reason. Thus in this pr i define a new exception type
WalletException
, it contains multiple error types.For instance, in
CalculateNetworkFee
method, the exception reason can be very different, but we will not know the cause of the exception if we catched the exception, as they are allArgumentException
s, thus we are not able to have an exact rpcserver response code.Fixes #
Type of change
How Has This Been Tested?
Existing tests that are related to the walletexception are updated accordingly.
Test Configuration:
Checklist: