kaspad/cmd/zoomyminer/templatemanager/templatemanager.go
Lazzeruz 9b722b8669 More changes yay
Renamed a bunch of stuff to the right Github. Hope it works.
2023-12-09 21:18:29 +01:00

48 lines
1.4 KiB
Go

package templatemanager
import (
<<<<<<< Updated upstream:cmd/kaspaminer/templatemanager/templatemanager.go
"github.com/zoomy-network/zoomyd/app/appmessage"
"github.com/zoomy-network/zoomyd/domain/consensus/model/externalapi"
"github.com/zoomy-network/zoomyd/domain/consensus/utils/pow"
=======
>>>>>>> Stashed changes:cmd/zoomyminer/templatemanager/templatemanager.go
"sync"
"github.com/zoomy-network/zoomyd/app/appmessage"
"github.com/zoomy-network/zoomyd/domain/consensus/model/externalapi"
"github.com/zoomy-network/zoomyd/domain/consensus/utils/pow"
)
var currentTemplate *externalapi.DomainBlock
var currentState *pow.State
var isSynced bool
var lock = &sync.Mutex{}
// Get returns the template to work on
func Get() (*externalapi.DomainBlock, *pow.State, bool) {
lock.Lock()
defer lock.Unlock()
// Shallow copy the block so when the user replaces the header it won't affect the template here.
if currentTemplate == nil {
return nil, nil, false
}
block := *currentTemplate
state := *currentState
return &block, &state, isSynced
}
// Set sets the current template to work on
func Set(template *appmessage.GetBlockTemplateResponseMessage) error {
block, err := appmessage.RPCBlockToDomainBlock(template.Block)
if err != nil {
return err
}
lock.Lock()
defer lock.Unlock()
currentTemplate = block
currentState = pow.NewState(block.Header.ToMutable())
isSynced = template.IsSynced
return nil
}