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

refactor: shortening the name DataValidationCertificate to DataCert #340

Merged
merged 5 commits into from
Jun 2, 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
2 changes: 1 addition & 1 deletion proto/panacea/datadeal/v2/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ import "panacea/datadeal/v2/tx.proto";
// GenesisState defines the datadeal module's genesis state.
message GenesisState {
map<uint64, Deal> deals = 1 [(gogoproto.nullable) = false];
map<string, DataValidationCertificate> data_certificates = 2 [(gogoproto.nullable) = false];
map<string, DataCert> data_certs = 2 [(gogoproto.nullable) = false];
uint64 next_deal_number = 3;
}
12 changes: 6 additions & 6 deletions proto/panacea/datadeal/v2/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ message MsgCreateDealResponse {

//MsgSellData defines the Msg/SellData request type.
message MsgSellData {
DataValidationCertificate cert = 1;
DataCert cert = 1;
string seller = 2;
}

Expand All @@ -43,14 +43,14 @@ message MsgSellDataResponse {
cosmos.base.v1beta1.Coin reward = 1;
}

// DataValidationCertificate defines data validation certificate.
message DataValidationCertificate {
UnsignedDataValidationCertificate unsigned_cert = 1;
// DataCert defines data validation certificate.
message DataCert {
UnsignedDataCert unsigned_cert = 1;
bytes signature = 2;
}

// UnsignedDataValidationCertificate defines unsigned data validation certificate.
message UnsignedDataValidationCertificate {
// UnsignedDataCert defines unsigned data validation certificate.
message UnsignedDataCert {
uint64 deal_id = 1;
bytes data_hash = 2;
bytes encrypted_data_url = 3;
Expand Down
12 changes: 6 additions & 6 deletions proto/panacea/datapool/v2/pool.proto
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ message Pool {
]; // curator commission rate
}

// DataValidationCertificate defines the certificate for data validation w/ oracle signature.
message DataValidationCertificate {
UnsignedDataValidationCertificate unsigned_cert = 1; // unsigned certificate
bytes signature = 2; // signature for data validation by oracle
// DataCert defines the certificate for data validation w/ data oricle signature.
message DataCert {
UnsignedDataCert unsigned_cert = 1; // unsigned certificate
bytes signature = 2; // signature for data validation by data validator
}

// UnsignedDataValidationCertificate defines the unsigned certificate for data validation.
message UnsignedDataValidationCertificate {
// UnsignedDataCert defines the unsigned certificate for data validation.
message UnsignedDataCert {
uint64 pool_id = 1; // pool Id for selling data
uint64 round = 2; // Always 1 for v0
bytes data_hash = 3; // sha-256 hash of the data
Expand Down
16 changes: 8 additions & 8 deletions proto/panacea/datapool/v2/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ service Query {
option (google.api.http).get = "/panacea/datapool/v2/module_addr";
}

// DataValidationCertificates returns DataValidationCertificates
rpc DataValidationCertificates(QueryDataValidationCertificatesRequest) returns (QueryDataValidationCertificatesResponse) {
option (google.api.http).get = "/panacea/datapool/v2/data_validation_certificates/pool/{pool_id}/round/{round}";
// DataCert returns DataCerts
rpc DataCerts(QueryDataCertsRequest) returns (QueryDataCertsResponse) {
option (google.api.http).get = "/panacea/datapool/v2/data_certs/pool/{pool_id}/round/{round}";
}

// DataPassRedeemReceipt returns DataPassRedeemReceipt
Expand Down Expand Up @@ -88,16 +88,16 @@ message QueryDataPoolModuleAddrResponse {
string address = 1;
}

// QueryDataValidationCertificatesRequest is the request type for the Query/DataValidationCertificates RPC method.
message QueryDataValidationCertificatesRequest {
// QueryDataCertsRequest is the request type for the Query/DataCerts RPC method.
message QueryDataCertsRequest {
uint64 pool_id = 1;
uint64 round = 2;
cosmos.base.query.v1beta1.PageRequest pagination = 3;
}

// QueryDataValidationCertificatesResponse is the response type for the QueryDataValidationCertificates RPC method.
message QueryDataValidationCertificatesResponse {
repeated DataValidationCertificate data_validation_certificates = 1 [
// QueryDataCertsResponse is the response type for the Query/DataCerts RPC method.
message QueryDataCertsResponse {
repeated DataCert data_certs = 1 [
(gogoproto.nullable) = false
];
cosmos.base.query.v1beta1.PageResponse pagination = 2;
Expand Down
4 changes: 2 additions & 2 deletions proto/panacea/datapool/v2/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ message MsgCreatePoolResponse {

// MsgSellData defines the Msg/SellData request type.
message MsgSellData {
DataValidationCertificate cert = 1; // certificate for data validation
string seller = 2; // 'panacea1' address of seller
DataCert cert = 1; // certificate for data validation
string seller = 2; // 'panacea1' address of seller
}

// MsgSellDataResponse defines the Msg/SellData response type.
Expand Down
4 changes: 2 additions & 2 deletions x/datadeal/client/cli/txDeal.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,13 @@ func newCreateDealMsg(clientCtx client.Context, file string) (sdk.Msg, error) {
return msg, nil
}

func readDataCertFile(file string) (*types.DataValidationCertificate, error) {
func readDataCertFile(file string) (*types.DataCert, error) {
contents, err := ioutil.ReadFile(file)
if err != nil {
return nil, fmt.Errorf("failed to read file: %w", err)
}

var cert types.DataValidationCertificate
var cert types.DataCert

if err := json.Unmarshal(contents, &cert); err != nil {
return nil, err
Expand Down
10 changes: 5 additions & 5 deletions x/datadeal/client/cli/txDeal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ func TestReadDataCertFile(t *testing.T) {
require.Equal(t, parsedDataCert.UnsignedCert.GetRequesterAddress(), testCert.UnsignedCert.GetRequesterAddress())
}

func makeTestCert() types.DataValidationCertificate {
func makeTestCert() types.DataCert {

decodeDataHash, _ := base64.StdEncoding.DecodeString("ZGF0YUhhc2g=")
decodeURL, _ := base64.StdEncoding.DecodeString("ZW5jcnlwdGVkRGF0YVVSTA==")

unsignedDataValidationCertificate := types.UnsignedDataValidationCertificate{
unsignedDataCert := types.UnsignedDataCert{
DealId: 1,
DataHash: decodeDataHash,
EncryptedDataUrl: decodeURL,
Expand All @@ -35,10 +35,10 @@ func makeTestCert() types.DataValidationCertificate {
}

decodeSig, _ := base64.StdEncoding.DecodeString("c2lnbmF0dXJl")
dataValidationCertificate := types.DataValidationCertificate{
UnsignedCert: &unsignedDataValidationCertificate,
dataCert := types.DataCert{
UnsignedCert: &unsignedDataCert,
Signature: decodeSig,
}

return dataValidationCertificate
return dataCert
}
20 changes: 10 additions & 10 deletions x/datadeal/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState types.GenesisState)
k.SetDeal(ctx, deal)
}

for _, dataCertificate := range genState.DataCertificates {
k.SetDataCertificate(ctx, dataCertificate.UnsignedCert.DealId, dataCertificate)
for _, dataCert := range genState.DataCerts {
k.SetDataCert(ctx, dataCert.UnsignedCert.DealId, dataCert)
}
}

Expand All @@ -32,15 +32,15 @@ func ExportGenesis(ctx sdk.Context, k keeper.Keeper) *types.GenesisState {
dealsMap[deal.DealId] = deal
}

dataCertificates, err := k.ListDataCertificates(ctx)
dataCerts, err := k.ListDataCerts(ctx)
if err != nil {
panic(err)
}

dataCertificateMap := make(map[string]types.DataValidationCertificate)
for _, dataCertificate := range dataCertificates {
dataKey := types.GetKeyPrefixDataCertificate(dataCertificate.UnsignedCert.DealId, dataCertificate.UnsignedCert.DataHash)
dataCertificateMap[string(dataKey)] = dataCertificate
dataCertMap := make(map[string]types.DataCert)
for _, dataCert := range dataCerts {
dataKey := types.GetKeyPrefixDataCert(dataCert.UnsignedCert.DealId, dataCert.UnsignedCert.DataHash)
dataCertMap[string(dataKey)] = dataCert
}

nextDealNum, err := k.GetNextDealNumber(ctx)
Expand All @@ -49,8 +49,8 @@ func ExportGenesis(ctx sdk.Context, k keeper.Keeper) *types.GenesisState {
}

return &types.GenesisState{
Deals: dealsMap,
DataCertificates: dataCertificateMap,
NextDealNumber: nextDealNum,
Deals: dealsMap,
DataCerts: dataCertMap,
NextDealNumber: nextDealNum,
}
}
52 changes: 26 additions & 26 deletions x/datadeal/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ func (suite *genesisTestSuite) TestDataDealInitGenesis() {
newDeal := makeTestDeal()
newDataCert := makeTestDataCert()

dataCertificateKey := types.GetKeyPrefixDataCertificate(newDataCert.UnsignedCert.DealId, newDataCert.UnsignedCert.DataHash)
stringDataCertificateKey := string(dataCertificateKey)
dataCertKey := types.GetKeyPrefixDataCert(newDataCert.UnsignedCert.DealId, newDataCert.UnsignedCert.DataHash)
stringDataCertKey := string(dataCertKey)

datadeal.InitGenesis(suite.Ctx, suite.DataDealKeeper, types.GenesisState{
Deals: map[uint64]types.Deal{
newDeal.GetDealId(): newDeal,
},
DataCertificates: map[string]types.DataValidationCertificate{
stringDataCertificateKey: newDataCert,
DataCerts: map[string]types.DataCert{
stringDataCertKey: newDataCert,
},
NextDealNumber: 2,
})
Expand All @@ -63,29 +63,29 @@ func (suite *genesisTestSuite) TestDataDealInitGenesis() {
_, err = suite.DataDealKeeper.GetDeal(suite.Ctx, 2)
suite.Require().Error(err)

dataCertificateStored, err := suite.DataDealKeeper.GetDataCertificate(suite.Ctx, newDataCert)
dataCertStored, err := suite.DataDealKeeper.GetDataCert(suite.Ctx, newDataCert)
suite.Require().NoError(err)
suite.Require().Equal(newDataCert.GetSignature(), dataCertificateStored.GetSignature())
suite.Require().Equal(newDataCert.UnsignedCert.GetDealId(), dataCertificateStored.UnsignedCert.GetDealId())
suite.Require().Equal(newDataCert.UnsignedCert.GetDataHash(), dataCertificateStored.UnsignedCert.GetDataHash())
suite.Require().Equal(newDataCert.UnsignedCert.GetEncryptedDataUrl(), dataCertificateStored.UnsignedCert.GetEncryptedDataUrl())
suite.Require().Equal(newDataCert.UnsignedCert.GetOracleAddress(), dataCertificateStored.UnsignedCert.GetOracleAddress())
suite.Require().Equal(newDataCert.UnsignedCert.GetRequesterAddress(), dataCertificateStored.UnsignedCert.GetRequesterAddress())
suite.Require().Equal(newDataCert.GetSignature(), dataCertStored.GetSignature())
suite.Require().Equal(newDataCert.UnsignedCert.GetDealId(), dataCertStored.UnsignedCert.GetDealId())
suite.Require().Equal(newDataCert.UnsignedCert.GetDataHash(), dataCertStored.UnsignedCert.GetDataHash())
suite.Require().Equal(newDataCert.UnsignedCert.GetEncryptedDataUrl(), dataCertStored.UnsignedCert.GetEncryptedDataUrl())
suite.Require().Equal(newDataCert.UnsignedCert.GetOracleAddress(), dataCertStored.UnsignedCert.GetOracleAddress())
suite.Require().Equal(newDataCert.UnsignedCert.GetRequesterAddress(), dataCertStored.UnsignedCert.GetRequesterAddress())
}

func (suite *genesisTestSuite) TestDataDealExportGenesis() {
newDeal := makeTestDeal()
newDataCert := makeTestDataCert()

dataCertificateKey := types.GetKeyPrefixDataCertificate(newDataCert.UnsignedCert.DealId, newDataCert.UnsignedCert.DataHash)
stringDataCertificateKey := string(dataCertificateKey)
dataCertKey := types.GetKeyPrefixDataCert(newDataCert.UnsignedCert.DealId, newDataCert.UnsignedCert.DataHash)
stringDataCertKey := string(dataCertKey)

datadeal.InitGenesis(suite.Ctx, suite.DataDealKeeper, types.GenesisState{
Deals: map[uint64]types.Deal{
newDeal.GetDealId(): newDeal,
},
DataCertificates: map[string]types.DataValidationCertificate{
stringDataCertificateKey: newDataCert,
DataCerts: map[string]types.DataCert{
stringDataCertKey: newDataCert,
},
NextDealNumber: 2,
})
Expand All @@ -111,7 +111,7 @@ func (suite *genesisTestSuite) TestDataDealExportGenesis() {
genesis := datadeal.ExportGenesis(suite.Ctx, suite.DataDealKeeper)
suite.Require().Equal(genesis.NextDealNumber, uint64(3))
suite.Require().Len(genesis.Deals, 2)
suite.Require().Len(genesis.DataCertificates, 2)
suite.Require().Len(genesis.DataCerts, 2)
}

func makeTestDeal() types.Deal {
Expand All @@ -128,8 +128,8 @@ func makeTestDeal() types.Deal {
}
}

func makeTestDataCert() types.DataValidationCertificate {
uCert := types.UnsignedDataValidationCertificate{
func makeTestDataCert() types.DataCert {
uCert := types.UnsignedDataCert{
DealId: 2,
DataHash: []byte("1a312c123x23"),
EncryptedDataUrl: []byte("https://panacea.org/a/123.json"),
Expand All @@ -139,22 +139,22 @@ func makeTestDataCert() types.DataValidationCertificate {

marshal, err := uCert.Marshal()
if err != nil {
return types.DataValidationCertificate{}
return types.DataCert{}
}

sign, err := privKey.Sign(marshal)
if err != nil {
return types.DataValidationCertificate{}
return types.DataCert{}
}

return types.DataValidationCertificate{
return types.DataCert{
UnsignedCert: &uCert,
Signature: sign,
}
}

func makeTestDataCert2() types.DataValidationCertificate {
uCert := types.UnsignedDataValidationCertificate{
func makeTestDataCert2() types.DataCert {
uCert := types.UnsignedDataCert{
DealId: 2,
DataHash: []byte("1a312c1223x2fs3"),
EncryptedDataUrl: []byte("https://panacea.org/a/123.json"),
Expand All @@ -164,15 +164,15 @@ func makeTestDataCert2() types.DataValidationCertificate {

marshal, err := uCert.Marshal()
if err != nil {
return types.DataValidationCertificate{}
return types.DataCert{}
}

sign, err := privKey.Sign(marshal)
if err != nil {
return types.DataValidationCertificate{}
return types.DataCert{}
}

return types.DataValidationCertificate{
return types.DataCert{
UnsignedCert: &uCert,
Signature: sign,
}
Expand Down
Loading