Updated interfaces and added EntryID Hash

This commit is contained in:
2026-02-11 06:49:21 +00:00
parent 652cfaf766
commit ca1a3e266b
3 changed files with 42 additions and 9 deletions

View File

@@ -5,13 +5,14 @@ import (
)
type EntryStore interface {
Put(ctx context.Context, id EntryID, canonical []byte) error
Get(ctx context.Context, id EntryID) ([]byte, error)
Has(ctx context.Context, id EntryID) (bool, error)
Store(ctx context.Context, entry Entry) error
Load(ctx context.Context, id EntryID) (Entry, error)
Exists(ctx context.Context, id EntryID) (bool, error)
Delete(ctx context.Context, id EntryID) error
}
type ReferenceStore interface {
GetRef(ctx context.Context, name string) (EntryID, bool, error)
SetRef(ctx context.Context, name string, entryID EntryID) (bool, error)
RemoveRef(ctx context.Context, name string) error
Set(ctx context.Context, name string, entryID EntryID) error
Get(ctx context.Context, name string) (EntryID, error)
Delete(ctx context.Context, name string) error
}

View File

@@ -7,8 +7,17 @@ type Ledger struct {
referenceStore ReferenceStore
}
func NewLedger(entryStore EntryStore) (*Ledger, error) {
func NewLedger(entryStore EntryStore, referenceStore ReferenceStore) (*Ledger, error) {
return &Ledger{
entryStore: entryStore,
entryStore: entryStore,
referenceStore: referenceStore,
}, nil
}
func (l *Ledger) Append() {}
func (l *Ledger) AppendToReference() {}
func (l *Ledger) Get() {}
func (l *Ledger) GetFromReference() {}
func (l *Ledger) SetHead() {}
func (l *Ledger) SetReference() {}
func (l *Ledger) RemoveReference() {}

View File

@@ -1,7 +1,10 @@
package core
import (
"encoding/binary"
"time"
"lukechampine.com/blake3"
)
type EntryID [32]byte
@@ -9,8 +12,28 @@ type EntryID [32]byte
type Entry struct {
EntryID EntryID
Previous []EntryID
Previous EntryID
Timestamp time.Time
Payload []byte
}
func ComputeEntryID(prev EntryID, ts time.Time, payload []byte) EntryID {
h := blake3.New(32, nil)
h.Write(prev[:])
var i64 [8]byte
binary.LittleEndian.PutUint64(i64[:], uint64(ts.UTC().UnixNano()))
h.Write(i64[:])
var u32 [4]byte
binary.LittleEndian.PutUint32(u32[:], uint32(len(payload)))
h.Write(u32[:])
h.Write(payload)
var id EntryID
copy(id[:], h.Sum(nil))
return id
}