github.com/annchain/OG@v0.0.9/arefactor_core/core/ledger.go (about)

     1  package core
     2  
     3  import (
     4  	"fmt"
     5  	ogTypes "github.com/annchain/OG/arefactor/og_interface"
     6  	"github.com/annchain/OG/arefactor/types"
     7  )
     8  
     9  type OgLedger struct {
    10  	pool *TxPool
    11  	dag  *Dag
    12  }
    13  
    14  type Proposal interface {
    15  	PrevBlock() ogTypes.Hash
    16  }
    17  
    18  // TODO ledger locker
    19  
    20  func (ol *OgLedger) Speculate(proposal Proposal) (stateRoot ogTypes.Hash, err error) {
    21  	seq, ok := proposal.(*types.Sequencer)
    22  	if !ok {
    23  		return nil, fmt.Errorf("OG ledger only support sequencer")
    24  	}
    25  	elderList, _, err := ol.pool.SeekElders(seq)
    26  	if err != nil {
    27  		return nil, fmt.Errorf("seek elder error: %v", err)
    28  	}
    29  
    30  	pushBatch := &PushBatch{
    31  		Seq: seq,
    32  		Txs: elderList,
    33  	}
    34  	root, err := ol.dag.Speculate(pushBatch)
    35  	if err != nil {
    36  		return nil, fmt.Errorf("dag speculate err: %v", err)
    37  	}
    38  	return root, nil
    39  }
    40  
    41  func (ol *OgLedger) Push(seq *types.Sequencer) (err error) {
    42  	// TODO handle bad sequencer, make sure parent sequencer has been pushed before.
    43  
    44  	elders, err := ol.pool.PreConfirm(seq)
    45  	if err != nil {
    46  		return err
    47  	}
    48  	pushBatch := &PushBatch{
    49  		Seq: seq,
    50  		Txs: elders,
    51  	}
    52  	return ol.dag.Push(pushBatch)
    53  }
    54  
    55  func (ol *OgLedger) Commit(seqHash ogTypes.Hash) (err error) {
    56  	err = ol.pool.Confirm(seqHash)
    57  	if err != nil {
    58  		return err
    59  	}
    60  	return ol.dag.Commit(seqHash)
    61  }
    62  
    63  func (ol *OgLedger) GetConsensusState() {
    64  
    65  }
    66  
    67  func (ol *OgLedger) SetConsensusState() {
    68  
    69  }
    70  
    71  func (ol *OgLedger) CurrentHeight() int64 {
    72  	return 0
    73  }
    74  
    75  func (ol *OgLedger) CurrentCommittee() {
    76  
    77  }