Skip to content
This repository has been archived by the owner on Jan 2, 2025. It is now read-only.

Commit

Permalink
feat(backend): implement GetProfileDocument and ChangeProfileDocument
Browse files Browse the repository at this point in the history
  • Loading branch information
burdiyan committed Jun 29, 2024
1 parent 878de17 commit 6291998
Show file tree
Hide file tree
Showing 61 changed files with 7,273 additions and 1,078 deletions.
2 changes: 2 additions & 0 deletions backend/BUILD.plz
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ go_binary(
exclude = ["**/*_test.go"],
) + [
"//backend/daemon/storage:go_library",
"//backend/daemon/storage2:go_library",
"//backend/hyper/hypersql:go_library",
"//backend/lndhub/lndhubsql:go_library",
"//backend/wallet/walletsql:go_library",
Expand Down Expand Up @@ -40,6 +41,7 @@ go_binary(
exclude = ["**/*_test.go"],
) + [
"//backend/daemon/storage:go_library",
"//backend/daemon/storage2:go_library",
"//backend/hyper/hypersql:go_library",
"//backend/lndhub/lndhubsql:go_library",
"//backend/wallet/walletsql:go_library",
Expand Down
18 changes: 1 addition & 17 deletions backend/cmd/mkdb/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ import (
"seed/backend/config"
"seed/backend/core"
"seed/backend/core/coretest"
"seed/backend/daemon"
"seed/backend/daemon/storage"
storage "seed/backend/daemon/storage2"

"github.com/burdiyan/go/mainutil"
)
Expand All @@ -22,9 +21,6 @@ func main() {
}

func run() error {
ctx, cancel := context.WithCancel(mainutil.TrapSignals())
defer cancel()

alice := coretest.NewTester("alice")

cfg := config.Default()
Expand All @@ -46,18 +42,6 @@ func run() error {
}
defer dir.Close()

if err := dir.KeyStore().StoreKey(ctx, "main", alice.Account); err != nil {
return err
}

app, err := daemon.Load(ctx, cfg, dir)
if err != nil {
return err
}

cancel()

err = app.Wait()
fmt.Println("Database has been saved in:", cfg.Base.DataDir)
if errors.Is(err, context.Canceled) {
return nil
Expand Down
2 changes: 1 addition & 1 deletion backend/cmd/seed-daemon/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"seed/backend/config"
"seed/backend/core"
"seed/backend/daemon"
"seed/backend/daemon/storage"
storage "seed/backend/daemon/storage2"
"seed/backend/logging"

"github.com/burdiyan/go/mainutil"
Expand Down
5 changes: 5 additions & 0 deletions backend/core/principal.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ func (p Principal) UnsafeString() string {
return unsafe.String(&p[0], len(p))
}

// Equal checks if two principals are equal.
func (p Principal) Equal(pp Principal) bool {
return p.UnsafeString() == pp.UnsafeString()
}

// Verify implements Verifier.
func (p Principal) Verify(data []byte, sig Signature) error {
code, key := p.Explode()
Expand Down
43 changes: 29 additions & 14 deletions backend/daemon/api/apis.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@ package api
import (
"context"
"fmt"
"seed/backend/core"
accounts "seed/backend/daemon/api/accounts/v1alpha"
activity "seed/backend/daemon/api/activity/v1alpha"
daemon "seed/backend/daemon/api/daemon/v1alpha"
documents "seed/backend/daemon/api/documents/v1alpha"
documentsv2 "seed/backend/daemon/api/documents/v2alpha"
entities "seed/backend/daemon/api/entities/v1alpha"
networking "seed/backend/daemon/api/networking/v1alpha"
"seed/backend/daemon/storage"
"seed/backend/daemon/index"
"seed/backend/hyper"
"seed/backend/logging"
"seed/backend/mttnet"
"seed/backend/pkg/future"

Expand All @@ -22,18 +25,26 @@ import (

// Server combines all the daemon API services into one thing.
type Server struct {
Accounts *accounts.Server
Daemon *daemon.Server
Documents *documents.Server
Networking *networking.Server
Entities *entities.Server
Activity *activity.Server
Accounts *accounts.Server
Daemon *daemon.Server
Documents *documents.Server
Networking *networking.Server
Entities *entities.Server
Activity *activity.Server
DocumentsV2 *documentsv2.Server
}

type Storage interface {
DB() *sqlitex.Pool
KeyStore() core.KeyStore
Migrate() error
Device() core.KeyPair
}

// New creates a new API server.
func New(
ctx context.Context,
repo *storage.Store,
repo Storage,
db *sqlitex.Pool,
blobs *hyper.Storage,
node *mttnet.Node,
Expand All @@ -44,17 +55,20 @@ func New(
return fmt.Errorf("TODO(hm24): implement forced syncing")
}

idx := index.NewIndex(db, logging.New("seed/index", LogLevel))

documentsSrv := documents.NewServer(repo.KeyStore(), db,
nil, // TODO(hm24): add discovery back
nil, // TODO(hm24): add gateway client back
LogLevel)
return Server{
Accounts: accounts.NewServer(repo.KeyStore(), blobs),
Activity: activity.NewServer(db),
Daemon: daemon.NewServer(repo, blobs, wallet, doSync),
Documents: documentsSrv,
Networking: networking.NewServer(blobs, node),
Entities: entities.NewServer(blobs, &lazyDiscoverer{}),
Accounts: accounts.NewServer(repo.KeyStore(), blobs),
Activity: activity.NewServer(db),
Daemon: daemon.NewServer(repo, blobs, wallet, doSync),
Documents: documentsSrv,
Networking: networking.NewServer(blobs, node),
Entities: entities.NewServer(blobs, &lazyDiscoverer{}),
DocumentsV2: documentsv2.NewServer(repo.KeyStore(), idx),
}
}

Expand All @@ -66,6 +80,7 @@ func (s Server) Register(srv *grpc.Server) {
s.Activity.RegisterServer(srv)
s.Networking.RegisterServer(srv)
s.Entities.RegisterServer(srv)
s.DocumentsV2.RegisterServer(srv)
}

type lazyGwClient struct {
Expand Down
32 changes: 14 additions & 18 deletions backend/daemon/api/daemon/v1alpha/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ type Server struct {
// NewServer creates a new Server.
func NewServer(store Storage, blobs *hyper.Storage, w Wallet, syncFunc func() error) *Server {
return &Server{
store: store,
blobs: blobs,
startTime: time.Now(),
wallet: w,
store: store,
blobs: blobs,
startTime: time.Now(),
// wallet: w, // TODO(hm24): Put the wallet back.
forceSyncFunc: syncFunc,
}
}
Expand Down Expand Up @@ -78,15 +78,8 @@ func (srv *Server) RegisterKey(ctx context.Context, req *daemon.RegisterKeyReque
srv.mu.Lock()
defer srv.mu.Unlock()

// TODO(hm24): Simply make name required when multiple keys are supported across the whole app.
{
if req.Name == "" {
req.Name = "main"
}

if req.Name != "main" {
return nil, status.Error(codes.InvalidArgument, "TODO: support for multiple keys is not implemented yet")
}
if req.Name == "" {
return nil, status.Errorf(codes.InvalidArgument, "name is required for a key")
}

acc, err := core.AccountFromMnemonic(req.Mnemonic, req.Passphrase)
Expand Down Expand Up @@ -152,15 +145,18 @@ func (srv *Server) RegisterAccount(ctx context.Context, name string, kp core.Key
return err
}

if _, err := Register(ctx, srv.blobs, kp, kp.PublicKey, time.Now().UTC()); err != nil {
return err
}
// TODO(hm24): Get rid of this Register function entirely.
// if _, err := Register(ctx, srv.blobs, kp, kp.PublicKey, time.Now().UTC()); err != nil {
// return err
// }

// TODO(hm24): we don't need to do this here since now we have the keys always accessible, unless the user
// chooses not to store the keys... Do this at the time of creating the seed wallet (new method not insert
// wallet which is an external wallet)
if err := srv.wallet.ConfigureSeedLNDHub(ctx, kp); err != nil {
return fmt.Errorf("failed to configure wallet when registering: %w", err)
if srv.wallet != nil {
if err := srv.wallet.ConfigureSeedLNDHub(ctx, kp); err != nil {
return fmt.Errorf("failed to configure wallet when registering: %w", err)
}
}
return nil
}
Expand Down
3 changes: 1 addition & 2 deletions backend/daemon/api/daemon/v1alpha/daemon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,9 @@ func newTestServer(t *testing.T, name string) *Server {
u := coretest.NewTester(name)
repo := daemontest.MakeTestRepo(t, u)
db := storage.MakeTestDB(t)
wallet := new(mockedWallet)
blobs := hyper.NewStorage(db, logging.New("seed/hyper", "debug"))

return NewServer(repo, blobs, wallet, nil)
return NewServer(repo, blobs, nil, nil)
}

type mockedWallet struct {
Expand Down
Loading

0 comments on commit 6291998

Please sign in to comment.