OSDN Git Service

Merge remote-tracking branch 'origin/subprotocol' into mov_merge
[bytom/vapor.git] / protocol / mov.go
1 package protocol
2
3 import (
4         "github.com/vapor/application/mov"
5         "github.com/vapor/config"
6         "github.com/vapor/consensus"
7         dbm "github.com/vapor/database/leveldb"
8         "github.com/vapor/errors"
9         "github.com/vapor/protocol/bc"
10         "github.com/vapor/protocol/bc/types"
11 )
12
13 const (
14         protocolName = "MOV"
15 )
16
17 type movCore interface {
18         ApplyBlock(block *types.Block) error
19         BeforeProposalBlock(capacity int) ([]*types.Tx, error)
20         ChainStatus() (uint64, *bc.Hash, error)
21         DetachBlock(block *types.Block) error
22         IsDust(tx *types.Tx) bool
23         ValidateBlock(block *types.Block) error
24         ValidateTxs(txs []*types.Tx) error
25 }
26
27 type MOV struct {
28         core movCore
29 }
30
31 func NewMOV(db dbm.DB, startPoint consensus.Checkpoint) (*MOV, error) {
32         if startPoint.Height == 0 {
33                 startPoint.Hash = config.GenesisBlock().Hash()
34         }
35
36         movCore, err := mov.NewMovCore(db, startPoint.Height, &startPoint.Hash)
37         if err != nil {
38                 return nil, errors.Wrap(err, "failed on create mov core")
39         }
40
41         return &MOV{
42                 core: movCore,
43         }, nil
44 }
45
46 func (m MOV) ApplyBlock(block *types.Block) error {
47         return m.core.ApplyBlock(block)
48 }
49
50 func (m MOV) BeforeProposalBlock(capacity int) ([]*types.Tx, error) {
51         return m.core.BeforeProposalBlock(capacity)
52 }
53
54 func (m MOV) ChainStatus() (uint64, *bc.Hash, error) {
55         return m.core.ChainStatus()
56 }
57
58 func (m MOV) DetachBlock(block *types.Block) error {
59         return m.core.DetachBlock(block)
60 }
61
62 func (m MOV) IsDust(tx *types.Tx) bool {
63         return m.core.IsDust(tx)
64 }
65
66 func (m MOV) Name() string {
67         return protocolName
68 }
69
70 func (m MOV) ValidateBlock(block *types.Block) error {
71         return m.core.ValidateBlock(block)
72 }
73
74 func (m MOV) ValidateTxs(txs []*types.Tx) error {
75         return m.core.ValidateTxs(txs)
76 }