kaspad/server/rpc/handle_get_subnetwork.go
Svarog 6b5b4bfb2a
[NOD-1164] Remove the singleton from dbaccess, to enable multiple db connections in same run (#806)
* [NOD-1164] Defined DatabaseContext as the basic object of dbaccess

* [NOD-1164] Update everything to use databaseContext

* [NOD-1164] Fix tests

* [NOD-1164] Add comments

* [NOD-1164] Removed databaseContext from blockNode

* [NOD-1164] Enforce DatabaseContext != nil

* [NOD-1164] Remove redundant and wrong comment line
2020-07-21 12:02:44 +03:00

35 lines
886 B
Go

package rpc
import (
"github.com/kaspanet/kaspad/rpcmodel"
"github.com/kaspanet/kaspad/util/subnetworkid"
)
// handleGetSubnetwork handles the getSubnetwork command.
func handleGetSubnetwork(s *Server, cmd interface{}, closeChan <-chan struct{}) (interface{}, error) {
c := cmd.(*rpcmodel.GetSubnetworkCmd)
subnetworkID, err := subnetworkid.NewFromStr(c.SubnetworkID)
if err != nil {
return nil, rpcDecodeHexError(c.SubnetworkID)
}
var gasLimit *uint64
if !subnetworkID.IsEqual(subnetworkid.SubnetworkIDNative) &&
!subnetworkID.IsBuiltIn() {
limit, err := s.cfg.DAG.GasLimit(subnetworkID)
if err != nil {
return nil, &rpcmodel.RPCError{
Code: rpcmodel.ErrRPCSubnetworkNotFound,
Message: "Subnetwork not found.",
}
}
gasLimit = &limit
}
subnetworkReply := &rpcmodel.GetSubnetworkResult{
GasLimit: gasLimit,
}
return subnetworkReply, nil
}