Skip to content

Commit

Permalink
add getcrossstateroot (#72)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhiqiangxu committed Aug 2, 2021
1 parent a42ecad commit aaa6644
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
4 changes: 4 additions & 0 deletions http/base/actor/ledger.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
20 changes: 20 additions & 0 deletions http/base/rpc/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
1 change: 1 addition & 0 deletions http/jsonrpc/rpc_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit aaa6644

Please sign in to comment.