kaspad/cmd/txgen/client.go
Ori Newman 6250342b86 [NOD-205] Reimplement txgen (#320)
* [NOD-205] Reimplement txgen

* [NOD-205] remove prev outpoints of all initial transactions

* [NOD-205] break txloop to smaller functions

* [NOD-205] Limit collectTransactions iterations

* [NOD-205] Use requiredConfirmations constant instead of inline number

* [NOD-205] Rename wTx -> walletTx

* [NOD-205] Remove handleNewBlock

* [NOD-205] Fix search and replace error
2019-06-04 18:06:35 +03:00

47 lines
1.1 KiB
Go

package main
import (
"fmt"
"github.com/daglabs/btcd/rpcclient"
"github.com/daglabs/btcd/util"
"github.com/daglabs/btcd/wire"
)
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, fmt.Errorf("Error connecting to address %s: %s", connCfg.Host, 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
}