rpc/client: support getproof RPC

This commit is contained in:
Evgenii Stratonikov 2020-06-25 15:52:51 +03:00
parent d8dddabc86
commit 654877fb1b
2 changed files with 33 additions and 0 deletions

View file

@ -635,6 +635,26 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{
},
},
},
"getproof": {
{
name: "positive",
serverResponse: `{"id":1,"jsonrpc":"2.0","result":{"proof":"256f20ccfbd5f01d5b9633387428b8bab95a9e78c2746573746b657900000000000000000009026d014a060f02000c0c0f0b0d050f00010d050b090603030308070402080b080b0a0b09050a090e07080c020704060507030704060b0605070900000000000000000000000000000000000000092068ae9a1a2c6b6b64216df47b4c44086141569d5d20dc9bd65fdfabed54d2c3250e030c00097465737476616c756500","success":true}}`,
invoke: func(c *Client) (interface{}, error) {
return c.GetProof(util.Uint256{}, util.Uint160{}, []byte{})
},
result: func(c *Client) interface{} {
var p result.ProofWithKey
err := p.FromString("256f20ccfbd5f01d5b9633387428b8bab95a9e78c2746573746b657900000000000000000009026d014a060f02000c0c0f0b0d050f00010d050b090603030308070402080b080b0a0b09050a090e07080c020704060507030704060b0605070900000000000000000000000000000000000000092068ae9a1a2c6b6b64216df47b4c44086141569d5d20dc9bd65fdfabed54d2c3250e030c00097465737476616c756500")
if err != nil {
panic(err)
}
return &result.GetProof{
Result: p,
Success: true,
}
},
},
},
"getstateroot": {
{
name: "positive",

View file

@ -1,6 +1,8 @@
package client
import (
"encoding/hex"
"github.com/nspcc-dev/neo-go/pkg/core/state"
"github.com/nspcc-dev/neo-go/pkg/rpc/request"
"github.com/nspcc-dev/neo-go/pkg/rpc/response/result"
@ -35,3 +37,14 @@ func (c *Client) GetStateHeight() (*result.StateHeight, error) {
}
return resp, nil
}
// GetProof returns proof that key belongs to a contract sc state rooted at root.
func (c *Client) GetProof(root util.Uint256, sc util.Uint160, key []byte) (*result.GetProof, error) {
var resp result.GetProof
ps := request.NewRawParams(root, sc, hex.EncodeToString(key))
err := c.performRequest("getproof", ps, &resp)
if err != nil {
return nil, err
}
return &resp, nil
}