Skip to content

Commit

Permalink
feat: impl query
Browse files Browse the repository at this point in the history
  • Loading branch information
Senna46 committed Feb 14, 2025
1 parent ee0f9e1 commit 3dd103d
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 7 deletions.
43 changes: 42 additions & 1 deletion x/da/keeper/query_da.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,46 @@ func (q queryServer) ValidityProof(goCtx context.Context, req *types.QueryValidi
if err != nil {
return nil, errorsmod.Wrap(err, "invalid validator address")
}
q.k.GetProof()
proof, found := q.k.GetProof(ctx, req.MetadataUri, validator)
if !found {
return nil, types.ErrProofNotFound
}

return &types.QueryValidityProofResponse{Proof: proof}, nil
}

func (q queryServer) AllValidityProofs(goCtx context.Context, req *types.QueryAllValidityProofsRequest) (*types.QueryAllValidityProofsResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "invalid request")
}
ctx := sdk.UnwrapSDKContext(goCtx)

return &types.QueryAllValidityProofsResponse{Proofs: q.k.GetAllProofs(ctx)}, nil
}

func (q queryServer) Invalidity(goCtx context.Context, req *types.QueryInvalidityRequest) (*types.QueryInvalidityResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "invalid request")
}
ctx := sdk.UnwrapSDKContext(goCtx)

sender, err := q.k.addressCodec.StringToBytes(req.SenderAddress)
if err != nil {
return nil, errorsmod.Wrap(err, "invalid sender address")
}
invalidity, found := q.k.GetInvalidity(ctx, req.MetadataUri, sender)
if !found {
return nil, types.ErrProofNotFound
}

return &types.QueryInvalidityResponse{Invalidity: invalidity}, nil
}

func (q queryServer) AllInvalidity(goCtx context.Context, req *types.QueryAllInvalidityRequest) (*types.QueryAllInvalidityResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "invalid request")
}
ctx := sdk.UnwrapSDKContext(goCtx)

return &types.QueryAllInvalidityResponse{Invalidity: q.k.GetAllInvalidities(ctx)}, nil
}
6 changes: 3 additions & 3 deletions x/da/keeper/store_invalidity.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,23 @@ import (
"github.com/sunriselayer/sunrise/x/da/types"
)

func (k Keeper) GetInvalidity(ctx context.Context, metadataUri string, sender []byte) (data types.Invalidity) {
func (k Keeper) GetInvalidity(ctx context.Context, metadataUri string, sender []byte) (invalidity types.Invalidity, found bool) {
key := collections.Join(metadataUri, sender)
has, err := k.Invalidities.Has(ctx, key)
if err != nil {
panic(err)
}

if !has {
return data
return invalidity, false
}

val, err := k.Invalidities.Get(ctx, key)
if err != nil {
panic(err)
}

return val
return val, true
}

// SetInvalidity set the Invalidity of the PublishedData
Expand Down
6 changes: 3 additions & 3 deletions x/da/keeper/store_proof.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,23 @@ import (
"github.com/sunriselayer/sunrise/x/da/types"
)

func (k Keeper) GetProof(ctx context.Context, metadataUri string, sender []byte) (data types.Proof) {
func (k Keeper) GetProof(ctx context.Context, metadataUri string, sender []byte) (proof types.Proof, found bool) {
key := collections.Join(metadataUri, sender)
has, err := k.Proofs.Has(ctx, key)
if err != nil {
panic(err)
}

if !has {
return data
return proof, false
}

val, err := k.Proofs.Get(ctx, key)
if err != nil {
panic(err)
}

return val
return val, true
}

// SetProof set the proof of the PublishedData
Expand Down
2 changes: 2 additions & 0 deletions x/da/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,6 @@ var (
ErrDataNotFound = errors.Register(ModuleName, 1110, "published data not found")
ErrDeputyNotFound = errors.Register(ModuleName, 1111, "proof deputy not found")
ErrInvalidDeputy = errors.Register(ModuleName, 1112, "invalid proof deputy")
ErrProofNotFound = errors.Register(ModuleName, 1113, "validity proof not found")
ErrInvalidityNotFound = errors.Register(ModuleName, 1114, "invalidity not found")
)

0 comments on commit 3dd103d

Please sign in to comment.