From efa195704bc68475af6db40913cb59aa826f2991 Mon Sep 17 00:00:00 2001 From: Ethan Reesor Date: Tue, 18 Jun 2024 13:11:59 -0500 Subject: [PATCH] Rename parameters --- pkg/database/bpt/bpt.go | 10 +++++----- pkg/database/bpt/marshal.go | 6 +++--- pkg/database/bpt/model.yml | 2 +- pkg/database/bpt/model_gen.go | 4 ++-- pkg/database/bpt/node.go | 8 ++++---- pkg/database/bpt/types.yml | 2 +- pkg/database/bpt/types_gen.go | 10 +++++----- 7 files changed, 21 insertions(+), 21 deletions(-) diff --git a/pkg/database/bpt/bpt.go b/pkg/database/bpt/bpt.go index 5cf23224f..fa7b4e3d5 100644 --- a/pkg/database/bpt/bpt.go +++ b/pkg/database/bpt/bpt.go @@ -49,20 +49,20 @@ func (b *BPT) GetRootHash() ([32]byte, error) { return h, nil } -func (b *BPT) newState() values.Value[*parameters] { - v := values.NewValue(b.logger.L, b.store, b.key.Append("Root"), false, values.Struct[parameters]()) +func (b *BPT) newState() values.Value[*stateData] { + v := values.NewValue(b.logger.L, b.store, b.key.Append("Root"), false, values.Struct[stateData]()) return paramsRecord{v} } // paramsRecord is a wrapper around Value that sets the power to 8 if the // parameters have not been configured. type paramsRecord struct { - values.Value[*parameters] + values.Value[*stateData] } // Get loads the parameters, initializing them to the default values if they // have not been set. -func (p paramsRecord) Get() (*parameters, error) { +func (p paramsRecord) Get() (*stateData, error) { v, err := p.Value.Get() switch { case err == nil: @@ -72,7 +72,7 @@ func (p paramsRecord) Get() (*parameters, error) { } // TODO Allow power to be configurable? - v = new(parameters) + v = new(stateData) v.Power = 8 v.Mask = v.Power - 1 err = p.Value.Put(v) diff --git a/pkg/database/bpt/marshal.go b/pkg/database/bpt/marshal.go index 9968bdfa7..1447277b3 100644 --- a/pkg/database/bpt/marshal.go +++ b/pkg/database/bpt/marshal.go @@ -26,7 +26,7 @@ const branchStateSize = 32 + 1 + 32 // leafStateSize is the marshaled size of [leaf]. const leafStateSize = 32 + 32 -func (r *parameters) MarshalBinary() ([]byte, error) { +func (r *stateData) MarshalBinary() ([]byte, error) { // Marshal the fields var data []byte data = append(data, byte(r.MaxHeight)) @@ -36,7 +36,7 @@ func (r *parameters) MarshalBinary() ([]byte, error) { return data, nil } -func (r *parameters) UnmarshalBinary(data []byte) error { +func (r *stateData) UnmarshalBinary(data []byte) error { // Check the size if len(data) != paramsStateSize { return encoding.ErrNotEnoughData @@ -50,7 +50,7 @@ func (r *parameters) UnmarshalBinary(data []byte) error { return nil } -func (r *parameters) UnmarshalBinaryFrom(rd io.Reader) error { +func (r *stateData) UnmarshalBinaryFrom(rd io.Reader) error { // Read paramStateSize bytes var buf [paramsStateSize]byte _, err := io.ReadFull(rd, buf[:]) diff --git a/pkg/database/bpt/model.yml b/pkg/database/bpt/model.yml index 93825c70c..0a5e388e3 100644 --- a/pkg/database/bpt/model.yml +++ b/pkg/database/bpt/model.yml @@ -13,7 +13,7 @@ omitConstructor: true type: state key: Root - dataType: parameters + dataType: stateData pointer: true - name: Root private: true diff --git a/pkg/database/bpt/model_gen.go b/pkg/database/bpt/model_gen.go index 8e1dfab83..481f8921a 100644 --- a/pkg/database/bpt/model_gen.go +++ b/pkg/database/bpt/model_gen.go @@ -22,13 +22,13 @@ type BPT struct { key *record.Key pending map[[32]byte]*mutation - state values.Value[*parameters] + state values.Value[*stateData] root *rootRecord } func (c *BPT) Key() *record.Key { return c.key } -func (c *BPT) getState() values.Value[*parameters] { +func (c *BPT) getState() values.Value[*stateData] { return values.GetOrCreate(c, &c.state, (*BPT).newState) } diff --git a/pkg/database/bpt/node.go b/pkg/database/bpt/node.go index fcf662a26..ce90aab87 100644 --- a/pkg/database/bpt/node.go +++ b/pkg/database/bpt/node.go @@ -33,7 +33,7 @@ type node interface { // copyWith copies the receiver with the given branch as the parent of the // new copy. - copyWith(_ *parameters, _ *branch, clean bool) node + copyWith(_ *stateData, _ *branch, clean bool) node // writeTo marshals the node and writes it to the writer. writeTo(io.Writer) error @@ -190,13 +190,13 @@ func (e *branch) load() error { } // copyWith returns a new empty node with parent set to the given branch. -func (e *emptyNode) copyWith(s *parameters, p *branch, clean bool) node { +func (e *emptyNode) copyWith(s *stateData, p *branch, clean bool) node { return &emptyNode{parent: p} } // copyWith returns a copy of the branch with parent set to the given branch. // copyWith copies recursively if put is true. -func (e *branch) copyWith(s *parameters, p *branch, clean bool) node { +func (e *branch) copyWith(s *stateData, p *branch, clean bool) node { // Ensure the hash is up to date e.getHash() @@ -231,7 +231,7 @@ func (e *branch) copyWith(s *parameters, p *branch, clean bool) node { // copyWith returns a copy of the leaf node with parent set to the given branch. // If the receiver's parent is nil, copyWith returns it instead after setting // its parent. -func (e *leaf) copyWith(s *parameters, p *branch, clean bool) node { +func (e *leaf) copyWith(s *stateData, p *branch, clean bool) node { f := *e f.parent = p return &f diff --git a/pkg/database/bpt/types.yml b/pkg/database/bpt/types.yml index 47e2dea7f..418c3f211 100644 --- a/pkg/database/bpt/types.yml +++ b/pkg/database/bpt/types.yml @@ -1,4 +1,4 @@ -parameters: +stateData: non-binary: true non-json: true fields: diff --git a/pkg/database/bpt/types_gen.go b/pkg/database/bpt/types_gen.go index bc02aa9c3..782f3f5db 100644 --- a/pkg/database/bpt/types_gen.go +++ b/pkg/database/bpt/types_gen.go @@ -38,7 +38,7 @@ type leaf struct { parent *branch } -type parameters struct { +type stateData struct { RootHash [32]byte `json:"rootHash,omitempty" form:"rootHash" query:"rootHash" validate:"required"` MaxHeight uint64 `json:"maxHeight,omitempty" form:"maxHeight" query:"maxHeight" validate:"required"` Power uint64 `json:"power,omitempty" form:"power" query:"power" validate:"required"` @@ -78,8 +78,8 @@ func (v *leaf) Copy() *leaf { func (v *leaf) CopyAsInterface() interface{} { return v.Copy() } -func (v *parameters) Copy() *parameters { - u := new(parameters) +func (v *stateData) Copy() *stateData { + u := new(stateData) u.RootHash = v.RootHash u.MaxHeight = v.MaxHeight @@ -89,7 +89,7 @@ func (v *parameters) Copy() *parameters { return u } -func (v *parameters) CopyAsInterface() interface{} { return v.Copy() } +func (v *stateData) CopyAsInterface() interface{} { return v.Copy() } func (v *branch) Equal(u *branch) bool { if !(v.Height == u.Height) { @@ -126,7 +126,7 @@ func (v *leaf) Equal(u *leaf) bool { return true } -func (v *parameters) Equal(u *parameters) bool { +func (v *stateData) Equal(u *stateData) bool { if !(v.RootHash == u.RootHash) { return false }