mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-10-14 00:59:33 +00:00

* [NOD-122] Handle each message in rpcclient with a separate goroutine * [NOD-122] Stop listening to new blocks when not mining * [NOD-122] Made RPC logging in mining simulator more explicit + some styling enhencement
40 lines
1011 B
Go
40 lines
1011 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/daglabs/btcd/rpcclient"
|
|
"github.com/daglabs/btcd/util"
|
|
"github.com/daglabs/btcd/wire"
|
|
)
|
|
|
|
type simulatorClient struct {
|
|
*rpcclient.Client
|
|
onBlockAdded chan struct{}
|
|
notifyForNewBlocks bool
|
|
}
|
|
|
|
func newSimulatorClient(address string, connCfg *rpcclient.ConnConfig) (*simulatorClient, error) {
|
|
client := &simulatorClient{
|
|
onBlockAdded: make(chan struct{}, 1),
|
|
}
|
|
notificationHandlers := &rpcclient.NotificationHandlers{
|
|
OnFilteredBlockAdded: func(height int32, header *wire.BlockHeader,
|
|
txs []*util.Tx) {
|
|
if client.notifyForNewBlocks {
|
|
client.onBlockAdded <- struct{}{}
|
|
}
|
|
},
|
|
}
|
|
var err error
|
|
client.Client, err = rpcclient.New(connCfg, notificationHandlers)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("Error connecting to address %s: %s", address, err)
|
|
}
|
|
|
|
if err = client.NotifyBlocks(); err != nil {
|
|
return nil, fmt.Errorf("Error while registering client %s for block notifications: %s", client.Host(), err)
|
|
}
|
|
return client, nil
|
|
}
|