Skip to content
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

Add CurrentAccountID to the AccountList response #57

Merged
merged 2 commits into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.22.1

require (
github.com/0xsequence/ethkit v1.25.0
github.com/0xsequence/go-sequence v0.33.1
github.com/0xsequence/go-sequence v0.33.2
github.com/0xsequence/nitrocontrol v0.3.0
github.com/BurntSushi/toml v1.3.2
github.com/aws/aws-sdk-go-v2 v1.27.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ github.com/0xsequence/ethkit v1.25.0 h1:auXjpJrpIckfzQ5jgVAD6GECLpFSViZWsJtz1F3E
github.com/0xsequence/ethkit v1.25.0/go.mod h1:E3eymNtV0oJabgqM9R92xTQYOsT7rVHxFRju8A2CFJw=
github.com/0xsequence/go-ethauth v0.13.0 h1:ZaqFEEqy574A2b1P7vjpcy5tb4W/izn+A3swwOYi9wA=
github.com/0xsequence/go-ethauth v0.13.0/go.mod h1:f3kx39S9F+W+qvZEB6bkKKbpUstmyB7goUntO3wvlhg=
github.com/0xsequence/go-sequence v0.33.1 h1:3N3AJ+AUNeuTmICWNha6fD/qvSx6IPUitGPQgoRov+U=
github.com/0xsequence/go-sequence v0.33.1/go.mod h1:7VGqBMoOGI43fzr3NDCMYxkXoz+qwdnnR3ocz4fHWjM=
github.com/0xsequence/go-sequence v0.33.2 h1:YUj1V1FnZd0dBvAk26P8TLcRY0zvRjc/w/OFYrOTJDs=
github.com/0xsequence/go-sequence v0.33.2/go.mod h1:7VGqBMoOGI43fzr3NDCMYxkXoz+qwdnnR3ocz4fHWjM=
github.com/0xsequence/nitrocontrol v0.3.0 h1:D0/gX576zQhitrJnBfBrOFFufEOzh6f2jO/+2ynwIUA=
github.com/0xsequence/nitrocontrol v0.3.0/go.mod h1:sTG5akVPzoVr3unv/7h9aZGaT+BVGmvUMOdwXFeIEEA=
github.com/0xsequence/nsm v0.1.0 h1:gVOViRWPUW/c5VEmGy2gCw1az/nqP3gY7VD9V2+069k=
Expand Down
9 changes: 7 additions & 2 deletions rpc/accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (

func (s *RPC) listAccounts(
ctx context.Context, sess *data.Session, intent *intents.IntentTyped[intents.IntentDataListAccounts],
) ([]*intents.Account, error) {
) (*intents.IntentResponseAccountList, error) {
tntData := tenant.FromContext(ctx)

dbAccounts, err := s.Accounts.ListByUserID(ctx, sess.UserID)
Expand Down Expand Up @@ -46,7 +46,12 @@ func (s *RPC) listAccounts(
out[i].Email = &dbAcc.Email
}
}
return out, nil

res := &intents.IntentResponseAccountList{
Accounts: out,
CurrentAccountID: sess.Identity,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i wonder if we should rename this to, SessionAccountID ..? but CurrentAccountID is fine too.. whatever you guys prefer

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd be wary of using the word session, we have way too many "sessions" and it's now a very overloaded word IMO 😅 though maybe in this case it'd fit well? not 100% sure

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool, lets stick to CurrentAccountID :)

}
return res, nil
}

func (s *RPC) federateAccount(
Expand Down
15 changes: 8 additions & 7 deletions rpc/intents.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func (s *RPC) SendIntent(ctx context.Context, protoIntent *proto.Intent) (*proto
if err != nil {
return nil, err
}
return makeIntentResponse(proto.IntentResponseCode_authInitiated, res), nil
return makeTypedIntentResponse(res)
}

sess, found, err := s.Sessions.Get(ctx, tntData.ProjectID, sessionID)
Expand All @@ -99,7 +99,7 @@ func (s *RPC) SendIntent(ctx context.Context, protoIntent *proto.Intent) (*proto
if err != nil {
return nil, err
}
return makeIntentResponse(proto.IntentResponseCode_sessionClosed, intents.IntentResponseSessionClosed{}), nil
return makeTypedIntentResponse(&intents.IntentResponseSessionClosed{})

case intents.IntentName_listSessions:
intentTyped, err := intents.NewIntentTypedFromIntent[intents.IntentDataListSessions](intent)
Expand All @@ -110,6 +110,7 @@ func (s *RPC) SendIntent(ctx context.Context, protoIntent *proto.Intent) (*proto
if err != nil {
return nil, err
}
// TODO switch to correct response (compare the intent.Version semver to not break older clients)
return makeIntentResponse(proto.IntentResponseCode_sessionList, sessions), nil

case intents.IntentName_sessionAuthProof:
Expand Down Expand Up @@ -138,11 +139,11 @@ func (s *RPC) SendIntent(ctx context.Context, protoIntent *proto.Intent) (*proto
if err != nil {
return nil, err
}
accounts, err := s.listAccounts(ctx, sess, intentTyped)
res, err := s.listAccounts(ctx, sess, intentTyped)
if err != nil {
return nil, err
}
return makeIntentResponse(proto.IntentResponseCode_accountList, accounts), nil
return makeTypedIntentResponse(res)

case intents.IntentName_federateAccount:
intentTyped, err := intents.NewIntentTypedFromIntent[intents.IntentDataFederateAccount](intent)
Expand All @@ -153,7 +154,7 @@ func (s *RPC) SendIntent(ctx context.Context, protoIntent *proto.Intent) (*proto
if err != nil {
return nil, err
}
return makeIntentResponse(proto.IntentResponseCode_accountFederated, account), nil
return makeTypedIntentResponse(&intents.IntentResponseAccountFederated{Account: account})

case intents.IntentName_removeAccount:
intentTyped, err := intents.NewIntentTypedFromIntent[intents.IntentDataRemoveAccount](intent)
Expand All @@ -163,7 +164,7 @@ func (s *RPC) SendIntent(ctx context.Context, protoIntent *proto.Intent) (*proto
if err := s.removeAccount(ctx, sess, intentTyped); err != nil {
return nil, err
}
return makeIntentResponse(proto.IntentResponseCode_accountRemoved, true), nil
return makeTypedIntentResponse(&intents.IntentResponseAccountRemoved{})

case intents.IntentName_getIdToken:
intentTyped, err := intents.NewIntentTypedFromIntent[intents.IntentDataGetIdToken](intent)
Expand All @@ -174,7 +175,7 @@ func (s *RPC) SendIntent(ctx context.Context, protoIntent *proto.Intent) (*proto
if err != nil {
return nil, err
}
return makeIntentResponse(proto.IntentResponseCode_idToken, res), nil
return makeTypedIntentResponse(res)
}

// Generic forwarding of intent, no special handling
Expand Down
8 changes: 8 additions & 0 deletions rpc/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,11 @@ func makeIntentResponse(code proto.IntentResponseCode, data any) *proto.IntentRe
Data: data,
}
}

func makeTypedIntentResponse[T any](data *T) (*proto.IntentResponse, error) {
code := intents.IntentResponseTypeToCode[T](data)
if code == "" {
return nil, fmt.Errorf("invalid intent response type")
}
return &proto.IntentResponse{Code: proto.IntentResponseCode(code), Data: data}, nil
}
10 changes: 6 additions & 4 deletions vendor/github.com/0xsequence/go-sequence/intents/intent.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 6 additions & 4 deletions vendor/github.com/0xsequence/go-sequence/intents/intent.gen.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions vendor/github.com/0xsequence/go-sequence/intents/intent.ridl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ github.com/0xsequence/ethkit/util
# github.com/0xsequence/go-ethauth v0.13.0
## explicit; go 1.17
github.com/0xsequence/go-ethauth
# github.com/0xsequence/go-sequence v0.33.1
# github.com/0xsequence/go-sequence v0.33.2
## explicit; go 1.21
github.com/0xsequence/go-sequence
github.com/0xsequence/go-sequence/contracts
Expand Down
Loading