mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-05-29 18:26:41 +00:00

* [NOD-375] Move to pkg/errors * [NOD-375] Fix tests * [NOD-375] Make AreErrorsEqual a shared function
46 lines
1.1 KiB
Go
46 lines
1.1 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 txgenClient struct {
|
|
*rpcclient.Client
|
|
onBlockAdded chan *blockAddedMsg
|
|
}
|
|
|
|
type blockAddedMsg struct {
|
|
chainHeight uint64
|
|
header *wire.BlockHeader
|
|
txs []*util.Tx
|
|
}
|
|
|
|
func newTxgenClient(connCfg *rpcclient.ConnConfig) (*txgenClient, error) {
|
|
client := &txgenClient{
|
|
onBlockAdded: make(chan *blockAddedMsg),
|
|
}
|
|
notificationHandlers := &rpcclient.NotificationHandlers{
|
|
OnFilteredBlockAdded: func(height uint64, header *wire.BlockHeader,
|
|
txs []*util.Tx) {
|
|
client.onBlockAdded <- &blockAddedMsg{
|
|
chainHeight: height,
|
|
header: header,
|
|
txs: txs,
|
|
}
|
|
},
|
|
}
|
|
var err error
|
|
client.Client, err = rpcclient.New(connCfg, notificationHandlers)
|
|
if err != nil {
|
|
return nil, errors.Errorf("Error connecting to address %s: %s", connCfg.Host, 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
|
|
}
|