parent
aab7dd515f
commit
c23a522d25
5 changed files with 139 additions and 33 deletions
|
@ -178,6 +178,14 @@ var (
|
|||
},
|
||||
)
|
||||
|
||||
getunclaimedCalled = prometheus.NewCounter(
|
||||
prometheus.CounterOpts{
|
||||
Help: "Number of calls to getunclaimed rpc endpoint",
|
||||
Name: "getunclaimed_called",
|
||||
Namespace: "neogo",
|
||||
},
|
||||
)
|
||||
|
||||
getunspentsCalled = prometheus.NewCounter(
|
||||
prometheus.CounterOpts{
|
||||
Help: "Number of calls to getunspents rpc endpoint",
|
||||
|
@ -229,6 +237,7 @@ func init() {
|
|||
validateaddressCalled,
|
||||
getassetstateCalled,
|
||||
getaccountstateCalled,
|
||||
getunclaimedCalled,
|
||||
getunspentsCalled,
|
||||
gettransactionheightCalled,
|
||||
gettxoutCalled,
|
||||
|
|
|
@ -298,6 +298,10 @@ Methods:
|
|||
gettxoutCalled.Inc()
|
||||
results, resultsErr = s.getTxOut(reqParams)
|
||||
|
||||
case "getunclaimed":
|
||||
getunclaimedCalled.Inc()
|
||||
results, resultsErr = s.getUnclaimed(reqParams)
|
||||
|
||||
case "getunspents":
|
||||
getunspentsCalled.Inc()
|
||||
results, resultsErr = s.getAccountState(reqParams, true)
|
||||
|
@ -768,6 +772,25 @@ func (s *Server) getBlockHeader(reqParams request.Params) (interface{}, error) {
|
|||
return hex.EncodeToString(buf.Bytes()), nil
|
||||
}
|
||||
|
||||
// getUnclaimed returns unclaimed GAS amount of the specified address.
|
||||
func (s *Server) getUnclaimed(ps request.Params) (interface{}, error) {
|
||||
p, ok := ps.ValueWithType(0, request.StringT)
|
||||
if !ok {
|
||||
return nil, response.ErrInvalidParams
|
||||
}
|
||||
u, err := p.GetUint160FromAddress()
|
||||
if err != nil {
|
||||
return nil, response.ErrInvalidParams
|
||||
}
|
||||
|
||||
acc := s.chain.GetAccountState(u)
|
||||
if acc == nil {
|
||||
return nil, response.NewInternalServerError("unknown account", nil)
|
||||
}
|
||||
|
||||
return result.NewUnclaimed(acc, s.chain)
|
||||
}
|
||||
|
||||
// getValidators returns the current NEO consensus nodes information and voting status.
|
||||
func (s *Server) getValidators() (interface{}, error) {
|
||||
var validators keys.PublicKeys
|
||||
|
|
|
@ -601,6 +601,32 @@ var rpcTestCases = map[string][]rpcTestCase{
|
|||
fail: true,
|
||||
},
|
||||
},
|
||||
"getunclaimed": {
|
||||
{
|
||||
name: "no params",
|
||||
params: "[]",
|
||||
fail: true,
|
||||
},
|
||||
{
|
||||
name: "invalid address",
|
||||
params: `["invalid"]`,
|
||||
fail: true,
|
||||
},
|
||||
{
|
||||
name: "positive",
|
||||
params: `["AZ81H31DMWzbSnFDLFkzh9vHwaDLayV7fU"]`,
|
||||
result: func(*executor) interface{} {
|
||||
return &result.Unclaimed{}
|
||||
},
|
||||
check: func(t *testing.T, e *executor, uncl interface{}) {
|
||||
res, ok := uncl.(*result.Unclaimed)
|
||||
require.True(t, ok)
|
||||
assert.Equal(t, res.Available, util.Fixed8FromInt64(8))
|
||||
assert.True(t, res.Unavailable > 0)
|
||||
assert.Equal(t, res.Available + res.Unavailable, res.Unclaimed)
|
||||
},
|
||||
},
|
||||
},
|
||||
"getunspents": {
|
||||
{
|
||||
name: "positive",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue