diff --git a/cmd/canined/file_server.go b/cmd/canined/file_server.go index 7d1622581..678cb0f6d 100644 --- a/cmd/canined/file_server.go +++ b/cmd/canined/file_server.go @@ -223,6 +223,7 @@ func (q *UploadQueue) makeContract(cmd *cobra.Command, args []string, wg *sync.W Message: msg, Callback: wg, Err: nil, + Response: nil, } k := &u @@ -344,7 +345,7 @@ func StartFileServer(cmd *cobra.Command) { handler := cors.Default().Handler(router) - go postProofs(cmd, db) + go postProofs(cmd, db, &q) go q.startListener(clientCtx, cmd) go q.checkStrays(clientCtx, cmd, db) diff --git a/cmd/canined/proofs.go b/cmd/canined/proofs.go index 4c374cf85..a5ed783c4 100644 --- a/cmd/canined/proofs.go +++ b/cmd/canined/proofs.go @@ -8,6 +8,7 @@ import ( "io" "os" "strconv" + "sync" "time" sdk "github.com/cosmos/cosmos-sdk/types" @@ -88,7 +89,7 @@ func CreateMerkleForProof(cmd *cobra.Command, filename string, index int) (strin } -func postProof(cmd *cobra.Command, cid string, block string, db *leveldb.DB) (*sdk.TxResponse, error) { +func postProof(cmd *cobra.Command, cid string, block string, db *leveldb.DB, queue *UploadQueue) (*sdk.TxResponse, error) { clientCtx, err := client.GetClientTxContext(cmd) if err != nil { return nil, err @@ -119,15 +120,23 @@ func postProof(cmd *cobra.Command, cid string, block string, db *leveldb.DB) (*s return nil, err } - res, err := SendTx(clientCtx, cmd.Flags(), msg) - if err != nil { - return nil, err + var wg sync.WaitGroup + wg.Add(1) + + u := Upload{ + Message: msg, + Err: nil, + Callback: &wg, + Response: nil, } - return res, nil + queue.append(&u) + wg.Wait() + + return u.Response, u.Err } -func postProofs(cmd *cobra.Command, db *leveldb.DB) { +func postProofs(cmd *cobra.Command, db *leveldb.DB, queue *UploadQueue) { debug, err := cmd.Flags().GetBool("debug") if err != nil { return @@ -216,7 +225,7 @@ func postProofs(cmd *cobra.Command, db *leveldb.DB) { continue } - res, err := postProof(cmd, cid, block, db) + res, err := postProof(cmd, cid, block, db, queue) if err != nil { fmt.Printf("Posting Error: %s\n", err.Error()) continue @@ -229,6 +238,9 @@ func postProofs(cmd *cobra.Command, db *leveldb.DB) { } iter.Release() err = iter.Error() + if err != nil { + fmt.Printf("Iterator Error: %s\n", err.Error()) + } time.Sleep(time.Duration(interval) * time.Second) } diff --git a/cmd/canined/queue.go b/cmd/canined/queue.go index 60e5d4dc8..fd5b863c1 100644 --- a/cmd/canined/queue.go +++ b/cmd/canined/queue.go @@ -15,6 +15,10 @@ import ( ctypes "github.com/cosmos/cosmos-sdk/types" ) +func (q *UploadQueue) append(upload *Upload) { + q.Queue = append(q.Queue, upload) +} + func (q *UploadQueue) checkStrays(clientCtx client.Context, cmd *cobra.Command, db *leveldb.DB) { for { time.Sleep(time.Second) @@ -83,6 +87,7 @@ func (q *UploadQueue) checkStrays(clientCtx client.Context, cmd *cobra.Command, Message: msg, Callback: nil, Err: nil, + Response: nil, } q.Queue = append(q.Queue, &u) @@ -95,7 +100,7 @@ func (q *UploadQueue) checkStrays(clientCtx client.Context, cmd *cobra.Command, func (q *UploadQueue) startListener(clientCtx client.Context, cmd *cobra.Command) error { for { - time.Sleep(time.Second) + time.Sleep(time.Second * 2) if q.Locked { continue @@ -122,6 +127,8 @@ func (q *UploadQueue) startListener(clientCtx client.Context, cmd *cobra.Command } else { if res.Code != 0 { v.Err = fmt.Errorf(res.RawLog) + } else { + v.Response = res } } v.Callback.Done() diff --git a/cmd/canined/types.go b/cmd/canined/types.go index 6fbc63b01..3c966f872 100644 --- a/cmd/canined/types.go +++ b/cmd/canined/types.go @@ -4,6 +4,7 @@ import ( "sync" "github.com/cosmos/cosmos-sdk/types" + sdk "github.com/cosmos/cosmos-sdk/types" ) const MaxFileSize = 32 << 30 @@ -41,6 +42,7 @@ type Upload struct { Message types.Msg Callback *sync.WaitGroup Err error + Response *sdk.TxResponse } type UploadQueue struct { diff --git a/x/storage/client/cli/tx_active_deals.go b/x/storage/client/cli/tx_active_deals.go deleted file mode 100644 index 98654b750..000000000 --- a/x/storage/client/cli/tx_active_deals.go +++ /dev/null @@ -1,134 +0,0 @@ -package cli - -import ( - "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/client/flags" - "github.com/cosmos/cosmos-sdk/client/tx" - "github.com/jackal-dao/canine/x/storage/types" - "github.com/spf13/cobra" -) - -func CmdCreateActiveDeals() *cobra.Command { - cmd := &cobra.Command{ - Use: "create-active-deals [cid] [signee] [provider] [startblock] [endblock] [filesize] [proofverified] [proofsmissed] [blocktoprove]", - Short: "Create a new active_deals", - Args: cobra.ExactArgs(9), - RunE: func(cmd *cobra.Command, args []string) (err error) { - // Get indexes - indexCid := args[0] - - // Get value arguments - argSignee := args[1] - argProvider := args[2] - argStartblock := args[3] - argEndblock := args[4] - argFilesize := args[5] - argProofverified := args[6] - argProofsmissed := args[7] - argBlocktoprove := args[8] - - clientCtx, err := client.GetClientTxContext(cmd) - if err != nil { - return err - } - - msg := types.NewMsgCreateActiveDeals( - clientCtx.GetFromAddress().String(), - indexCid, - argSignee, - argProvider, - argStartblock, - argEndblock, - argFilesize, - argProofverified, - argProofsmissed, - argBlocktoprove, - ) - if err := msg.ValidateBasic(); err != nil { - return err - } - return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) - }, - } - - flags.AddTxFlagsToCmd(cmd) - - return cmd -} - -func CmdUpdateActiveDeals() *cobra.Command { - cmd := &cobra.Command{ - Use: "update-active-deals [cid] [signee] [provider] [startblock] [endblock] [filesize] [proofverified] [proofsmissed] [blocktoprove]", - Short: "Update a active_deals", - Args: cobra.ExactArgs(9), - RunE: func(cmd *cobra.Command, args []string) (err error) { - // Get indexes - indexCid := args[0] - - // Get value arguments - argSignee := args[1] - argProvider := args[2] - argStartblock := args[3] - argEndblock := args[4] - argFilesize := args[5] - argProofverified := args[6] - argProofsmissed := args[7] - argBlocktoprove := args[8] - - clientCtx, err := client.GetClientTxContext(cmd) - if err != nil { - return err - } - - msg := types.NewMsgUpdateActiveDeals( - clientCtx.GetFromAddress().String(), - indexCid, - argSignee, - argProvider, - argStartblock, - argEndblock, - argFilesize, - argProofverified, - argProofsmissed, - argBlocktoprove, - ) - if err := msg.ValidateBasic(); err != nil { - return err - } - return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) - }, - } - - flags.AddTxFlagsToCmd(cmd) - - return cmd -} - -func CmdDeleteActiveDeals() *cobra.Command { - cmd := &cobra.Command{ - Use: "delete-active-deals [cid]", - Short: "Delete a active_deals", - Args: cobra.ExactArgs(1), - RunE: func(cmd *cobra.Command, args []string) (err error) { - indexCid := args[0] - - clientCtx, err := client.GetClientTxContext(cmd) - if err != nil { - return err - } - - msg := types.NewMsgDeleteActiveDeals( - clientCtx.GetFromAddress().String(), - indexCid, - ) - if err := msg.ValidateBasic(); err != nil { - return err - } - return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) - }, - } - - flags.AddTxFlagsToCmd(cmd) - - return cmd -} diff --git a/x/storage/client/cli/tx_active_deals_test.go b/x/storage/client/cli/tx_active_deals_test.go deleted file mode 100644 index da7949a81..000000000 --- a/x/storage/client/cli/tx_active_deals_test.go +++ /dev/null @@ -1,189 +0,0 @@ -package cli_test - -import ( - "fmt" - "strconv" - "testing" - - "github.com/cosmos/cosmos-sdk/client/flags" - clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" - sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - "github.com/stretchr/testify/require" - - "github.com/jackal-dao/canine/testutil/network" - "github.com/jackal-dao/canine/x/storage/client/cli" -) - -// Prevent strconv unused error -var _ = strconv.IntSize - -func TestCreateActiveDeals(t *testing.T) { - net := network.New(t) - val := net.Validators[0] - ctx := val.ClientCtx - - fields := []string{"xyz", "xyz", "xyz", "xyz", "xyz", "xyz", "xyz", "xyz"} - for _, tc := range []struct { - desc string - idCid string - - args []string - err error - code uint32 - }{ - { - idCid: strconv.Itoa(0), - - desc: "valid", - args: []string{ - fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address.String()), - fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), - fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock), - fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(net.Config.BondDenom, sdk.NewInt(10))).String()), - }, - }, - } { - tc := tc - t.Run(tc.desc, func(t *testing.T) { - args := []string{ - tc.idCid, - } - args = append(args, fields...) - args = append(args, tc.args...) - out, err := clitestutil.ExecTestCLICmd(ctx, cli.CmdCreateActiveDeals(), args) - if tc.err != nil { - require.ErrorIs(t, err, tc.err) - } else { - require.NoError(t, err) - var resp sdk.TxResponse - require.NoError(t, ctx.Codec.UnmarshalJSON(out.Bytes(), &resp)) - require.Equal(t, tc.code, resp.Code) - } - }) - } -} - -func TestUpdateActiveDeals(t *testing.T) { - net := network.New(t) - val := net.Validators[0] - ctx := val.ClientCtx - - fields := []string{"xyz", "xyz", "xyz", "xyz", "xyz", "xyz", "xyz", "xyz"} - common := []string{ - fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address.String()), - fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), - fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock), - fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(net.Config.BondDenom, sdk.NewInt(10))).String()), - } - args := []string{ - "0", - } - args = append(args, fields...) - args = append(args, common...) - _, err := clitestutil.ExecTestCLICmd(ctx, cli.CmdCreateActiveDeals(), args) - require.NoError(t, err) - - for _, tc := range []struct { - desc string - idCid string - - args []string - code uint32 - err error - }{ - { - desc: "valid", - idCid: strconv.Itoa(0), - - args: common, - }, - { - desc: "key not found", - idCid: strconv.Itoa(100000), - - args: common, - code: sdkerrors.ErrKeyNotFound.ABCICode(), - }, - } { - tc := tc - t.Run(tc.desc, func(t *testing.T) { - args := []string{ - tc.idCid, - } - args = append(args, fields...) - args = append(args, tc.args...) - out, err := clitestutil.ExecTestCLICmd(ctx, cli.CmdUpdateActiveDeals(), args) - if tc.err != nil { - require.ErrorIs(t, err, tc.err) - } else { - require.NoError(t, err) - var resp sdk.TxResponse - require.NoError(t, ctx.Codec.UnmarshalJSON(out.Bytes(), &resp)) - require.Equal(t, tc.code, resp.Code) - } - }) - } -} - -func TestDeleteActiveDeals(t *testing.T) { - net := network.New(t) - - val := net.Validators[0] - ctx := val.ClientCtx - - fields := []string{"xyz", "xyz", "xyz", "xyz", "xyz", "xyz", "xyz", "xyz"} - common := []string{ - fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address.String()), - fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), - fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock), - fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(net.Config.BondDenom, sdk.NewInt(10))).String()), - } - args := []string{ - "0", - } - args = append(args, fields...) - args = append(args, common...) - _, err := clitestutil.ExecTestCLICmd(ctx, cli.CmdCreateActiveDeals(), args) - require.NoError(t, err) - - for _, tc := range []struct { - desc string - idCid string - - args []string - code uint32 - err error - }{ - { - desc: "valid", - idCid: strconv.Itoa(0), - - args: common, - }, - { - desc: "key not found", - idCid: strconv.Itoa(100000), - - args: common, - code: sdkerrors.ErrKeyNotFound.ABCICode(), - }, - } { - tc := tc - t.Run(tc.desc, func(t *testing.T) { - args := []string{ - tc.idCid, - } - args = append(args, tc.args...) - out, err := clitestutil.ExecTestCLICmd(ctx, cli.CmdDeleteActiveDeals(), args) - if tc.err != nil { - require.ErrorIs(t, err, tc.err) - } else { - require.NoError(t, err) - var resp sdk.TxResponse - require.NoError(t, ctx.Codec.UnmarshalJSON(out.Bytes(), &resp)) - require.Equal(t, tc.code, resp.Code) - } - }) - } -} diff --git a/x/storage/client/cli/tx_contracts.go b/x/storage/client/cli/tx_contracts.go index c15f72da9..417440879 100644 --- a/x/storage/client/cli/tx_contracts.go +++ b/x/storage/client/cli/tx_contracts.go @@ -51,76 +51,3 @@ func CmdCreateContracts() *cobra.Command { return cmd } - -func CmdUpdateContracts() *cobra.Command { - cmd := &cobra.Command{ - Use: "update-contracts [cid] [chunks] [merkle] [signee] [duration] [filesize] [fid]", - Short: "Update a contracts", - Args: cobra.ExactArgs(7), - RunE: func(cmd *cobra.Command, args []string) (err error) { - // Get indexes - indexCid := args[0] - - // Get value arguments - argChunks := args[1] - argMerkle := args[2] - argSignee := args[3] - argDuration := args[4] - argFilesize := args[5] - argFid := args[6] - - clientCtx, err := client.GetClientTxContext(cmd) - if err != nil { - return err - } - - msg := types.NewMsgUpdateContracts( - clientCtx.GetFromAddress().String(), - indexCid, - argChunks, - argMerkle, - argSignee, - argDuration, - argFilesize, - argFid, - ) - if err := msg.ValidateBasic(); err != nil { - return err - } - return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) - }, - } - - flags.AddTxFlagsToCmd(cmd) - - return cmd -} - -func CmdDeleteContracts() *cobra.Command { - cmd := &cobra.Command{ - Use: "delete-contracts [cid]", - Short: "Delete a contracts", - Args: cobra.ExactArgs(1), - RunE: func(cmd *cobra.Command, args []string) (err error) { - indexCid := args[0] - - clientCtx, err := client.GetClientTxContext(cmd) - if err != nil { - return err - } - - msg := types.NewMsgDeleteContracts( - clientCtx.GetFromAddress().String(), - indexCid, - ) - if err := msg.ValidateBasic(); err != nil { - return err - } - return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) - }, - } - - flags.AddTxFlagsToCmd(cmd) - - return cmd -} diff --git a/x/storage/client/cli/tx_contracts_test.go b/x/storage/client/cli/tx_contracts_test.go index ce1359423..d4170f835 100644 --- a/x/storage/client/cli/tx_contracts_test.go +++ b/x/storage/client/cli/tx_contracts_test.go @@ -8,7 +8,6 @@ import ( "github.com/cosmos/cosmos-sdk/client/flags" clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/stretchr/testify/require" "github.com/jackal-dao/canine/testutil/network" @@ -63,127 +62,3 @@ func TestCreateContracts(t *testing.T) { }) } } - -func TestUpdateContracts(t *testing.T) { - net := network.New(t) - val := net.Validators[0] - ctx := val.ClientCtx - - fields := []string{"xyz", "xyz", "xyz", "xyz", "xyz", "xyz", "xyz", "xyz"} - common := []string{ - fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address.String()), - fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), - fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock), - fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(net.Config.BondDenom, sdk.NewInt(10))).String()), - } - args := []string{ - "0", - } - args = append(args, fields...) - args = append(args, common...) - _, err := clitestutil.ExecTestCLICmd(ctx, cli.CmdCreateContracts(), args) - require.NoError(t, err) - - for _, tc := range []struct { - desc string - idCid string - - args []string - code uint32 - err error - }{ - { - desc: "valid", - idCid: strconv.Itoa(0), - - args: common, - }, - { - desc: "key not found", - idCid: strconv.Itoa(100000), - - args: common, - code: sdkerrors.ErrKeyNotFound.ABCICode(), - }, - } { - tc := tc - t.Run(tc.desc, func(t *testing.T) { - args := []string{ - tc.idCid, - } - args = append(args, fields...) - args = append(args, tc.args...) - out, err := clitestutil.ExecTestCLICmd(ctx, cli.CmdUpdateContracts(), args) - if tc.err != nil { - require.ErrorIs(t, err, tc.err) - } else { - require.NoError(t, err) - var resp sdk.TxResponse - require.NoError(t, ctx.Codec.UnmarshalJSON(out.Bytes(), &resp)) - require.Equal(t, tc.code, resp.Code) - } - }) - } -} - -func TestDeleteContracts(t *testing.T) { - net := network.New(t) - - val := net.Validators[0] - ctx := val.ClientCtx - - fields := []string{"xyz", "xyz", "xyz", "xyz", "xyz", "xyz", "xyz", "xyz"} - common := []string{ - fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address.String()), - fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), - fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock), - fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(net.Config.BondDenom, sdk.NewInt(10))).String()), - } - args := []string{ - "0", - } - args = append(args, fields...) - args = append(args, common...) - _, err := clitestutil.ExecTestCLICmd(ctx, cli.CmdCreateContracts(), args) - require.NoError(t, err) - - for _, tc := range []struct { - desc string - idCid string - - args []string - code uint32 - err error - }{ - { - desc: "valid", - idCid: strconv.Itoa(0), - - args: common, - }, - { - desc: "key not found", - idCid: strconv.Itoa(100000), - - args: common, - code: sdkerrors.ErrKeyNotFound.ABCICode(), - }, - } { - tc := tc - t.Run(tc.desc, func(t *testing.T) { - args := []string{ - tc.idCid, - } - args = append(args, tc.args...) - out, err := clitestutil.ExecTestCLICmd(ctx, cli.CmdDeleteContracts(), args) - if tc.err != nil { - require.ErrorIs(t, err, tc.err) - } else { - require.NoError(t, err) - var resp sdk.TxResponse - require.NoError(t, ctx.Codec.UnmarshalJSON(out.Bytes(), &resp)) - require.Equal(t, tc.code, resp.Code) - } - }) - } -} diff --git a/x/storage/keeper/msg_server_active_deals.go b/x/storage/keeper/msg_server_active_deals.go deleted file mode 100644 index 638563354..000000000 --- a/x/storage/keeper/msg_server_active_deals.go +++ /dev/null @@ -1,101 +0,0 @@ -package keeper - -import ( - "context" - - sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - "github.com/jackal-dao/canine/x/storage/types" -) - -func (k msgServer) CreateActiveDeals(goCtx context.Context, msg *types.MsgCreateActiveDeals) (*types.MsgCreateActiveDealsResponse, error) { - ctx := sdk.UnwrapSDKContext(goCtx) - - // Check if the value already exists - _, isFound := k.GetActiveDeals( - ctx, - msg.Cid, - ) - if isFound { - return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "index already set") - } - - var activeDeals = types.ActiveDeals{ - Creator: msg.Creator, - Cid: msg.Cid, - Signee: msg.Signee, - Provider: msg.Provider, - Startblock: msg.Startblock, - Endblock: msg.Endblock, - Filesize: msg.Filesize, - Proofverified: msg.Proofverified, - Proofsmissed: msg.Proofsmissed, - Blocktoprove: msg.Blocktoprove, - } - - k.SetActiveDeals( - ctx, - activeDeals, - ) - return &types.MsgCreateActiveDealsResponse{}, nil -} - -func (k msgServer) UpdateActiveDeals(goCtx context.Context, msg *types.MsgUpdateActiveDeals) (*types.MsgUpdateActiveDealsResponse, error) { - ctx := sdk.UnwrapSDKContext(goCtx) - - // Check if the value exists - valFound, isFound := k.GetActiveDeals( - ctx, - msg.Cid, - ) - if !isFound { - return nil, sdkerrors.Wrap(sdkerrors.ErrKeyNotFound, "index not set") - } - - // Checks if the the msg creator is the same as the current owner - if msg.Creator != valFound.Creator { - return nil, sdkerrors.Wrap(sdkerrors.ErrUnauthorized, "incorrect owner") - } - - var activeDeals = types.ActiveDeals{ - Creator: msg.Creator, - Cid: msg.Cid, - Signee: msg.Signee, - Provider: msg.Provider, - Startblock: msg.Startblock, - Endblock: msg.Endblock, - Filesize: msg.Filesize, - Proofverified: msg.Proofverified, - Proofsmissed: msg.Proofsmissed, - Blocktoprove: msg.Blocktoprove, - } - - k.SetActiveDeals(ctx, activeDeals) - - return &types.MsgUpdateActiveDealsResponse{}, nil -} - -func (k msgServer) DeleteActiveDeals(goCtx context.Context, msg *types.MsgDeleteActiveDeals) (*types.MsgDeleteActiveDealsResponse, error) { - ctx := sdk.UnwrapSDKContext(goCtx) - - // Check if the value exists - valFound, isFound := k.GetActiveDeals( - ctx, - msg.Cid, - ) - if !isFound { - return nil, sdkerrors.Wrap(sdkerrors.ErrKeyNotFound, "index not set") - } - - // Checks if the the msg creator is the same as the current owner - if msg.Creator != valFound.Creator { - return nil, sdkerrors.Wrap(sdkerrors.ErrUnauthorized, "incorrect owner") - } - - k.RemoveActiveDeals( - ctx, - msg.Cid, - ) - - return &types.MsgDeleteActiveDealsResponse{}, nil -} diff --git a/x/storage/keeper/msg_server_contracts.go b/x/storage/keeper/msg_server_contracts.go index 6b0406b39..e2838e865 100644 --- a/x/storage/keeper/msg_server_contracts.go +++ b/x/storage/keeper/msg_server_contracts.go @@ -38,60 +38,3 @@ func (k msgServer) CreateContracts(goCtx context.Context, msg *types.MsgCreateCo ) return &types.MsgCreateContractsResponse{}, nil } - -func (k msgServer) UpdateContracts(goCtx context.Context, msg *types.MsgUpdateContracts) (*types.MsgUpdateContractsResponse, error) { - ctx := sdk.UnwrapSDKContext(goCtx) - - // Check if the value exists - valFound, isFound := k.GetContracts( - ctx, - msg.Cid, - ) - if !isFound { - return nil, sdkerrors.Wrap(sdkerrors.ErrKeyNotFound, "index not set") - } - - // Checks if the the msg creator is the same as the current owner - if msg.Creator != valFound.Creator { - return nil, sdkerrors.Wrap(sdkerrors.ErrUnauthorized, "incorrect owner") - } - - var contracts = types.Contracts{ - Creator: msg.Creator, - Cid: msg.Cid, - Merkle: msg.Merkle, - Signee: msg.Signee, - Duration: msg.Duration, - Filesize: msg.Filesize, - Fid: msg.Fid, - } - - k.SetContracts(ctx, contracts) - - return &types.MsgUpdateContractsResponse{}, nil -} - -func (k msgServer) DeleteContracts(goCtx context.Context, msg *types.MsgDeleteContracts) (*types.MsgDeleteContractsResponse, error) { - ctx := sdk.UnwrapSDKContext(goCtx) - - // Check if the value exists - valFound, isFound := k.GetContracts( - ctx, - msg.Cid, - ) - if !isFound { - return nil, sdkerrors.Wrap(sdkerrors.ErrKeyNotFound, "index not set") - } - - // Checks if the the msg creator is the same as the current owner - if msg.Creator != valFound.Creator { - return nil, sdkerrors.Wrap(sdkerrors.ErrUnauthorized, "incorrect owner") - } - - k.RemoveContracts( - ctx, - msg.Cid, - ) - - return &types.MsgDeleteContractsResponse{}, nil -}