[lbry] rpc, mining: fix generatetoaddress

This commit is contained in:
Roy Lee 2021-08-19 16:39:53 -04:00
parent 9ae7b95c85
commit 96846fef20
2 changed files with 6 additions and 4 deletions

View file

@ -274,7 +274,7 @@ func (m *CPUMiner) solveBlock(msgBlock *wire.MsgBlock, blockHeight int32,
// increment the number of hashes completed for each // increment the number of hashes completed for each
// attempt accordingly. // attempt accordingly.
header.Nonce = i header.Nonce = i
hash := header.BlockHash() hash := header.BlockPoWHash()
hashesCompleted += 2 hashesCompleted += 2
// The block is solved when the new block hash is less // The block is solved when the new block hash is less
@ -544,7 +544,7 @@ func (m *CPUMiner) NumWorkers() int32 {
// detecting when it is performing stale work and reacting accordingly by // detecting when it is performing stale work and reacting accordingly by
// generating a new block template. When a block is solved, it is submitted. // generating a new block template. When a block is solved, it is submitted.
// The function returns a list of the hashes of generated blocks. // The function returns a list of the hashes of generated blocks.
func (m *CPUMiner) GenerateNBlocks(n uint32) ([]*chainhash.Hash, error) { func (m *CPUMiner) GenerateNBlocks(n uint32, payToAddr btcutil.Address) ([]*chainhash.Hash, error) {
m.Lock() m.Lock()
// Respond with an error if server is already mining. // Respond with an error if server is already mining.
@ -590,8 +590,9 @@ func (m *CPUMiner) GenerateNBlocks(n uint32) ([]*chainhash.Hash, error) {
// Choose a payment address at random. // Choose a payment address at random.
rand.Seed(time.Now().UnixNano()) rand.Seed(time.Now().UnixNano())
payToAddr := m.cfg.MiningAddrs[rand.Intn(len(m.cfg.MiningAddrs))] if payToAddr == nil {
payToAddr = m.cfg.MiningAddrs[rand.Intn(len(m.cfg.MiningAddrs))]
}
// Create a new block template using the available transactions // Create a new block template using the available transactions
// in the memory pool as a source of transactions to potentially // in the memory pool as a source of transactions to potentially
// include in the block. // include in the block.

View file

@ -842,6 +842,7 @@ var rpcResultTypes = map[string][]interface{}{
"decodescript": {(*btcjson.DecodeScriptResult)(nil)}, "decodescript": {(*btcjson.DecodeScriptResult)(nil)},
"estimatefee": {(*float64)(nil)}, "estimatefee": {(*float64)(nil)},
"generate": {(*[]string)(nil)}, "generate": {(*[]string)(nil)},
"generatetoaddress": {(*[]string)(nil)},
"getaddednodeinfo": {(*[]string)(nil), (*[]btcjson.GetAddedNodeInfoResult)(nil)}, "getaddednodeinfo": {(*[]string)(nil), (*[]btcjson.GetAddedNodeInfoResult)(nil)},
"getbestblock": {(*btcjson.GetBestBlockResult)(nil)}, "getbestblock": {(*btcjson.GetBestBlockResult)(nil)},
"getbestblockhash": {(*string)(nil)}, "getbestblockhash": {(*string)(nil)},