Skip to content
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 Rpc Methods] fix contact rpc methods parameters #3485

Open
wants to merge 12 commits into
base: master
Choose a base branch
from

Conversation

Jim8y
Copy link
Contributor

@Jim8y Jim8y commented Sep 11, 2024

Description

This pr updates the rpc plugin contract related methods.

Fixes # (issue)

Type of change

  • Optimization (the change is only an optimization)
  • Style (the change is only a code style for better maintenance or standard purpose)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

  • TestInvokeFunction
  • TestInvokeScript
  • TestTraverseIterator
  • TestGetUnclaimedGas

Test Configuration:

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

shargon
shargon previously approved these changes Sep 11, 2024
cschuchardt88
cschuchardt88 previously approved these changes Sep 11, 2024
/// This method is used to test your VM script as if they ran on the blockchain at that point in time.
/// This RPC call does not affect the blockchain in any way.
/// </remarks>
/// <param name="scriptHash">Smart contract scripthash. Use big endian for Hash160, little endian for ByteArray.</param>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use big endian for Hash160

It's LE.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not resolved.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you check it again, cause its from the official document.

src/Plugins/RpcServer/ParameterConverter.cs Show resolved Hide resolved
/// <param name="useDiagnostic">Optional. Flag to enable diagnostic information.</param>
/// <returns>A JToken containing the result of the invocation.</returns>
[RpcMethodWithParams]
protected internal virtual JToken InvokeFunction(string scriptHash, string operation, ContractParameter[] args = null, Signer[] signers = null, bool useDiagnostic = false)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This behaviour diverges from an old one. This method should accept the list of signers with witnesses as the fourth parameter, not only the list of signers.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It never worked. And not bing of any use at anywhere.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And not bing of any use at anywhere.

You don't know that. It's an external API and it's a very widely used one. Your changes can easily break real applications. Refactorings must not break compatibility.

src/Plugins/RpcServer/RpcServer.SmartContract.cs Outdated Show resolved Hide resolved
@Jim8y Jim8y dismissed stale reviews from cschuchardt88 and shargon via 656bee9 September 13, 2024 04:04

namespace Neo.Plugins.RpcServer.Model;

public class SignerOrWitness
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not make a base class for common stuff? Than two different classes one, being Signer and other being Witness. This way we can get Signer attributes like Rules or other properties that separate the two classes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make it work first, optimize it later. I think you are better than me to make the code more elegent.

Copy link
Member

@AnnaShaleva AnnaShaleva left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

src/Plugins/RpcServer/Model/SignerOrWitness.cs Outdated Show resolved Hide resolved
src/Plugins/RpcServer/ParameterConverter.cs Show resolved Hide resolved
src/Plugins/RpcServer/ParameterConverter.cs Show resolved Hide resolved
@Jim8y
Copy link
Contributor Author

Jim8y commented Sep 14, 2024

@AnnaShaleva please check latest update to make it SignerWithWitness, @chenzhitong please update the document accordingly, @superboyiii may you please test this pr? expecially the InvokeFunction and InvokeScript that may contain signer and/or witness.

throw new RpcException(CreateInvalidParamError<Signer>(token));
}
}
throw new RpcException(CreateInvalidParamError<Signer>(token));
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would adding an else statement here make it clearer?


namespace Neo.Plugins.RpcServer.Model;

public class SignerWithWitness(Signer? signer, Witness? witness)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to fix the linter comment.

src/Plugins/RpcServer/Model/SignerWithWitness.cs Outdated Show resolved Hide resolved
src/Plugins/RpcServer/Model/SignerWithWitness.cs Outdated Show resolved Hide resolved
}).ToArray();
}

private static UInt160 AddressToScriptHash(string address, byte version)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought we already had this helper somewhere else. If so, can we reuse the existing helper?

src/Plugins/RpcServer/ParameterConverter.cs Outdated Show resolved Hide resolved
return new[] { signerOrWitness };
}
}
throw new RpcException(RpcError.InvalidParams.WithData($"Invalid SignerOrWitness format: {token}"));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto.

src/Plugins/RpcServer/ParameterConverter.cs Show resolved Hide resolved
src/Plugins/RpcServer/ParameterConverter.cs Show resolved Hide resolved
/// This method is used to test your VM script as if they ran on the blockchain at that point in time.
/// This RPC call does not affect the blockchain in any way.
/// </remarks>
/// <param name="scriptHash">Smart contract scripthash. Use big endian for Hash160, little endian for ByteArray.</param>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not resolved.

@Jim8y
Copy link
Contributor Author

Jim8y commented Sep 21, 2024

@AnnaShaleva updated this pr to mock the complete http request process, now should be able to work without miss any detail.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants