github.com/unicornultrafoundation/go-u2u@v1.0.0-rc1.0.20240205080301-e74a83d3fadc/utils/adapters/vecmt2dagidx/vecmt2hashgraph.go (about)

     1  package vecmt2dagidx
     2  
     3  import (
     4  	"github.com/unicornultrafoundation/go-helios/consensus"
     5  	"github.com/unicornultrafoundation/go-helios/consensus/dagidx"
     6  	"github.com/unicornultrafoundation/go-helios/hash"
     7  	"github.com/unicornultrafoundation/go-helios/native/idx"
     8  	"github.com/unicornultrafoundation/go-helios/vecfc"
     9  
    10  	"github.com/unicornultrafoundation/go-u2u/vecmt"
    11  )
    12  
    13  type Adapter struct {
    14  	*vecmt.Index
    15  }
    16  
    17  var _ consensus.DagIndex = (*Adapter)(nil)
    18  
    19  type AdapterSeq struct {
    20  	*vecmt.HighestBefore
    21  }
    22  
    23  type BranchSeq struct {
    24  	vecfc.BranchSeq
    25  }
    26  
    27  // Seq is a maximum observed e.Seq in the branch
    28  func (b *BranchSeq) Seq() idx.Event {
    29  	return b.BranchSeq.Seq
    30  }
    31  
    32  // MinSeq is a minimum observed e.Seq in the branch
    33  func (b *BranchSeq) MinSeq() idx.Event {
    34  	return b.BranchSeq.MinSeq
    35  }
    36  
    37  // Size of the vector clock
    38  func (b AdapterSeq) Size() int {
    39  	return b.VSeq.Size()
    40  }
    41  
    42  // Get i's position in the byte-encoded vector clock
    43  func (b AdapterSeq) Get(i idx.Validator) dagidx.Seq {
    44  	seq := b.HighestBefore.VSeq.Get(i)
    45  	return &BranchSeq{seq}
    46  }
    47  
    48  func (v *Adapter) GetMergedHighestBefore(id hash.Event) dagidx.HighestBeforeSeq {
    49  	return AdapterSeq{v.Index.GetMergedHighestBefore(id)}
    50  }
    51  
    52  func Wrap(v *vecmt.Index) *Adapter {
    53  	return &Adapter{v}
    54  }