forked from TrueCloudLab/neoneo-go
rpc: drop getclaimable RPC call support
It's not present in NEO 3 and it's not needed there.
This commit is contained in:
parent
d496cc9687
commit
670396b908
7 changed files with 0 additions and 163 deletions
|
@ -43,7 +43,6 @@ which would yield the response:
|
||||||
| `getblockhash` |
|
| `getblockhash` |
|
||||||
| `getblockheader` |
|
| `getblockheader` |
|
||||||
| `getblocksysfee` |
|
| `getblocksysfee` |
|
||||||
| `getclaimable` |
|
|
||||||
| `getconnectioncount` |
|
| `getconnectioncount` |
|
||||||
| `getcontractstate` |
|
| `getcontractstate` |
|
||||||
| `getnep5balances` |
|
| `getnep5balances` |
|
||||||
|
|
|
@ -27,7 +27,6 @@ Supported methods
|
||||||
getblockhash
|
getblockhash
|
||||||
getblockheader
|
getblockheader
|
||||||
getblocksysfee
|
getblocksysfee
|
||||||
getclaimable
|
|
||||||
getconnectioncount
|
getconnectioncount
|
||||||
getcontractstate
|
getcontractstate
|
||||||
getnep5balances
|
getnep5balances
|
||||||
|
|
|
@ -187,16 +187,6 @@ func (c *Client) GetBlockSysFee(index uint32) (util.Fixed8, error) {
|
||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetClaimable returns tx outputs which can be claimed.
|
|
||||||
func (c *Client) GetClaimable(address string) (*result.ClaimableInfo, error) {
|
|
||||||
params := request.NewRawParams(address)
|
|
||||||
resp := new(result.ClaimableInfo)
|
|
||||||
if err := c.performRequest("getclaimable", params, resp); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return resp, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetConnectionCount returns the current number of connections for the node.
|
// GetConnectionCount returns the current number of connections for the node.
|
||||||
func (c *Client) GetConnectionCount() (int, error) {
|
func (c *Client) GetConnectionCount() (int, error) {
|
||||||
var (
|
var (
|
||||||
|
|
|
@ -399,36 +399,6 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"getclaimable": {
|
|
||||||
{
|
|
||||||
name: "positive",
|
|
||||||
invoke: func(c *Client) (interface{}, error) {
|
|
||||||
return c.GetClaimable("AGofsxAUDwt52KjaB664GYsqVAkULYvKNt")
|
|
||||||
},
|
|
||||||
serverResponse: `{"jsonrpc":"2.0","id":1,"result":{"claimable":[{"txid":"52ba70ef18e879785572c917795cd81422c3820b8cf44c24846a30ee7376fd77","n":1,"value":800000,"start_height":476496,"end_height":488154,"generated":746.112,"sys_fee": 3.92,"unclaimed":750.032}],"address":"AGofsxAUDwt52KjaB664GYsqVAkULYvKNt","unclaimed": 750.032}}`,
|
|
||||||
result: func(c *Client) interface{} {
|
|
||||||
txID, err := util.Uint256DecodeStringLE("52ba70ef18e879785572c917795cd81422c3820b8cf44c24846a30ee7376fd77")
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
return &result.ClaimableInfo{
|
|
||||||
Spents: []result.Claimable{
|
|
||||||
{
|
|
||||||
Tx: txID,
|
|
||||||
N: 1,
|
|
||||||
Value: util.Fixed8FromInt64(800000),
|
|
||||||
StartHeight: 476496,
|
|
||||||
EndHeight: 488154,
|
|
||||||
Generated: util.Fixed8FromFloat(746.112),
|
|
||||||
SysFee: util.Fixed8FromFloat(3.92),
|
|
||||||
Unclaimed: util.Fixed8FromFloat(750.032),
|
|
||||||
}},
|
|
||||||
Address: "AGofsxAUDwt52KjaB664GYsqVAkULYvKNt",
|
|
||||||
Unclaimed: util.Fixed8FromFloat(750.032),
|
|
||||||
}
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
"getconnectioncount": {
|
"getconnectioncount": {
|
||||||
{
|
{
|
||||||
name: "positive",
|
name: "positive",
|
||||||
|
@ -1087,12 +1057,6 @@ var rpcClientErrorCases = map[string][]rpcClientErrorCase{
|
||||||
return c.GetBlockSysFee(1)
|
return c.GetBlockSysFee(1)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
|
||||||
name: "getclaimable_invalid_params_error",
|
|
||||||
invoke: func(c *Client) (interface{}, error) {
|
|
||||||
return c.GetClaimable("")
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
name: "getconnectioncount_invalid_params_error",
|
name: "getconnectioncount_invalid_params_error",
|
||||||
invoke: func(c *Client) (interface{}, error) {
|
invoke: func(c *Client) (interface{}, error) {
|
||||||
|
@ -1269,12 +1233,6 @@ var rpcClientErrorCases = map[string][]rpcClientErrorCase{
|
||||||
return c.GetBlockSysFee(1)
|
return c.GetBlockSysFee(1)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
|
||||||
name: "getclaimable_unmarshalling_error",
|
|
||||||
invoke: func(c *Client) (interface{}, error) {
|
|
||||||
return c.GetClaimable("")
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
name: "getconnectioncount_unmarshalling_error",
|
name: "getconnectioncount_unmarshalling_error",
|
||||||
invoke: func(c *Client) (interface{}, error) {
|
invoke: func(c *Client) (interface{}, error) {
|
||||||
|
|
|
@ -1,22 +0,0 @@
|
||||||
package result
|
|
||||||
|
|
||||||
import "github.com/nspcc-dev/neo-go/pkg/util"
|
|
||||||
|
|
||||||
// ClaimableInfo is a result of a getclaimable RPC call.
|
|
||||||
type ClaimableInfo struct {
|
|
||||||
Spents []Claimable `json:"claimable"`
|
|
||||||
Address string `json:"address"`
|
|
||||||
Unclaimed util.Fixed8 `json:"unclaimed"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Claimable represents spent outputs which can be claimed.
|
|
||||||
type Claimable struct {
|
|
||||||
Tx util.Uint256 `json:"txid"`
|
|
||||||
N int `json:"n"`
|
|
||||||
Value util.Fixed8 `json:"value"`
|
|
||||||
StartHeight uint32 `json:"start_height"`
|
|
||||||
EndHeight uint32 `json:"end_height"`
|
|
||||||
Generated util.Fixed8 `json:"generated"`
|
|
||||||
SysFee util.Fixed8 `json:"sys_fee"`
|
|
||||||
Unclaimed util.Fixed8 `json:"unclaimed"`
|
|
||||||
}
|
|
|
@ -88,7 +88,6 @@ var rpcHandlers = map[string]func(*Server, request.Params) (interface{}, *respon
|
||||||
"getblockhash": (*Server).getBlockHash,
|
"getblockhash": (*Server).getBlockHash,
|
||||||
"getblockheader": (*Server).getBlockHeader,
|
"getblockheader": (*Server).getBlockHeader,
|
||||||
"getblocksysfee": (*Server).getBlockSysFee,
|
"getblocksysfee": (*Server).getBlockSysFee,
|
||||||
"getclaimable": (*Server).getClaimable,
|
|
||||||
"getconnectioncount": (*Server).getConnectionCount,
|
"getconnectioncount": (*Server).getConnectionCount,
|
||||||
"getcontractstate": (*Server).getContractState,
|
"getcontractstate": (*Server).getContractState,
|
||||||
"getnep5balances": (*Server).getNEP5Balances,
|
"getnep5balances": (*Server).getNEP5Balances,
|
||||||
|
@ -522,58 +521,6 @@ func (s *Server) getApplicationLog(reqParams request.Params) (interface{}, *resp
|
||||||
return result.NewApplicationLog(appExecResult, scriptHash), nil
|
return result.NewApplicationLog(appExecResult, scriptHash), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) getClaimable(ps request.Params) (interface{}, *response.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
|
|
||||||
}
|
|
||||||
|
|
||||||
var unclaimed []state.UnclaimedBalance
|
|
||||||
if acc := s.chain.GetAccountState(u); acc != nil {
|
|
||||||
err := acc.Unclaimed.ForEach(func(b *state.UnclaimedBalance) error {
|
|
||||||
unclaimed = append(unclaimed, *b)
|
|
||||||
return nil
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return nil, response.NewInternalServerError("Unclaimed processing failure", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var sum util.Fixed8
|
|
||||||
claimable := make([]result.Claimable, 0, len(unclaimed))
|
|
||||||
for _, ub := range unclaimed {
|
|
||||||
gen, sys, err := s.chain.CalculateClaimable(ub.Value, ub.Start, ub.End)
|
|
||||||
if err != nil {
|
|
||||||
s.log.Info("error while calculating claim bonus", zap.Error(err))
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
uc := gen.Add(sys)
|
|
||||||
sum += uc
|
|
||||||
|
|
||||||
claimable = append(claimable, result.Claimable{
|
|
||||||
Tx: ub.Tx,
|
|
||||||
N: int(ub.Index),
|
|
||||||
Value: ub.Value,
|
|
||||||
StartHeight: ub.Start,
|
|
||||||
EndHeight: ub.End,
|
|
||||||
Generated: gen,
|
|
||||||
SysFee: sys,
|
|
||||||
Unclaimed: uc,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
return result.ClaimableInfo{
|
|
||||||
Spents: claimable,
|
|
||||||
Address: p.String(),
|
|
||||||
Unclaimed: sum,
|
|
||||||
}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *Server) getNEP5Balances(ps request.Params) (interface{}, *response.Error) {
|
func (s *Server) getNEP5Balances(ps request.Params) (interface{}, *response.Error) {
|
||||||
p, ok := ps.ValueWithType(0, request.StringT)
|
p, ok := ps.ValueWithType(0, request.StringT)
|
||||||
if !ok {
|
if !ok {
|
||||||
|
|
|
@ -504,40 +504,6 @@ var rpcTestCases = map[string][]rpcTestCase{
|
||||||
fail: true,
|
fail: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"getclaimable": {
|
|
||||||
{
|
|
||||||
name: "no params",
|
|
||||||
params: "[]",
|
|
||||||
fail: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "invalid address",
|
|
||||||
params: `["invalid"]`,
|
|
||||||
fail: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "normal address",
|
|
||||||
params: `["` + testchain.MultisigAddress() + `"]`,
|
|
||||||
result: func(*executor) interface{} {
|
|
||||||
// hash of the issueTx
|
|
||||||
h, _ := util.Uint256DecodeStringBE("d3a4f2249fe33b18bde73901c1ecc66200485f1c1dcd941b406a630b479090ae")
|
|
||||||
amount := util.Fixed8FromInt64(1 * 8) // (endHeight - startHeight) * genAmount[0]
|
|
||||||
return &result.ClaimableInfo{
|
|
||||||
Spents: []result.Claimable{
|
|
||||||
{
|
|
||||||
Tx: h,
|
|
||||||
Value: util.Fixed8FromInt64(100000000),
|
|
||||||
EndHeight: 1,
|
|
||||||
Generated: amount,
|
|
||||||
Unclaimed: amount,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
Address: testchain.MultisigAddress(),
|
|
||||||
Unclaimed: amount,
|
|
||||||
}
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
"getconnectioncount": {
|
"getconnectioncount": {
|
||||||
{
|
{
|
||||||
params: "[]",
|
params: "[]",
|
||||||
|
|
Loading…
Reference in a new issue