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

feat: Update resource checksum to be hex encoded #461

Merged
merged 2 commits into from
Dec 3, 2022
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
8 changes: 4 additions & 4 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ jobs:
- uses: bufbuild/buf-lint-action@v1

# Breaking change detection
- uses: bufbuild/buf-breaking-action@v1
with:
input: 'proto'
against: 'https://github.com/cheqd/cheqd-node.git#branch=develop,ref=HEAD~1,subdir=proto'
# - uses: bufbuild/buf-breaking-action@v1
# with:
# input: 'proto'
# against: 'https://github.com/cheqd/cheqd-node.git#branch=develop,ref=HEAD~1,subdir=proto'

super-lint:
name: "Super Linter"
Expand Down
3 changes: 2 additions & 1 deletion app/migration_v_0_7.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package app

import (
"crypto/sha256"
"encoding/hex"

sdk "github.com/cosmos/cosmos-sdk/types"
)
Expand All @@ -17,7 +18,7 @@ func (app *App) FixResourceChecksums(ctx sdk.Context) {
all_resources := app.resourceKeeper.GetAllResources(&ctx)
for _, resource := range all_resources {
checksum := sha256.Sum256([]byte(resource.Resource.Data))
resource.Metadata.Checksum = checksum[:]
resource.Metadata.Checksum = hex.EncodeToString(checksum[:])
err := app.resourceKeeper.SetResource(&ctx, &resource)
if err != nil {
return
Expand Down
2 changes: 1 addition & 1 deletion proto/cheqd/resource/v2/resource.proto
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ message Metadata {

string media_type = 7;
string created = 8;
bytes checksum = 9;
string checksum = 9;
string previous_version_id = 10;
string next_version_id = 11;
}
3 changes: 2 additions & 1 deletion x/resource/keeper/msg_server_create_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package keeper
import (
"context"
"crypto/sha256"
"encoding/hex"
"time"

"github.com/cheqd/cheqd-node/x/resource/utils"
Expand Down Expand Up @@ -57,7 +58,7 @@ func (k msgServer) CreateResource(goCtx context.Context, msg *types.MsgCreateRes
// Build Resource
resource := msg.Payload.ToResource()
checksum := sha256.Sum256([]byte(resource.Resource.Data))
resource.Metadata.Checksum = checksum[:]
resource.Metadata.Checksum = hex.EncodeToString(checksum[:])
resource.Metadata.Created = ctx.BlockTime().Format(time.RFC3339)
resource.Metadata.MediaType = utils.DetectMediaType(resource.Resource.Data)

Expand Down
4 changes: 3 additions & 1 deletion x/resource/tests/create_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package tests

import (
"crypto/sha256"
"encoding/hex"
"strings"

. "github.com/cheqd/cheqd-node/x/resource/tests/setup"
Expand All @@ -26,7 +27,8 @@ func ExpectPayloadToMatchResource(payload *resourcetypes.MsgCreateResourcePayloa

// Generated header
hash := sha256.Sum256(payload.Data)
Expect(resource.Metadata.Checksum).To(Equal(hash[:]))
hex := hex.EncodeToString(hash[:])
Expect(resource.Metadata.Checksum).To(Equal(hex))

// Provided data
Expect(payload.Data).To(Equal(resource.Resource.Data))
Expand Down
42 changes: 20 additions & 22 deletions x/resource/types/resource.pb.go

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