mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-05-30 02:36:42 +00:00

* Replace BlockMessage with RpcBlock in rpc.proto. * Convert everything in kaspad to use RPCBlocks and fix tests. * Fix compilation errors in stability tests and the miner. * Update TransactionVerboseData in rpc.proto. * Update TransactionVerboseData in the rest of kaspad. * Make golint happy. * Include RpcTransactionVerboseData in RpcTransaction instead of the other way around. * Regenerate rpc.pb.go after merge. * Update appmessage types. * Update appmessage request and response types. * Reimplement conversion functions between appmessage.RPCTransaction and protowire.RpcTransaction. * Extract RpcBlockHeader toAppMessage/fromAppMessage out of RpcBlock. * Fix compilation errors in getBlock, getBlocks, and submitBlock. * Fix compilation errors in getMempoolEntry. * Fix compilation errors in notifyBlockAdded. * Update verbosedata.go. * Fix compilation errors in getBlock and getBlocks. * Fix compilation errors in getBlocks tests. * Fix conversions between getBlocks message types. * Fix integration tests. * Fix a comment. * Add selectedParent to the verbose block response.
37 lines
884 B
Go
37 lines
884 B
Go
package templatemanager
|
|
|
|
import (
|
|
"github.com/kaspanet/kaspad/app/appmessage"
|
|
"github.com/kaspanet/kaspad/domain/consensus/model/externalapi"
|
|
"sync"
|
|
)
|
|
|
|
var currentTemplate *externalapi.DomainBlock
|
|
var isSynced bool
|
|
var lock = &sync.Mutex{}
|
|
|
|
// Get returns the template to work on
|
|
func Get() (*externalapi.DomainBlock, 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, false
|
|
}
|
|
block := *currentTemplate
|
|
return &block, 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
|
|
isSynced = template.IsSynced
|
|
return nil
|
|
}
|