mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-27 03:58:06 +00:00
Merge pull request #684 from nspcc-dev/feature/getblocksysfee
rpc: implement getblocksysfee RPC
This commit is contained in:
commit
5d4dfbfa1a
4 changed files with 70 additions and 1 deletions
|
@ -42,7 +42,7 @@ which would yield the response:
|
|||
| `getblock` | Yes |
|
||||
| `getblockcount` | Yes |
|
||||
| `getblockhash` | Yes |
|
||||
| `getblocksysfee` | No (#341) |
|
||||
| `getblocksysfee` | Yes |
|
||||
| `getconnectioncount` | Yes |
|
||||
| `getcontractstate` | Yes |
|
||||
| `getnep5balances` | No (#498) |
|
||||
|
|
|
@ -36,6 +36,14 @@ var (
|
|||
},
|
||||
)
|
||||
|
||||
getblocksysfeeCalled = prometheus.NewCounter(
|
||||
prometheus.CounterOpts{
|
||||
Help: "Number of calls to getblocksysfee rpc endpoint",
|
||||
Name: "getblocksysfee_called",
|
||||
Namespace: "neogo",
|
||||
},
|
||||
)
|
||||
|
||||
getconnectioncountCalled = prometheus.NewCounter(
|
||||
prometheus.CounterOpts{
|
||||
Help: "Number of calls to getconnectioncount rpc endpoint",
|
||||
|
@ -139,6 +147,7 @@ func init() {
|
|||
getbestblockCalled,
|
||||
getblockcountCalled,
|
||||
getblockHashCalled,
|
||||
getblocksysfeeCalled,
|
||||
getconnectioncountCalled,
|
||||
getcontractstateCalled,
|
||||
getversionCalled,
|
||||
|
|
|
@ -181,6 +181,10 @@ Methods:
|
|||
|
||||
results = s.chain.GetHeaderHash(num)
|
||||
|
||||
case "getblocksysfee":
|
||||
getblocksysfeeCalled.Inc()
|
||||
results, resultsErr = s.getBlockSysFee(reqParams)
|
||||
|
||||
case "getconnectioncount":
|
||||
getconnectioncountCalled.Inc()
|
||||
results = s.coreServer.PeerCount()
|
||||
|
@ -430,6 +434,32 @@ func (s *Server) getAccountState(reqParams request.Params, unspents bool) (inter
|
|||
return results, resultsErr
|
||||
}
|
||||
|
||||
// getBlockSysFee returns the system fees of the block, based on the specified index.
|
||||
func (s *Server) getBlockSysFee(reqParams request.Params) (util.Fixed8, error) {
|
||||
param, ok := reqParams.ValueWithType(0, request.NumberT)
|
||||
if !ok {
|
||||
return 0, response.ErrInvalidParams
|
||||
}
|
||||
|
||||
num, err := s.blockHeightFromParam(param)
|
||||
if err != nil {
|
||||
return 0, response.NewRPCError("Invalid height", "", nil)
|
||||
}
|
||||
|
||||
headerHash := s.chain.GetHeaderHash(num)
|
||||
block, err := s.chain.GetBlock(headerHash)
|
||||
if err != nil {
|
||||
return 0, response.NewRPCError(err.Error(), "", nil)
|
||||
}
|
||||
|
||||
var blockSysFee util.Fixed8
|
||||
for _, tx := range block.Transactions {
|
||||
blockSysFee += s.chain.SystemFee(tx)
|
||||
}
|
||||
|
||||
return blockSysFee, nil
|
||||
}
|
||||
|
||||
// invoke implements the `invoke` RPC call.
|
||||
func (s *Server) invoke(reqParams request.Params) (interface{}, error) {
|
||||
scriptHashHex, ok := reqParams.ValueWithType(0, request.StringT)
|
||||
|
|
|
@ -295,6 +295,36 @@ var rpcTestCases = map[string][]rpcTestCase{
|
|||
fail: true,
|
||||
},
|
||||
},
|
||||
"getblocksysfee": {
|
||||
{
|
||||
name: "positive",
|
||||
params: "[1]",
|
||||
result: func(e *executor) interface{} {
|
||||
block, _ := e.chain.GetBlock(e.chain.GetHeaderHash(1))
|
||||
|
||||
var expectedBlockSysFee util.Fixed8
|
||||
for _, tx := range block.Transactions {
|
||||
expectedBlockSysFee += e.chain.SystemFee(tx)
|
||||
}
|
||||
return &expectedBlockSysFee
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "no params",
|
||||
params: `[]`,
|
||||
fail: true,
|
||||
},
|
||||
{
|
||||
name: "string height",
|
||||
params: `["first"]`,
|
||||
fail: true,
|
||||
},
|
||||
{
|
||||
name: "invalid number height",
|
||||
params: `[-2]`,
|
||||
fail: true,
|
||||
},
|
||||
},
|
||||
"getconnectioncount": {
|
||||
{
|
||||
params: "[]",
|
||||
|
|
Loading…
Reference in a new issue