Skip to content
This repository was archived by the owner on Jun 18, 2025. It is now read-only.

Commit 129df05

Browse files
authored
Merge branch 'develop' into refactor/remove-deprecated-rest
2 parents d6afa83 + d55fd30 commit 129df05

File tree

18 files changed

+117
-71
lines changed

18 files changed

+117
-71
lines changed

localnet/spn/node1/data/priv_validator_state.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
"height": "0",
33
"round": 0,
44
"step": 0
5-
}
5+
}

localnet/spn/node2/data/priv_validator_state.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
"height": "0",
33
"round": 0,
44
"step": 0
5-
}
5+
}

localnet/spn/node3/data/priv_validator_state.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
"height": "0",
33
"round": 0,
44
"step": 0
5-
}
5+
}

x/campaign/keeper/mainnet_account.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
func (k Keeper) SetMainnetAccount(ctx sdk.Context, mainnetAccount types.MainnetAccount) {
1212
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.MainnetAccountKeyPrefix))
1313
b := k.cdc.MustMarshal(&mainnetAccount)
14-
store.Set(types.MainnetAccountKey(
14+
store.Set(types.AccountKeyPath(
1515
mainnetAccount.CampaignID,
1616
mainnetAccount.Address,
1717
), b)
@@ -25,7 +25,7 @@ func (k Keeper) GetMainnetAccount(
2525
) (val types.MainnetAccount, found bool) {
2626
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.MainnetAccountKeyPrefix))
2727

28-
b := store.Get(types.MainnetAccountKey(campaignID, address))
28+
b := store.Get(types.AccountKeyPath(campaignID, address))
2929
if b == nil {
3030
return val, false
3131
}
@@ -41,7 +41,7 @@ func (k Keeper) RemoveMainnetAccount(
4141
address string,
4242
) {
4343
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.MainnetAccountKeyPrefix))
44-
store.Delete(types.MainnetAccountKey(
44+
store.Delete(types.AccountKeyPath(
4545
campaignID,
4646
address,
4747
))

x/campaign/keeper/msg_mint_vouchers.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,11 @@ func (k msgServer) MintVouchers(goCtx context.Context, msg *types.MsgMintVoucher
3535

3636
// Increase the campaign shares
3737
campaign.AllocatedShares = types.IncreaseShares(campaign.AllocatedShares, msg.Shares)
38-
if types.IsTotalSharesReached(campaign.AllocatedShares, k.GetTotalShares(ctx)) {
38+
reached, err := types.IsTotalSharesReached(campaign.AllocatedShares, k.GetTotalShares(ctx))
39+
if err != nil {
40+
return nil, spnerrors.Criticalf("verified shares are invalid %s", err.Error())
41+
}
42+
if reached {
3943
return nil, sdkerrors.Wrapf(types.ErrTotalSharesLimit, "%d", msg.CampaignID)
4044
}
4145

x/campaign/keeper/msg_update_special_allocations.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,12 @@ func (k msgServer) UpdateSpecialAllocations(goCtx context.Context, msg *types.Ms
5454
// increase with new special allocations
5555
campaign.AllocatedShares = types.IncreaseShares(campaign.AllocatedShares, msg.SpecialAllocations.TotalShares())
5656

57-
// check total is not reached
58-
if types.IsTotalSharesReached(campaign.AllocatedShares, k.GetTotalShares(ctx)) {
57+
// increase the campaign shares
58+
reached, err := types.IsTotalSharesReached(campaign.AllocatedShares, k.GetTotalShares(ctx))
59+
if err != nil {
60+
return nil, spnerrors.Criticalf("verified shares are invalid %s", err.Error())
61+
}
62+
if reached {
5963
return nil, sdkerrors.Wrapf(types.ErrTotalSharesLimit, "%d", msg.CampaignID)
6064
}
6165

x/campaign/types/campaign.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,12 @@ func (m Campaign) Validate(totalShareNumber uint64) error {
4242
if !m.TotalSupply.IsValid() {
4343
return errors.New("invalid total supply")
4444
}
45-
if !sdk.Coins(m.AllocatedShares).IsValid() {
46-
return errors.New("invalid allocated shares")
47-
}
4845

49-
if IsTotalSharesReached(m.AllocatedShares, totalShareNumber) {
46+
reached, err := IsTotalSharesReached(m.AllocatedShares, totalShareNumber)
47+
if err != nil {
48+
return errors.Wrap(err, "invalid allocated shares")
49+
}
50+
if reached {
5051
return errors.New("more allocated shares than total shares")
5152
}
5253

x/campaign/types/campaign_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ func TestCampaign_Validate(t *testing.T) {
5252
totalSharesReached.AllocatedShares = campaign.NewSharesFromCoins(sdk.NewCoins(
5353
sdk.NewCoin("foo", sdk.NewInt(spntypes.TotalShareNumber+1)),
5454
))
55-
require.True(t, campaign.IsTotalSharesReached(totalSharesReached.AllocatedShares, spntypes.TotalShareNumber))
55+
reached, err := campaign.IsTotalSharesReached(totalSharesReached.AllocatedShares, spntypes.TotalShareNumber)
56+
require.NoError(t, err)
57+
require.True(t, reached)
5658

5759
invalidSpecialAllocations := campaign.NewSpecialAllocations(
5860
sample.Shares(r),

x/campaign/types/genesis.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func (gs GenesisState) Validate() error {
5858
return fmt.Errorf("campaign id %d doesn't exist for mainnet account %s",
5959
elem.CampaignID, elem.Address)
6060
}
61-
index := string(MainnetAccountKey(elem.CampaignID, elem.Address))
61+
index := string(AccountKeyPath(elem.CampaignID, elem.Address))
6262
if _, ok := mainnetAccountIndexMap[index]; ok {
6363
return fmt.Errorf("duplicated index for mainnetAccount")
6464
}

x/campaign/types/keys.go

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ func CampaignChainsKey(campaignID uint64) []byte {
4646
return append(spntypes.UintBytes(campaignID), byte('/'))
4747
}
4848

49-
// MainnetAccountKey returns the store key to retrieve a MainnetAccount from the index fields
50-
func MainnetAccountKey(campaignID uint64, address string) []byte {
49+
// AccountKeyPath returns the store key path without prefix for an account defined by a campaign ID and an address
50+
func AccountKeyPath(campaignID uint64, address string) []byte {
5151
campaignIDBytes := append(spntypes.UintBytes(campaignID), byte('/'))
5252
addressBytes := append([]byte(address), byte('/'))
5353
return append(campaignIDBytes, addressBytes...)
@@ -60,13 +60,6 @@ func MainnetAccountAllKey(campaignID uint64) []byte {
6060
return append(prefixBytes, campaignIDBytes...)
6161
}
6262

63-
// MainnetVestingAccountKey returns the store key to retrieve a MainnetVestingAccount from the index fields
64-
func MainnetVestingAccountKey(campaignID uint64, address string) []byte {
65-
campaignIDBytes := append(spntypes.UintBytes(campaignID), byte('/'))
66-
addressBytes := append([]byte(address), byte('/'))
67-
return append(campaignIDBytes, addressBytes...)
68-
}
69-
7063
// MainnetVestingAccountAllKey returns the store key to retrieve all MainnetVestingAccount by campaign id
7164
func MainnetVestingAccountAllKey(campaignID uint64) []byte {
7265
prefixBytes := []byte(MainnetVestingAccountKeyPrefix)

0 commit comments

Comments
 (0)