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

InvokeScript RpcClient sending Base64 but RpcServer expecting Hex #385

Closed
devhawk opened this issue Nov 4, 2020 · 3 comments · Fixed by #386
Closed

InvokeScript RpcClient sending Base64 but RpcServer expecting Hex #385

devhawk opened this issue Nov 4, 2020 · 3 comments · Fixed by #386

Comments

@devhawk
Copy link
Contributor

devhawk commented Nov 4, 2020

Describe the bug
Script format mismatch between RpcClient and RpcServer

I believe this is a MUST FIX for preview 4

RpcClient passes script parameter as string after calling Convert.ToBase64String(script)

public async Task<RpcInvokeResult> InvokeScriptAsync(byte[] script, params Signer[] signers)
{
    List<JObject> parameters = new List<JObject> { Convert.ToBase64String(script) };
    if (signers.Length > 0)
    {
        parameters.Add(signers.Select(p => p.ToJson()).ToArray());
    }
    var result = await RpcSendAsync(GetRpcName(), parameters.ToArray()).ConfigureAwait(false);
    return RpcInvokeResult.FromJson(result);
}

RpcServer attempts to parse the script parameter via HexToBytes

[RpcMethod]
protected virtual JObject InvokeScript(JArray _params)
{
    byte[] script = _params[0].AsString().HexToBytes();
    Signers signers = _params.Count >= 2 ? SignersFromJson((JArray)_params[1]) : null;
    return GetInvokeResult(script, signers);
}
@roman-khimov
Copy link
Contributor

RpcServer was converted to using base64 in #362, but then it looks like the old code was partially reintroduced with #368. What's really weird is that this wasn't caught by any unit test.

@devhawk
Copy link
Contributor Author

devhawk commented Nov 4, 2020

I confirmed that changing the first line of RpcServer InvokeScript to byte[] script = Convert.FromBase64String(_params[0].AsString()); solves the issue

devhawk pushed a commit to neo-project/neo-express that referenced this issue Nov 4, 2020
djnicholson pushed a commit to neo-project/neo-express that referenced this issue Nov 4, 2020
* compile against master

* ApplicationEngine.Log Event

* save appexec notifications in own storage table

* Nep5 RPC methods

* use neo core binary serializer for stack items

* cmd type visibility

* export + wallet export commands

* wallet delete command

* show applog as part of show tx

* show balances command

* write error messages to stderr

* ExpressGetPopulatedBlocks

* update packages

* adapt for neo3 notification structure

* show balance/balances command

* fix bugs

* update rpcserver package to fix neo-project/neo-modules#385

Co-authored-by: Harry <[email protected]>
@superboyiii
Copy link
Member

superboyiii commented Nov 5, 2020

I confirmed that changing the first line of RpcServer InvokeScript to byte[] script = Convert.FromBase64String(_params[0].AsString()); solves the issue

Fixed in #386. Please have a review.

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

Successfully merging a pull request may close this issue.

3 participants