Skip to content

Commit

Permalink
refactor & optimise code (#143)
Browse files Browse the repository at this point in the history
* refactor code

* lint fix
  • Loading branch information
harish551 authored Feb 5, 2024
1 parent 10cf452 commit f579e4f
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 188 deletions.
32 changes: 0 additions & 32 deletions ignite.ci.yml

This file was deleted.

11 changes: 1 addition & 10 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,6 @@ wget -q -O - https://git.io/vQhTU | bash -s -- --version 1.21.3

**Linux**

### Before v2 upgrade
```
git clone https://github.com/Omniflix/omniflixhub.git
cd omniflixhub
git checkout v0.12.1
go mod tidy
make install
```

### After v2 upgrade
```
git clone https://github.com/Omniflix/omniflixhub.git
cd omniflixhub
Expand Down Expand Up @@ -83,6 +73,7 @@ curl https://raw.githubusercontent.com/OmniFlix/mainnet/main/omniflixhub-1/genes
- [v0.11.0](https://github.com/OmniFlix/docs/blob/main/guides/mainnet/omniflixhub-1/upgrades/v0.11.0-upgrade.md) at block 7339200
- [v0.12.x](https://github.com/OmniFlix/docs/blob/main/guides/mainnet/omniflixhub-1/upgrades/v0.12.x-upgrade.md) at block 8054200
- [v2](https://github.com/OmniFlix/docs/blob/main/guides/mainnet/omniflixhub-1/upgrades/v2-upgrade.md) at block 10428200
- [v2.1]((https://github.com/OmniFlix/docs/blob/main/guides/mainnet/omniflixhub-1/upgrades/v2.1-upgrade.md)) at block 10678600

### Testnets

Expand Down
6 changes: 3 additions & 3 deletions x/itc/keeper/itc.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,9 @@ func (k Keeper) FinalizeAndEndCampaigns(ctx sdk.Context) error {
func (k Keeper) endCampaign(ctx sdk.Context, campaign types.Campaign) {
// Transfer Remaining funds to creator
availableTokens := campaign.AvailableTokens
moduleAccAddr := k.accountKeeper.GetModuleAddress(types.ModuleName)
if availableTokens.IsValid() && availableTokens.Amount != sdk.ZeroInt() {
if err := k.bankKeeper.SendCoinsFromModuleToAccount(ctx,
types.ModuleName, campaign.GetCreator(),
if err := k.bankKeeper.SendCoins(ctx, moduleAccAddr, campaign.GetCreator(),
sdk.NewCoins(sdk.NewCoin(availableTokens.Denom, availableTokens.Amount))); err != nil {
panic(err)
}
Expand All @@ -191,7 +191,7 @@ func (k Keeper) endCampaign(ctx sdk.Context, campaign types.Campaign) {
err := k.nftKeeper.TransferOwnership(ctx,
campaign.NftDenomId,
nft,
k.GetModuleAccountAddress(ctx),
moduleAccAddr,
campaign.GetCreator(),
)
if err != nil {
Expand Down
15 changes: 7 additions & 8 deletions x/marketplace/keeper/auction.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,8 @@ func (k Keeper) processBid(ctx sdk.Context, auction types.AuctionListing, bid ty
}
BidAmountCoin := bid.Amount
auctionSaleAmountCoin := BidAmountCoin
err = k.nftKeeper.TransferOwnership(ctx, auction.GetDenomId(), auction.GetNftId(),
k.accountKeeper.GetModuleAddress(types.ModuleName), bid.GetBidder())
moduleAccAddr := k.accountKeeper.GetModuleAddress(types.ModuleName)
err = k.nftKeeper.TransferOwnership(ctx, auction.GetDenomId(), auction.GetNftId(), moduleAccAddr, bid.GetBidder())
if err != nil {
return err
}
Expand Down Expand Up @@ -308,7 +308,7 @@ func (k Keeper) processBid(ctx sdk.Context, auction types.AuctionListing, bid ty
sharePortionCoin := k.GetProportions(auctionSaleAmountCoin, share.Weight)
sharePortionCoins := sdk.NewCoins(sharePortionCoin)
if share.Address == "" {
err = k.bankKeeper.SendCoinsFromModuleToAccount(ctx, types.ModuleName, owner, sharePortionCoins)
err = k.bankKeeper.SendCoins(ctx, moduleAccAddr, owner, sharePortionCoins)
if err != nil {
return err
}
Expand All @@ -317,21 +317,20 @@ func (k Keeper) processBid(ctx sdk.Context, auction types.AuctionListing, bid ty
if err != nil {
return err
}
err = k.bankKeeper.SendCoinsFromModuleToAccount(
ctx, types.ModuleName, saleSplitAddr, sharePortionCoins)
err = k.bankKeeper.SendCoins(ctx, moduleAccAddr, saleSplitAddr, sharePortionCoins)
if err != nil {
return err
}
k.createSplitShareTransferEvent(ctx, k.accountKeeper.GetModuleAddress(types.ModuleName), saleSplitAddr, sharePortionCoin)
k.createSplitShareTransferEvent(ctx, moduleAccAddr, saleSplitAddr, sharePortionCoin)
}
remaining = remaining.Sub(sharePortionCoin)
}
err = k.bankKeeper.SendCoinsFromModuleToAccount(ctx, types.ModuleName, owner, sdk.NewCoins(remaining))
err = k.bankKeeper.SendCoins(ctx, moduleAccAddr, owner, sdk.NewCoins(remaining))
if err != nil {
return err
}
} else {
err = k.bankKeeper.SendCoinsFromModuleToAccount(ctx, types.ModuleName, owner, sdk.NewCoins(remaining))
err = k.bankKeeper.SendCoins(ctx, moduleAccAddr, owner, sdk.NewCoins(remaining))
if err != nil {
return err
}
Expand Down
54 changes: 30 additions & 24 deletions x/marketplace/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,13 @@ func (k Keeper) Buy(ctx sdk.Context, listing types.Listing, buyer sdk.AccAddress
if err != nil {
return err
}
moduleAccAddr := k.accountKeeper.GetModuleAddress(types.ModuleName)

err = k.bankKeeper.SendCoinsFromAccountToModule(ctx, buyer, types.ModuleName, sdk.NewCoins(listingPriceCoin))
err = k.bankKeeper.SendCoins(ctx, buyer, moduleAccAddr, sdk.NewCoins(listingPriceCoin))
if err != nil {
return err
}
err = k.nftKeeper.TransferOwnership(ctx, listing.GetDenomId(), listing.GetNftId(),
k.accountKeeper.GetModuleAddress(types.ModuleName), buyer)
err = k.nftKeeper.TransferOwnership(ctx, listing.GetDenomId(), listing.GetNftId(), moduleAccAddr, buyer)
if err != nil {
return err
}
Expand Down Expand Up @@ -156,7 +156,7 @@ func (k Keeper) Buy(ctx sdk.Context, listing types.Listing, buyer sdk.AccAddress
sharePortionCoin := k.GetProportions(listingSaleAmountCoin, share.Weight)
sharePortionCoins := sdk.NewCoins(sharePortionCoin)
if share.Address == "" {
err = k.bankKeeper.SendCoinsFromModuleToAccount(ctx, types.ModuleName, owner, sharePortionCoins)
err = k.bankKeeper.SendCoins(ctx, moduleAccAddr, owner, sharePortionCoins)
if err != nil {
return err
}
Expand All @@ -165,21 +165,20 @@ func (k Keeper) Buy(ctx sdk.Context, listing types.Listing, buyer sdk.AccAddress
if err != nil {
return err
}
err = k.bankKeeper.SendCoinsFromModuleToAccount(
ctx, types.ModuleName, saleSplitAddr, sharePortionCoins)
err = k.bankKeeper.SendCoins(ctx, moduleAccAddr, saleSplitAddr, sharePortionCoins)
if err != nil {
return err
}
k.createSplitShareTransferEvent(ctx, k.accountKeeper.GetModuleAddress(types.ModuleName), saleSplitAddr, sharePortionCoin)
k.createSplitShareTransferEvent(ctx, moduleAccAddr, saleSplitAddr, sharePortionCoin)
}
remaining = remaining.Sub(sharePortionCoin)
}
err = k.bankKeeper.SendCoinsFromModuleToAccount(ctx, types.ModuleName, owner, sdk.NewCoins(remaining))
err = k.bankKeeper.SendCoins(ctx, moduleAccAddr, owner, sdk.NewCoins(remaining))
if err != nil {
return err
}
} else {
err = k.bankKeeper.SendCoinsFromModuleToAccount(ctx, types.ModuleName, owner, sdk.NewCoins(remaining))
err = k.bankKeeper.SendCoins(ctx, moduleAccAddr, owner, sdk.NewCoins(remaining))
if err != nil {
return err
}
Expand All @@ -196,14 +195,16 @@ func (k Keeper) GetProportions(totalCoin sdk.Coin, ratio sdk.Dec) sdk.Coin {
func (k Keeper) DistributeCommission(ctx sdk.Context, marketplaceCoin sdk.Coin) error {
distrParams := k.GetMarketplaceDistributionParams(ctx)
stakingCommissionCoin := k.GetProportions(marketplaceCoin, distrParams.Staking)
moduleAccAddr := k.accountKeeper.GetModuleAddress(types.ModuleName)
feeCollectorAddr := k.accountKeeper.GetModuleAddress(authtypes.FeeCollectorName)
if distrParams.Staking.GT(sdk.ZeroDec()) && stakingCommissionCoin.Amount.GT(sdk.ZeroInt()) {
err := k.bankKeeper.SendCoinsFromModuleToModule(ctx, types.ModuleName, authtypes.FeeCollectorName, sdk.NewCoins(stakingCommissionCoin))
err := k.bankKeeper.SendCoins(ctx, moduleAccAddr, feeCollectorAddr, sdk.NewCoins(stakingCommissionCoin))
if err != nil {
return err
}
k.createSaleCommissionTransferEvent(ctx,
k.accountKeeper.GetModuleAddress(types.ModuleName),
k.accountKeeper.GetModuleAddress(authtypes.FeeCollectorName),
moduleAccAddr,
feeCollectorAddr,
stakingCommissionCoin,
)
marketplaceCoin = marketplaceCoin.Sub(stakingCommissionCoin)
Expand All @@ -213,13 +214,13 @@ func (k Keeper) DistributeCommission(ctx sdk.Context, marketplaceCoin sdk.Coin)
err := k.distributionKeeper.FundCommunityPool(
ctx,
sdk.NewCoins(communityPoolCommissionCoin),
k.accountKeeper.GetModuleAddress(types.ModuleName),
moduleAccAddr,
)
if err != nil {
return err
}
k.createSaleCommissionTransferEvent(ctx,
k.accountKeeper.GetModuleAddress(types.ModuleName),
moduleAccAddr,
k.accountKeeper.GetModuleAddress("distribution"),
communityPoolCommissionCoin,
)
Expand Down Expand Up @@ -289,15 +290,19 @@ func (k Keeper) PlaceBid(ctx sdk.Context, auction types.AuctionListing, newBid t
return errorsmod.Wrapf(types.ErrBidAmountNotEnough,
"cannot place bid for given auction %d, required amount to bid is %s", auction.Id, newBidPrice.String())
}
moduleAccAddr := k.accountKeeper.GetModuleAddress(types.ModuleName)

// Transfer amount from bidder to module account
err := k.bankKeeper.SendCoinsFromAccountToModule(ctx, newBid.GetBidder(), types.ModuleName, sdk.NewCoins(newBid.Amount))
err := k.bankKeeper.SendCoins(ctx, newBid.GetBidder(), moduleAccAddr, sdk.NewCoins(newBid.Amount))
if err != nil {
return err
}
// Release previous Bid
if bidExists {
_ = k.bankKeeper.SendCoinsFromModuleToAccount(ctx, types.ModuleName, prevBid.GetBidder(), sdk.NewCoins(prevBid.Amount))
err = k.bankKeeper.SendCoins(ctx, moduleAccAddr, prevBid.GetBidder(), sdk.NewCoins(prevBid.Amount))
if err != nil {
return err
}
k.RemoveBid(ctx, prevBid.AuctionId)
}
// Set new bid
Expand All @@ -318,6 +323,7 @@ func (k Keeper) TransferRoyalty(
) error {
// if royalty splits configured, distributing royalty
// else sending royalty to collection creator
moduleAcc := k.accountKeeper.GetModuleAddress(types.ModuleName)
if len(royaltyReceivers) > 0 {
remaining := nftRoyaltyShareCoin
for _, share := range royaltyReceivers {
Expand All @@ -326,34 +332,34 @@ func (k Keeper) TransferRoyalty(
royaltySplitAddr, err := sdk.AccAddressFromBech32(share.Address)
if err != nil {
// ignoring error and sending royalty to creator
if err := k.bankKeeper.SendCoinsFromModuleToAccount(ctx, types.ModuleName, creator, sharePortionCoins); err != nil {
if err := k.bankKeeper.SendCoins(ctx, moduleAcc, creator, sharePortionCoins); err != nil {
return err
}
k.createRoyaltyShareTransferEvent(ctx, k.accountKeeper.GetModuleAddress(types.ModuleName), creator, sharePortionCoin)
k.createRoyaltyShareTransferEvent(ctx, moduleAcc, creator, sharePortionCoin)
} else {
err = k.bankKeeper.SendCoinsFromModuleToAccount(ctx, types.ModuleName, royaltySplitAddr, sharePortionCoins)
err = k.bankKeeper.SendCoins(ctx, moduleAcc, royaltySplitAddr, sharePortionCoins)
if err != nil {
return err
}
k.createRoyaltyShareTransferEvent(ctx, k.accountKeeper.GetModuleAddress(types.ModuleName), royaltySplitAddr, sharePortionCoin)
k.createRoyaltyShareTransferEvent(ctx, moduleAcc, royaltySplitAddr, sharePortionCoin)
}

remaining = remaining.Sub(sharePortionCoin)
}
// sending remaining to creator
if remaining.Amount.GT(sdk.ZeroInt()) {
err := k.bankKeeper.SendCoinsFromModuleToAccount(ctx, types.ModuleName, creator, sdk.NewCoins(remaining))
err := k.bankKeeper.SendCoins(ctx, moduleAcc, creator, sdk.NewCoins(remaining))
if err != nil {
return err
}
k.createRoyaltyShareTransferEvent(ctx, k.accountKeeper.GetModuleAddress(types.ModuleName), creator, nftRoyaltyShareCoin)
k.createRoyaltyShareTransferEvent(ctx, moduleAcc, creator, nftRoyaltyShareCoin)
}
} else {
err := k.bankKeeper.SendCoinsFromModuleToAccount(ctx, types.ModuleName, creator, sdk.NewCoins(nftRoyaltyShareCoin))
err := k.bankKeeper.SendCoins(ctx, moduleAcc, creator, sdk.NewCoins(nftRoyaltyShareCoin))
if err != nil {
return err
}
k.createRoyaltyShareTransferEvent(ctx, k.accountKeeper.GetModuleAddress(types.ModuleName), creator, nftRoyaltyShareCoin)
k.createRoyaltyShareTransferEvent(ctx, moduleAcc, creator, nftRoyaltyShareCoin)
}
return nil
}
Loading

0 comments on commit f579e4f

Please sign in to comment.