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

fix: Redefine connection method and data type of some fields #261

Merged
merged 1 commit into from
Jan 28, 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
4 changes: 2 additions & 2 deletions proto/panacea/market/v2/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ message DataValidationCertificate {
// UnsignedDataValidationCertificate defines unsigned data validation certificate.
message UnsignedDataValidationCertificate {
uint64 deal_id = 1;
string data_hash = 2;
string encrypted_data_url = 3;
bytes data_hash = 2;
bytes encrypted_data_url = 3;
string data_validator_address = 4;
string requester_address = 5;
}
14 changes: 7 additions & 7 deletions x/market/client/cli/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ type sellDataInputs struct {
}

type DataValidationCertification struct {
UnsignedCert UnsignedDataValidationCertification `json:"unsigned_cert"`
Signature []byte `json:"signature"`
UnsignedCert UnsignedDataValidationCertification `json:"unsigned_cert"`
SignatureBase64 string `json:"signature_base64"`
}

type UnsignedDataValidationCertification struct {
DealId uint64 `json:"deal_id"`
DataHash string `json:"data_hash"`
EncryptedDataUrl string `json:"encrypted_data_url"`
DataValidatorAddress string `json:"data_validator_address"`
RequesterAddress string `json:"requester_address"`
DealId uint64 `json:"deal_id"`
DataHashBase64 string `json:"data_hash_base64"`
EncryptedDataUrlBase64 string `json:"encrypted_data_url_base64"`
DataValidatorAddress string `json:"data_validator_address"`
RequesterAddress string `json:"requester_address"`
}
22 changes: 19 additions & 3 deletions x/market/client/cli/txDeal.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cli

import (
"bytes"
"encoding/base64"
"encoding/json"
"fmt"
"github.com/cosmos/cosmos-sdk/client"
Expand Down Expand Up @@ -119,17 +120,32 @@ func NewSellDataMsg(clientCtx client.Context, txf tx.Factory, fs *flag.FlagSet)
return txf, nil, fmt.Errorf("failed to parse data certificate file: %w", err)
}

encryptedDataUrlBytes, err := base64.URLEncoding.DecodeString(sellData.Cert.UnsignedCert.EncryptedDataUrlBase64)
if err != nil {
return txf, nil, err
}

dataHashBytes, err := base64.StdEncoding.DecodeString(sellData.Cert.UnsignedCert.DataHashBase64)
if err != nil {
return txf, nil, err
}

unSigned := types.UnsignedDataValidationCertificate{
DealId: sellData.Cert.UnsignedCert.DealId,
DataHash: sellData.Cert.UnsignedCert.DataHash,
EncryptedDataUrl: sellData.Cert.UnsignedCert.EncryptedDataUrl,
DataHash: dataHashBytes,
EncryptedDataUrl: encryptedDataUrlBytes,
DataValidatorAddress: sellData.Cert.UnsignedCert.DataValidatorAddress,
RequesterAddress: sellData.Cert.UnsignedCert.RequesterAddress,
}

signatureBytes, err := base64.StdEncoding.DecodeString(sellData.Cert.SignatureBase64)
if err != nil {
return txf, nil, err
}

signed := types.DataValidationCertificate{
UnsignedCert: &unSigned,
Signature: sellData.Cert.Signature,
Signature: signatureBytes,
}

msg := types.NewMsgSellData(signed, clientCtx.GetFromAddress().String())
Expand Down
4 changes: 2 additions & 2 deletions x/market/keeper/deal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,8 @@ func makeTestDeal() types.Deal {
func makeTestCert() types.DataValidationCertificate {
uCert := types.UnsignedDataValidationCertificate{
DealId: 2,
DataHash: "1a312c123x23",
EncryptedDataUrl: "https://panacea.org/a/123.json",
DataHash: []byte("1a312c123x23"),
EncryptedDataUrl: []byte("https://panacea.org/a/123.json"),
DataValidatorAddress: newAddr.String(),
RequesterAddress: acc3.String(),
}
Expand Down
5 changes: 2 additions & 3 deletions x/market/types/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,9 @@ func GetKeyPrefixDeals(dealId uint64) []byte {
return append(KeyPrefixDeals, sdk.Uint64ToBigEndian(dealId)...)
}

func GetKeyPrefixCertificate(dealId uint64, dataHash string) []byte {
func GetKeyPrefixCertificate(dealId uint64, dataHash []byte) []byte {
beDealId := sdk.Uint64ToBigEndian(dealId)
dataHashBytes := []byte(dataHash)
keys := CombineKeys(beDealId, dataHashBytes)
keys := CombineKeys(beDealId, dataHash)
return append(KeyPrefixDataCertificateStore, keys...)
}

Expand Down
4 changes: 2 additions & 2 deletions x/market/types/message_deal.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,11 @@ func (msg *MsgSellData) ValidateBasic() error {
return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "invalid deal id format")
}

if unsignedCert.DataHash == "" {
if unsignedCert.DataHash == nil {
return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "empty data hash")
}

if unsignedCert.EncryptedDataUrl == "" {
if unsignedCert.EncryptedDataUrl == nil {
return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "empty encrypted data url")
}

Expand Down
114 changes: 59 additions & 55 deletions x/market/types/tx.pb.go

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