2018-03-30 06:15:03 +00:00
|
|
|
package wrappers
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/CityOfZion/neo-go/pkg/core"
|
2020-01-14 12:32:07 +00:00
|
|
|
"github.com/CityOfZion/neo-go/pkg/core/block"
|
2018-03-30 06:15:03 +00:00
|
|
|
"github.com/CityOfZion/neo-go/pkg/util"
|
|
|
|
)
|
|
|
|
|
|
|
|
type (
|
|
|
|
// Block wrapper used for the representation of
|
2020-01-14 12:32:07 +00:00
|
|
|
// block.Block / block.BlockBase on the RPC Server.
|
2018-03-30 06:15:03 +00:00
|
|
|
Block struct {
|
2020-01-14 12:32:07 +00:00
|
|
|
*block.Block
|
2018-03-30 06:15:03 +00:00
|
|
|
Confirmations uint32 `json:"confirmations"`
|
|
|
|
NextBlockHash util.Uint256 `json:"nextblockhash,omitempty"`
|
|
|
|
Hash util.Uint256 `json:"hash"`
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
// NewBlock creates a new Block wrapper.
|
2020-01-14 12:32:07 +00:00
|
|
|
func NewBlock(block *block.Block, chain core.Blockchainer) Block {
|
2018-03-30 06:15:03 +00:00
|
|
|
blockWrapper := Block{
|
|
|
|
Block: block,
|
|
|
|
Hash: block.Hash(),
|
|
|
|
}
|
|
|
|
|
|
|
|
hash := chain.GetHeaderHash(int(block.Index) + 1)
|
|
|
|
if !hash.Equals(util.Uint256{}) {
|
|
|
|
blockWrapper.NextBlockHash = hash
|
|
|
|
}
|
|
|
|
|
|
|
|
blockWrapper.Confirmations = chain.BlockHeight() - block.Index - 1
|
|
|
|
return blockWrapper
|
|
|
|
}
|