mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2025-05-03 11:41:48 +00:00
rpc: implement verifyproof RPC
Test getproof and verifyproof together.
This commit is contained in:
parent
e38e8aa48a
commit
8e60a65b55
4 changed files with 108 additions and 0 deletions
|
@ -20,6 +20,7 @@ import (
|
|||
"github.com/nspcc-dev/neo-go/pkg/core"
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/block"
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/blockchainer"
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/mpt"
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/state"
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
||||
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
||||
|
@ -114,6 +115,7 @@ var rpcHandlers = map[string]func(*Server, request.Params) (interface{}, *respon
|
|||
"sendrawtransaction": (*Server).sendrawtransaction,
|
||||
"submitblock": (*Server).submitBlock,
|
||||
"validateaddress": (*Server).validateAddress,
|
||||
"verifyproof": (*Server).verifyProof,
|
||||
}
|
||||
|
||||
var rpcWsHandlers = map[string]func(*Server, request.Params, *subscriber) (interface{}, *response.Error){
|
||||
|
@ -817,6 +819,36 @@ func (s *Server) getProof(ps request.Params) (interface{}, *response.Error) {
|
|||
}, nil
|
||||
}
|
||||
|
||||
func (s *Server) verifyProof(ps request.Params) (interface{}, *response.Error) {
|
||||
if s.chain.GetConfig().KeepOnlyLatestState {
|
||||
return nil, response.NewInvalidRequestError("'verifyproof' is not supported", errKeepOnlyLatestState)
|
||||
}
|
||||
root, err := ps.Value(0).GetUint256()
|
||||
if err != nil {
|
||||
return nil, response.ErrInvalidParams
|
||||
}
|
||||
proofStr, err := ps.Value(1).GetString()
|
||||
if err != nil {
|
||||
return nil, response.ErrInvalidParams
|
||||
}
|
||||
var p result.ProofWithKey
|
||||
if err := p.FromString(proofStr); err != nil {
|
||||
return nil, response.ErrInvalidParams
|
||||
}
|
||||
vp := new(result.VerifyProof)
|
||||
val, ok := mpt.VerifyProof(root, p.Key, p.Proof)
|
||||
if ok {
|
||||
var si state.StorageItem
|
||||
r := io.NewBinReaderFromBuf(val)
|
||||
si.DecodeBinary(r)
|
||||
if r.Err != nil {
|
||||
return nil, response.NewInternalServerError("invalid item in trie", r.Err)
|
||||
}
|
||||
vp.Value = si.Value
|
||||
}
|
||||
return vp, nil
|
||||
}
|
||||
|
||||
func (s *Server) getStateHeight(_ request.Params) (interface{}, *response.Error) {
|
||||
var height = s.chain.BlockHeight()
|
||||
var stateHeight uint32
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue