-
Notifications
You must be signed in to change notification settings - Fork 4
Refactor, implement OpStore interface #22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 9 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
2c9e47b
refactor, implement OpStore interface
DavidBuchanan314 4afd56f
roll getValidationContext into VerifyOperation
DavidBuchanan314 ee9dc03
implement driver.Valuer and sql.Scanner for OpEnum
DavidBuchanan314 8868657
add ctx to OpStore interface
DavidBuchanan314 3f13df3
avoid calculating op cid twice during VerifyOpLog
DavidBuchanan314 88e28fe
don't fetch prevStatus twice
DavidBuchanan314 9fedce2
renaming things
DavidBuchanan314 f24a1f1
refactor OpStore interface, introduce GetEntry, GetLatest
DavidBuchanan314 0641a34
distinguish db failures from validation failures
DavidBuchanan314 35ada6e
remove Value/Scan
DavidBuchanan314 cfdbd8d
replace WrapOperation with Operation.AsOpEnum
DavidBuchanan314 501dd12
Add stubbed GetAllEntries, update comments
DavidBuchanan314 8a4a67c
simplify VerifyOperation slightly
DavidBuchanan314 af54c82
comment tweak
DavidBuchanan314 ce1032a
typo
DavidBuchanan314 c124492
re-order methods to better distinguish interface from impl
DavidBuchanan314 b83cae6
rework error handling w/ wrapped errors
DavidBuchanan314 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ package didplc | |
|
|
||
| import ( | ||
| "crypto/sha256" | ||
| "database/sql/driver" | ||
| "encoding/base32" | ||
| "encoding/base64" | ||
| "encoding/json" | ||
|
|
@@ -484,6 +485,31 @@ func (o *OpEnum) UnmarshalJSON(b []byte) error { | |
| } | ||
| } | ||
|
|
||
| // Value implements the driver.Valuer interface | ||
| func (o OpEnum) Value() (driver.Value, error) { | ||
| // TODO: consider using CBOR here? | ||
| return o.MarshalJSON() | ||
| } | ||
|
|
||
| // Scan implements the sql.Scanner interface | ||
| func (o *OpEnum) Scan(value interface{}) error { | ||
| if value == nil { | ||
| return nil | ||
| } | ||
|
|
||
| var bytes []byte | ||
| switch v := value.(type) { | ||
| case []byte: | ||
| bytes = v | ||
| case string: | ||
| bytes = []byte(v) | ||
| default: | ||
| return fmt.Errorf("failed to scan OpEnum: expected []byte or string, got %T", value) | ||
| } | ||
|
|
||
| return o.UnmarshalJSON(bytes) | ||
| } | ||
|
|
||
| // returns a new signed PLC operation using the provided atproto-specific metdata | ||
| func NewAtproto(priv atcrypto.PrivateKey, handle string, pdsEndpoint string, rotationKeys []string) (RegularOp, error) { | ||
|
|
||
|
|
@@ -528,3 +554,25 @@ func (oe *OpEnum) AsOperation() Operation { | |
| return nil | ||
| } | ||
| } | ||
|
|
||
| // WrapOperation converts an Operation interface to an OpEnum for marshaling | ||
| func WrapOperation(op Operation) (*OpEnum, error) { | ||
|
DavidBuchanan314 marked this conversation as resolved.
Outdated
|
||
| if op == nil { | ||
| return nil, fmt.Errorf("cannot wrap nil operation") | ||
| } | ||
|
|
||
| opEnum := &OpEnum{} | ||
|
|
||
| switch v := op.(type) { | ||
| case *RegularOp: | ||
| opEnum.Regular = v | ||
| case *LegacyOp: | ||
| opEnum.Legacy = v | ||
| case *TombstoneOp: | ||
| opEnum.Tombstone = v | ||
| default: | ||
| return nil, fmt.Errorf("unknown operation type: %T", op) | ||
| } | ||
|
|
||
| return opEnum, nil | ||
| } | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This addition is unrelated to the OpStore interface, it's just something else I'm using in the replica impl |
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.