Merge pull request #725 from nspcc-dev/feature/gettransactionheight

rpc: implement gettransactionheight
This commit is contained in:
Roman Khimov 2020-03-05 23:56:02 +03:00 committed by GitHub
commit 66ec5b491f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 58 additions and 1 deletions

View file

@ -53,7 +53,7 @@ which would yield the response:
| `getrawmempool` | Yes |
| `getrawtransaction` | Yes |
| `getstorage` | Yes |
| `gettransactionheight` | No (#713) |
| `gettransactionheight` | Yes |
| `gettxout` | Yes |
| `getunclaimed` | No (#712) |
| `getunspents` | Yes |

View file

@ -147,6 +147,14 @@ var (
},
)
gettransactionheightCalled = prometheus.NewCounter(
prometheus.CounterOpts{
Help: "Number of calls to gettransactionheight rpc endpoint",
Name: "gettransactionheight_called",
Namespace: "neogo",
},
)
gettxoutCalled = prometheus.NewCounter(
prometheus.CounterOpts{
Help: "Number of calls to gettxout rpc endpoint",
@ -206,6 +214,7 @@ func init() {
getassetstateCalled,
getaccountstateCalled,
getunspentsCalled,
gettransactionheightCalled,
gettxoutCalled,
getrawtransactionCalled,
sendrawtransactionCalled,

View file

@ -285,6 +285,10 @@ Methods:
getrawtransactionCalled.Inc()
results, resultsErr = s.getrawtransaction(reqParams)
case "gettransactionheight":
gettransactionheightCalled.Inc()
results, resultsErr = s.getTransactionHeight(reqParams)
case "gettxout":
gettxoutCalled.Inc()
results, resultsErr = s.getTxOut(reqParams)
@ -589,6 +593,25 @@ func (s *Server) getrawtransaction(reqParams request.Params) (interface{}, error
return results, resultsErr
}
func (s *Server) getTransactionHeight(ps request.Params) (interface{}, error) {
p, ok := ps.Value(0)
if !ok {
return nil, response.ErrInvalidParams
}
h, err := p.GetUint256()
if err != nil {
return nil, response.ErrInvalidParams
}
_, height, err := s.chain.GetTransaction(h)
if err != nil {
return nil, response.NewRPCError("unknown transaction", "", nil)
}
return height, nil
}
func (s *Server) getTxOut(ps request.Params) (interface{}, error) {
p, ok := ps.Value(0)
if !ok {

View file

@ -576,6 +576,31 @@ var rpcTestCases = map[string][]rpcTestCase{
fail: true,
},
},
"gettransactionheight": {
{
name: "poositive",
params: `["3fee783413c27849c8ee2656fd757a7483de64f4e78bd7897f30ecdf42ce788b"]`,
result: func(e *executor) interface{} {
h := 202
return &h
},
},
{
name: "no params",
params: `[]`,
fail: true,
},
{
name: "invalid hash",
params: `["notahex"]`,
fail: true,
},
{
name: "missing hash",
params: `["` + util.Uint256{}.String() + `"]`,
fail: true,
},
},
"getunspents": {
{
name: "positive",