Skip to content

Commit

Permalink
Urgent 1.1.0 rc (#66)
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMarstonConnell authored Oct 24, 2022
2 parents 1a02fef + 97ce869 commit ea7fd0b
Show file tree
Hide file tree
Showing 13 changed files with 780 additions and 111 deletions.
1 change: 0 additions & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,6 @@ type WasmApp struct {
DsigKeeper dsigmodulekeeper.Keeper
FileTreeKeeper filetreemodulekeeper.Keeper


NotificationsKeeper notificationsmodulekeeper.Keeper

// the module manager
Expand Down
2 changes: 1 addition & 1 deletion config.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
accounts:
- name: alice
coins: ["200000000ujkl", "100000000ujwl"]
coins: ["2000000000ujkl", "100000000ujwl"]
mnemonic: "across business friend enact find light myself pistol stick place oil anchor deny orient sudden educate flame proud crash panel right aisle found connect"
- name: bob
coins: ["100000000ujkl"]
Expand Down
50 changes: 50 additions & 0 deletions docs/static/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37168,6 +37168,47 @@ paths:
type: string
tags:
- Query
'/jackal-dao/canine/storage/get_pay_data/{address}':
get:
summary: Queries a list of GetPayData items.
operationId: JackaldaoCanineStorageGetPayData
responses:
'200':
description: A successful response.
schema:
type: object
properties:
blocks_remaining:
type: string
format: int64
bytes:
type: string
format: int64
default:
description: An unexpected error response.
schema:
type: object
properties:
code:
type: integer
format: int32
message:
type: string
details:
type: array
items:
type: object
properties:
'@type':
type: string
additionalProperties: {}
parameters:
- name: address
in: path
required: true
type: string
tags:
- Query
/jackal-dao/canine/storage/params:
get:
summary: Parameters queries the parameters of the module.
Expand Down Expand Up @@ -62323,6 +62364,15 @@ definitions:
type: string
blocknum:
type: string
jackaldao.canine.storage.QueryGetPayDataResponse:
type: object
properties:
blocks_remaining:
type: string
format: int64
bytes:
type: string
format: int64
jackaldao.canine.storage.QueryGetProofsResponse:
type: object
properties:
Expand Down
14 changes: 14 additions & 0 deletions proto/storage/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ service Query {
option (google.api.http).get = "/jackal-dao/canine/storage/fid_cid";
}

// Queries a list of GetPayData items.
rpc GetPayData(QueryGetPayDataRequest) returns (QueryGetPayDataResponse) {
option (google.api.http).get = "/jackal-dao/canine/storage/get_pay_data/{address}";
}

// this line is used by starport scaffolding # 2
}

Expand Down Expand Up @@ -299,4 +304,13 @@ message QueryAllFidCidResponse {
cosmos.base.query.v1beta1.PageResponse pagination = 2;
}

message QueryGetPayDataRequest {
string address = 1;
}

message QueryGetPayDataResponse {
int64 blocks_remaining = 1;
int64 bytes = 2;
}

// this line is used by starport scaffolding # 3
2 changes: 2 additions & 0 deletions x/storage/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ func GetQueryCmd(queryRoute string) *cobra.Command {

cmd.AddCommand(CmdListFidCid())
cmd.AddCommand(CmdShowFidCid())
cmd.AddCommand(CmdGetPayData())

// this line is used by starport scaffolding # 1

return cmd
Expand Down
46 changes: 46 additions & 0 deletions x/storage/client/cli/query_get_pay_data.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package cli

import (
"strconv"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/jackal-dao/canine/x/storage/types"
"github.com/spf13/cobra"
)

var _ = strconv.Itoa(0)

func CmdGetPayData() *cobra.Command {
cmd := &cobra.Command{
Use: "get-pay-data [address]",
Short: "get all payment info from account",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) (err error) {
reqAddress := args[0]

clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}

queryClient := types.NewQueryClient(clientCtx)

params := &types.QueryGetPayDataRequest{

Address: reqAddress,
}

res, err := queryClient.GetPayData(cmd.Context(), params)
if err != nil {
return err
}

return clientCtx.PrintProto(res)
},
}

flags.AddQueryFlagsToCmd(cmd)

return cmd
}
2 changes: 1 addition & 1 deletion x/storage/keeper/grpc_query_get_client_free_space.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (k Keeper) GetClientFreeSpace(goCtx context.Context, req *types.QueryGetCli
return nil, fmt.Errorf("cannot parse client usage")
}

paid := k.GetPaidAmount(ctx, req.Address, ctx.BlockHeight())
paid, _, _ := k.GetPaidAmount(ctx, req.Address, ctx.BlockHeight())

if paid < usage.Int64() {
return nil, fmt.Errorf("paid amount cannot be smaller than usage")
Expand Down
31 changes: 31 additions & 0 deletions x/storage/keeper/grpc_query_get_pay_data.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package keeper

import (
"context"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/jackal-dao/canine/x/storage/types"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)

func (k Keeper) GetPayData(goCtx context.Context, req *types.QueryGetPayDataRequest) (*types.QueryGetPayDataResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "invalid request")
}

ctx := sdk.UnwrapSDKContext(goCtx)

paid, _, block := k.GetPaidAmount(ctx, req.Address, ctx.BlockHeight())
blocks := ctx.BlockHeight()
if block != nil {
bnum, ok := sdk.NewIntFromString(block.Blocknum)
if ok {
blocks = bnum.Int64()
}
}

blocks = blocks - ctx.BlockHeight()

return &types.QueryGetPayDataResponse{BlocksRemaining: blocks, Bytes: paid}, nil
}
18 changes: 16 additions & 2 deletions x/storage/keeper/msg_server_buy_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"fmt"

sdk "github.com/cosmos/cosmos-sdk/types"
sdkerr "github.com/cosmos/cosmos-sdk/types/errors"

"github.com/jackal-dao/canine/x/storage/types"
)

Expand All @@ -22,13 +24,25 @@ func (k msgServer) BuyStorage(goCtx context.Context, msg *types.MsgBuyStorage) (
}

denom := msg.PaymentDenom
if denom != "ujkl" {
return nil, sdkerr.Wrap(sdkerr.ErrInvalidCoins, "cannot pay with anything other than ujkl")
}

var gb int64 = 1000000000

gbs := bytes.Int64() / gb
if gbs == 0 {
return nil, fmt.Errorf("cannot buy less than a gb")
}
price := sdk.NewCoin(denom, sdk.NewInt(gbs*8000))

monthInBlocks := 432000
dr := duration.Int64() - (duration.Int64() % int64(monthInBlocks))

if dr <= 0 {
return nil, fmt.Errorf("cannot buy less than a month")
}

price := sdk.NewCoin(denom, sdk.NewInt(gbs*4000*(dr/int64(monthInBlocks))))
add, err := sdk.AccAddressFromBech32(msg.Creator)
if err != nil {
return nil, err
Expand All @@ -38,7 +52,7 @@ func (k msgServer) BuyStorage(goCtx context.Context, msg *types.MsgBuyStorage) (
return nil, err
}

err = k.CreatePayBlock(ctx, msg.ForAddress, duration.Int64(), bytes.Int64())
err = k.CreatePayBlock(ctx, msg.ForAddress, dr, bytes.Int64())

if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion x/storage/keeper/msg_server_post_contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func (k msgServer) PostContract(goCtx context.Context, msg *types.MsgPostContrac
return nil, fmt.Errorf("not enough space on provider")
}

paidAMT := k.GetPaidAmount(ctx, msg.Signee, ctx.BlockHeight())
paidAMT, _, _ := k.GetPaidAmount(ctx, msg.Signee, ctx.BlockHeight())

if paidAMT <= 0 {
return nil, fmt.Errorf("user has not paid for any storage")
Expand Down
34 changes: 22 additions & 12 deletions x/storage/keeper/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const (
TWO_GIGS = 2000000000
)

func (k Keeper) GetPaidAmount(ctx sdk.Context, address string, blockh int64) int64 {
func (k Keeper) GetPaidAmount(ctx sdk.Context, address string, blockh int64) (int64, bool, *types.PayBlocks) {

store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.PayBlocksKeyPrefix))

Expand All @@ -37,16 +37,22 @@ func (k Keeper) GetPaidAmount(ctx sdk.Context, address string, blockh int64) int

eblock, found := k.GetPayBlocks(ctx, fmt.Sprintf(".%s", address))
if !found {
return TWO_GIGS
return TWO_GIGS, true, nil
}

endblock, ok := sdk.NewIntFromString(eblock.Blocknum)
if !ok {
return TWO_GIGS
return TWO_GIGS, true, nil
}

if endblock.Int64() <= blockh {
return TWO_GIGS
if endblock.Int64() <= blockh+432000 {
bytes, ok := sdk.NewIntFromString(eblock.Bytes)
if !ok {
return bytes.Int64(), true, nil
}
}
return TWO_GIGS, true, &eblock
}

for ; iterator.Valid(); iterator.Next() {
Expand All @@ -59,6 +65,11 @@ func (k Keeper) GetPaidAmount(ctx sdk.Context, address string, blockh int64) int
continue
}

adr := val.Blockid[:42]
if adr != address {
continue
}

blocknum, ok := sdk.NewIntFromString(val.Blocknum)
if !ok {
continue
Expand All @@ -70,27 +81,26 @@ func (k Keeper) GetPaidAmount(ctx sdk.Context, address string, blockh int64) int

if blocknum.Int64() > highestBlock {
highestBlock = blocknum.Int64()
fmt.Printf("NEW HIGHEST BLOCK: %s", val.Blocknum)

ctx.Logger().Debug(fmt.Sprintf("NEW HIGHEST BLOCK: %s", val.Blocknum))
}

}

if highestBlock == 0 {
return TWO_GIGS
return TWO_GIGS, true, &eblock
}

hblock, found := k.GetPayBlocks(ctx, fmt.Sprintf("%s%d", address, highestBlock))
if !found {
return TWO_GIGS
return TWO_GIGS, true, &eblock
}

bytes, ok := sdk.NewIntFromString(hblock.Bytes)
if !ok {
return TWO_GIGS
return TWO_GIGS, true, &eblock
}

return bytes.Int64()
return bytes.Int64(), false, &eblock
}

func (k Keeper) CreatePayBlock(ctx sdk.Context, address string, length int64, bytes int64) error {
Expand All @@ -113,9 +123,9 @@ func (k Keeper) CreatePayBlock(ctx sdk.Context, address string, length int64, by
Blocknum: fmt.Sprintf("%d", endBlock),
}

paidamt := k.GetPaidAmount(ctx, address, endBlock)
amount, trial, _ := k.GetPaidAmount(ctx, address, startBlock)

if paidamt > 0 {
if !trial && bytes <= amount {
return fmt.Errorf("can't buy storage within another storage window")
}

Expand Down
Loading

0 comments on commit ea7fd0b

Please sign in to comment.