-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #182 from sunriselayer/query/proxy
feat: lockup account & proxy account Query
- Loading branch information
Showing
16 changed files
with
1,635 additions
and
84 deletions.
There are no files selected for viewing
This file contains 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
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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 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 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 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 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
26 changes: 26 additions & 0 deletions
26
x/selfdelegation/keeper/msg_server_register_lockup_account.go
This file contains 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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package keeper | ||
|
||
import ( | ||
"context" | ||
|
||
"cosmossdk.io/errors" | ||
|
||
"github.com/sunriselayer/sunrise/x/selfdelegation/types" | ||
) | ||
|
||
func (k msgServer) RegisterLockupAccount(ctx context.Context, msg *types.MsgRegisterLockupAccount) (*types.MsgRegisterLockupAccountResponse, error) { | ||
lockupBytes, err := k.addressCodec.StringToBytes(msg.Sender) | ||
if err != nil { | ||
return nil, errors.Wrap(err, "invalid lockup account address") | ||
} | ||
ownerBytes, err := k.addressCodec.StringToBytes(msg.Owner) | ||
if err != nil { | ||
return nil, errors.Wrap(err, "invalid owner address") | ||
} | ||
err = k.LockupAccounts.Set(ctx, lockupBytes, ownerBytes) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &types.MsgRegisterLockupAccountResponse{}, nil | ||
} |
This file contains 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 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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package keeper | ||
|
||
import ( | ||
"bytes" | ||
"context" | ||
|
||
"google.golang.org/grpc/codes" | ||
"google.golang.org/grpc/status" | ||
|
||
"github.com/sunriselayer/sunrise/x/selfdelegation/types" | ||
) | ||
|
||
func (q queryServer) LockupAccountsByOwner(ctx context.Context, req *types.QueryLockupAccountsByOwnerRequest) (*types.QueryLockupAccountsByOwnerResponse, error) { | ||
if req == nil { | ||
return nil, status.Error(codes.InvalidArgument, "invalid request") | ||
} | ||
|
||
ownerAddress, err := q.k.addressCodec.StringToBytes(req.OwnerAddress) | ||
if err != nil { | ||
return nil, status.Error(codes.InvalidArgument, "invalid owner address") | ||
} | ||
|
||
var lockupAccountAddresses []string | ||
err = q.k.LockupAccounts.Walk(ctx, nil, func(key []byte, val []byte) (stop bool, err error) { | ||
if bytes.Equal(val, ownerAddress) { // if owner address matches | ||
lockupAddressString, err := q.k.addressCodec.BytesToString(key) | ||
if err != nil { | ||
// continue walking and skip current lockup account | ||
return true, nil | ||
} | ||
lockupAccountAddresses = append(lockupAccountAddresses, lockupAddressString) | ||
} | ||
return false, nil // continue walking to find all lockup accounts for the owner | ||
}) | ||
if err != nil { | ||
return nil, status.Error(codes.Internal, "failed to walk lockup accounts") | ||
} | ||
|
||
return &types.QueryLockupAccountsByOwnerResponse{LockupAccountAddresses: lockupAccountAddresses}, nil | ||
} |
This file contains 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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package keeper | ||
|
||
import ( | ||
"context" | ||
|
||
"google.golang.org/grpc/codes" | ||
"google.golang.org/grpc/status" | ||
|
||
"github.com/sunriselayer/sunrise/x/selfdelegation/types" | ||
) | ||
|
||
func (q queryServer) SelfDelegationProxyAccountByOwner(ctx context.Context, req *types.QuerySelfDelegationProxyAccountByOwnerRequest) (*types.QuerySelfDelegationProxyAccountByOwnerResponse, error) { | ||
if req == nil { | ||
return nil, status.Error(codes.InvalidArgument, "invalid request") | ||
} | ||
|
||
ownerAddress, err := q.k.addressCodec.StringToBytes(req.OwnerAddress) | ||
if err != nil { | ||
return nil, status.Error(codes.InvalidArgument, "invalid owner address") | ||
} | ||
|
||
proxyAccountAddress, err := q.k.SelfDelegationProxies.Get(ctx, ownerAddress) | ||
if err != nil { | ||
return nil, status.Error(codes.NotFound, "proxy account not found") | ||
} | ||
|
||
proxyAccountString, err := q.k.addressCodec.BytesToString(proxyAccountAddress) | ||
if err != nil { | ||
return nil, status.Error(codes.Internal, "failed to convert proxy account address to string") | ||
} | ||
|
||
return &types.QuerySelfDelegationProxyAccountByOwnerResponse{SelfDelegationProxyAccountAddress: proxyAccountString}, nil | ||
} |
This file contains 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 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
Oops, something went wrong.