mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-06-14 18:16:43 +00:00

* [NOD-375] Move to pkg/errors * [NOD-375] Fix tests * [NOD-375] Make AreErrorsEqual a shared function
39 lines
1.0 KiB
Go
39 lines
1.0 KiB
Go
package main
|
|
|
|
import (
|
|
"github.com/daglabs/btcd/rpcclient"
|
|
"github.com/daglabs/btcd/util"
|
|
"github.com/daglabs/btcd/wire"
|
|
"github.com/pkg/errors"
|
|
)
|
|
|
|
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 uint64, 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, errors.Errorf("Error connecting to address %s: %s", address, err)
|
|
}
|
|
|
|
if err = client.NotifyBlocks(); err != nil {
|
|
return nil, errors.Errorf("Error while registering client %s for block notifications: %s", client.Host(), err)
|
|
}
|
|
return client, nil
|
|
}
|