kaspad/server/rpc/handle_notify_new_transactions.go
Svarog 369ec449a8 [NOD-509] Change organization name to kaspanet (#524)
* [NOD-509] Change organization name to kaspanet

* [NOD-509] Reorganize imports
2019-12-08 17:33:42 +02:00

64 lines
1.9 KiB
Go

package rpc
import (
"github.com/kaspanet/kaspad/btcjson"
"github.com/kaspanet/kaspad/util/subnetworkid"
)
// handleNotifyNewTransations implements the notifyNewTransactions command
// extension for websocket connections.
func handleNotifyNewTransactions(wsc *wsClient, icmd interface{}) (interface{}, error) {
cmd, ok := icmd.(*btcjson.NotifyNewTransactionsCmd)
if !ok {
return nil, btcjson.ErrRPCInternal
}
isVerbose := cmd.Verbose != nil && *cmd.Verbose
if isVerbose == false && cmd.Subnetwork != nil {
return nil, &btcjson.RPCError{
Code: btcjson.ErrRPCInvalidParameter,
Message: "Subnetwork switch is only allowed if verbose=true",
}
}
var subnetworkID *subnetworkid.SubnetworkID
if cmd.Subnetwork != nil {
var err error
subnetworkID, err = subnetworkid.NewFromStr(*cmd.Subnetwork)
if err != nil {
return nil, &btcjson.RPCError{
Code: btcjson.ErrRPCInvalidParameter,
Message: "Subnetwork is malformed",
}
}
}
if isVerbose {
nodeSubnetworkID := wsc.server.cfg.DAG.SubnetworkID()
if nodeSubnetworkID.IsEqual(subnetworkid.SubnetworkIDNative) && subnetworkID != nil {
return nil, &btcjson.RPCError{
Code: btcjson.ErrRPCInvalidParameter,
Message: "Subnetwork switch is disabled when node is in Native subnetwork",
}
} else if nodeSubnetworkID != nil {
if subnetworkID == nil {
return nil, &btcjson.RPCError{
Code: btcjson.ErrRPCInvalidParameter,
Message: "Subnetwork switch is required when node is partial",
}
}
if !nodeSubnetworkID.IsEqual(subnetworkID) {
return nil, &btcjson.RPCError{
Code: btcjson.ErrRPCInvalidParameter,
Message: "Subnetwork must equal the node's subnetwork when the node is partial",
}
}
}
}
wsc.verboseTxUpdates = isVerbose
wsc.subnetworkIDForTxUpdates = subnetworkID
wsc.server.ntfnMgr.RegisterNewMempoolTxsUpdates(wsc)
return nil, nil
}