From aaa66443deb5cad60e8873105c1383d43428da79 Mon Sep 17 00:00:00 2001 From: zhiqiangxu <652732310@qq.com> Date: Mon, 2 Aug 2021 10:52:48 +0800 Subject: [PATCH] add getcrossstateroot (#72) --- http/base/actor/ledger.go | 4 ++++ http/base/rpc/interfaces.go | 20 ++++++++++++++++++++ http/jsonrpc/rpc_server.go | 1 + 3 files changed, 25 insertions(+) diff --git a/http/base/actor/ledger.go b/http/base/actor/ledger.go index 75792f8f9..9b795a029 100644 --- a/http/base/actor/ledger.go +++ b/http/base/actor/ledger.go @@ -105,3 +105,7 @@ func GetMerkleProof(proofHeight uint32, rootHeight uint32) ([]byte, error) { func GetCrossStatesProof(height uint32, key []byte) ([]byte, error) { return ledger.DefLedger.GetCrossStatesProof(height, key) } + +func GetCrossStateRoot(height uint32) (common.Uint256, error) { + return ledger.DefLedger.GetCrossStateRoot(height) +} diff --git a/http/base/rpc/interfaces.go b/http/base/rpc/interfaces.go index 129e02595..ab6793523 100644 --- a/http/base/rpc/interfaces.go +++ b/http/base/rpc/interfaces.go @@ -98,6 +98,26 @@ func GetLatestBlockMsgsSnap(params []interface{}) map[string]interface{} { return responseSuccess(result) } +// get cross state root +func GetCrossStateRoot(params []interface{}) map[string]interface{} { + if len(params) < 1 { + return responsePack(berr.INVALID_PARAMS, nil) + } + switch (params[0]).(type) { + // block height + case float64: + height := uint32(params[0].(float64)) + result, err := bactor.GetCrossStateRoot(height) + if err != nil { + return responsePack(berr.UNKNOWN_BLOCK, err.Error()) + } + return responseSuccess(result) + default: + return responsePack(berr.INVALID_PARAMS, "") + } + +} + //get block hash // A JSON example for getblockhash method as following: // {"jsonrpc": "2.0", "method": "getblockhash", "params": [1], "id": 0} diff --git a/http/jsonrpc/rpc_server.go b/http/jsonrpc/rpc_server.go index c73d45e4a..d4dcd24c7 100644 --- a/http/jsonrpc/rpc_server.go +++ b/http/jsonrpc/rpc_server.go @@ -39,6 +39,7 @@ func StartRPCServer() error { rpc.HandleFunc("getblockcount", rpc.GetBlockCount) rpc.HandleFunc("getblockhash", rpc.GetBlockHash) rpc.HandleFunc("getlatestblockmsgssnap", rpc.GetLatestBlockMsgsSnap) + rpc.HandleFunc("getcrossstateroot", rpc.GetCrossStateRoot) rpc.HandleFunc("getconnectioncount", rpc.GetConnectionCount) //HandleFunc("getrawmempool", GetRawMemPool)