2019-11-15 10:32:40 +00:00
|
|
|
package consensus
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/nspcc-dev/dbft/block"
|
|
|
|
"github.com/nspcc-dev/dbft/crypto"
|
2020-03-03 14:21:42 +00:00
|
|
|
coreb "github.com/nspcc-dev/neo-go/pkg/core/block"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
2019-11-15 10:32:40 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// neoBlock is a wrapper of core.Block which implements
|
|
|
|
// methods necessary for dBFT library.
|
|
|
|
type neoBlock struct {
|
2020-01-14 12:32:07 +00:00
|
|
|
coreb.Block
|
2019-11-15 10:32:40 +00:00
|
|
|
|
|
|
|
signature []byte
|
|
|
|
}
|
|
|
|
|
|
|
|
var _ block.Block = (*neoBlock)(nil)
|
|
|
|
|
|
|
|
// Sign implements block.Block interface.
|
|
|
|
func (n *neoBlock) Sign(key crypto.PrivateKey) error {
|
2020-04-13 13:31:04 +00:00
|
|
|
data := n.Base.GetSignedPart()
|
2019-11-15 10:32:40 +00:00
|
|
|
sig, err := key.Sign(data[:])
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
n.signature = sig
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Verify implements block.Block interface.
|
|
|
|
func (n *neoBlock) Verify(key crypto.PublicKey, sign []byte) error {
|
2020-04-13 13:31:04 +00:00
|
|
|
data := n.Base.GetSignedPart()
|
2019-11-15 10:32:40 +00:00
|
|
|
return key.Verify(data, sign)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Transactions implements block.Block interface.
|
|
|
|
func (n *neoBlock) Transactions() []block.Transaction {
|
|
|
|
txes := make([]block.Transaction, len(n.Block.Transactions))
|
|
|
|
for i, tx := range n.Block.Transactions {
|
|
|
|
txes[i] = tx
|
|
|
|
}
|
|
|
|
|
|
|
|
return txes
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetTransactions implements block.Block interface.
|
|
|
|
func (n *neoBlock) SetTransactions(txes []block.Transaction) {
|
|
|
|
n.Block.Transactions = make([]*transaction.Transaction, len(txes))
|
|
|
|
for i, tx := range txes {
|
|
|
|
n.Block.Transactions[i] = tx.(*transaction.Transaction)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Version implements block.Block interface.
|
|
|
|
func (n *neoBlock) Version() uint32 { return n.Block.Version }
|
|
|
|
|
|
|
|
// SetVersion implements block.Block interface.
|
|
|
|
func (n *neoBlock) SetVersion(v uint32) { n.Block.Version = v }
|
|
|
|
|
|
|
|
// PrevHash implements block.Block interface.
|
|
|
|
func (n *neoBlock) PrevHash() util.Uint256 { return n.Block.PrevHash }
|
|
|
|
|
|
|
|
// SetPrevHash implements block.Block interface.
|
|
|
|
func (n *neoBlock) SetPrevHash(h util.Uint256) { n.Block.PrevHash = h }
|
|
|
|
|
|
|
|
// MerkleRoot implements block.Block interface.
|
|
|
|
func (n *neoBlock) MerkleRoot() util.Uint256 { return n.Block.MerkleRoot }
|
|
|
|
|
|
|
|
// SetMerkleRoot implements block.Block interface.
|
|
|
|
func (n *neoBlock) SetMerkleRoot(r util.Uint256) { n.Block.MerkleRoot = r }
|
|
|
|
|
|
|
|
// Timestamp implements block.Block interface.
|
2020-04-21 11:26:57 +00:00
|
|
|
func (n *neoBlock) Timestamp() uint64 { return n.Block.Timestamp }
|
2019-11-15 10:32:40 +00:00
|
|
|
|
|
|
|
// SetTimestamp implements block.Block interface.
|
2020-04-21 11:26:57 +00:00
|
|
|
func (n *neoBlock) SetTimestamp(ts uint64) { n.Block.Timestamp = ts }
|
2019-11-15 10:32:40 +00:00
|
|
|
|
|
|
|
// Index implements block.Block interface.
|
|
|
|
func (n *neoBlock) Index() uint32 { return n.Block.Index }
|
|
|
|
|
|
|
|
// SetIndex implements block.Block interface.
|
|
|
|
func (n *neoBlock) SetIndex(i uint32) { n.Block.Index = i }
|
|
|
|
|
|
|
|
// ConsensusData implements block.Block interface.
|
|
|
|
func (n *neoBlock) ConsensusData() uint64 { return n.Block.ConsensusData }
|
|
|
|
|
|
|
|
// SetConsensusData implements block.Block interface.
|
|
|
|
func (n *neoBlock) SetConsensusData(nonce uint64) { n.Block.ConsensusData = nonce }
|
|
|
|
|
|
|
|
// NextConsensus implements block.Block interface.
|
|
|
|
func (n *neoBlock) NextConsensus() util.Uint160 { return n.Block.NextConsensus }
|
|
|
|
|
|
|
|
// SetNextConsensus implements block.Block interface.
|
|
|
|
func (n *neoBlock) SetNextConsensus(h util.Uint160) { n.Block.NextConsensus = h }
|
|
|
|
|
|
|
|
// Signature implements block.Block interface.
|
|
|
|
func (n *neoBlock) Signature() []byte { return n.signature }
|