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

feat(launch): default chain account balances #936

Merged
merged 19 commits into from
Sep 1, 2022
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go 1.18
require (
cosmossdk.io/errors v1.0.0-beta.7
cosmossdk.io/math v1.0.0-beta.3
github.com/cosmos/cosmos-proto v1.0.0-alpha7
github.com/cosmos/cosmos-sdk v0.46.1
github.com/cosmos/ibc-go/v5 v5.0.0-rc0
github.com/gogo/protobuf v1.3.3
Expand All @@ -14,7 +15,6 @@ require (
github.com/grpc-ecosystem/grpc-gateway v1.16.0
github.com/ignite/modules v0.0.0-20220830145312-d006783a7a21
github.com/pkg/errors v0.9.1
github.com/regen-network/cosmos-proto v0.3.1
github.com/spf13/cast v1.5.0
github.com/spf13/cobra v1.5.0
github.com/spf13/pflag v1.0.5
Expand All @@ -25,7 +25,6 @@ require (
golang.org/x/tools v0.1.12
google.golang.org/genproto v0.0.0-20220822174746-9e6da59bd2fc
google.golang.org/grpc v1.48.0
google.golang.org/protobuf v1.28.1
gopkg.in/yaml.v2 v2.4.0
mvdan.cc/gofumpt v0.3.1
)
Expand Down Expand Up @@ -73,7 +72,6 @@ require (
github.com/coinbase/rosetta-sdk-go v0.7.9 // indirect
github.com/confio/ics23/go v0.7.0 // indirect
github.com/cosmos/btcutil v1.0.4 // indirect
github.com/cosmos/cosmos-proto v1.0.0-alpha7 // indirect
github.com/cosmos/go-bip39 v1.0.0 // indirect
github.com/cosmos/gorocksdb v1.2.0 // indirect
github.com/cosmos/iavl v0.19.1 // indirect
Expand Down Expand Up @@ -212,6 +210,7 @@ require (
github.com/quasilyte/stdinfo v0.0.0-20220114132959-f7386bf02567 // indirect
github.com/rakyll/statik v0.1.7 // indirect
github.com/rcrowley/go-metrics v0.0.0-20200313005456-10cdbea86bc0 // indirect
github.com/regen-network/cosmos-proto v0.3.1 // indirect
github.com/rs/cors v1.8.2 // indirect
github.com/rs/zerolog v1.27.0 // indirect
github.com/ryancurrah/gomodguard v1.2.4 // indirect
Expand Down Expand Up @@ -270,6 +269,7 @@ require (
golang.org/x/xerrors v0.0.0-20220609144429-65e65417b02f // indirect
google.golang.org/api v0.84.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/ini.v1 v1.66.6 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
honnef.co/go/tools v0.3.3 // indirect
Expand Down
2 changes: 1 addition & 1 deletion pkg/types/monitoring.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 11 additions & 1 deletion proto/launch/chain.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ syntax = "proto3";
package tendermint.spn.launch;

import "gogoproto/gogo.proto";
import "cosmos/base/v1beta1/coin.proto";

option go_package = "github.com/tendermint/spn/x/launch/types";

Expand All @@ -27,7 +28,16 @@ message Chain {

bool monitoringConnected = 14;

bytes metadata = 15;
// account balance is the balance given to approved accounts
// for this chain. If not set, the balances used will be those
// contained in the requests
repeated cosmos.base.v1beta1.Coin accountBalance = 15 [
(gogoproto.nullable) = false,
(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.Coin",
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"
];

bytes metadata = 16;
}

message InitialGenesis {
Expand Down
33 changes: 19 additions & 14 deletions proto/launch/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -29,27 +29,32 @@ service Msg {
}

message MsgCreateChain {
string coordinator = 1;
string genesisChainID = 2;
string sourceURL = 3;
string sourceHash = 4;
string genesisURL = 5;
string genesisHash = 6;
bool hasCampaign = 7;
uint64 campaignID = 8;
bytes metadata = 9;
string coordinator = 1;
string genesisChainID = 2;
string sourceURL = 3;
string sourceHash = 4;
string genesisURL = 5;
string genesisHash = 6;
bool hasCampaign = 7;
uint64 campaignID = 8;
repeated cosmos.base.v1beta1.Coin AccountBalance = 9 [
(gogoproto.nullable) = false,
(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.Coin",
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"
];
bytes metadata = 10;
}

message MsgCreateChainResponse {
uint64 launchID = 1;
}

message MsgEditChain {
string coordinator = 1;
uint64 launchID = 2;
bool setCampaignID = 3;
uint64 campaignID = 4;
bytes metadata = 5;
string coordinator = 1;
uint64 launchID = 2;
bool setCampaignID = 3;
uint64 campaignID = 4;
bytes metadata = 5;
}

message MsgEditChainResponse {}
Expand Down
2 changes: 2 additions & 0 deletions testutil/sample/launch.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ func Chain(r *rand.Rand, id, coordinatorID uint64) launch.Chain {
SourceHash: String(r, 10),
LaunchTriggered: false,
InitialGenesis: launch.NewDefaultInitialGenesis(),
AccountBalance: Coins(r),
Metadata: Metadata(r, 20),
}
}
Expand Down Expand Up @@ -161,6 +162,7 @@ func MsgCreateChain(r *rand.Rand, coordAddress, genesisURL string, hasCampaign b
genesisHash,
hasCampaign,
campaignID,
Coins(r),
Metadata(r, 20),
)
}
Expand Down
1 change: 1 addition & 0 deletions x/campaign/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type LaunchKeeper interface {
hasCampaign bool,
campaignID uint64,
isMainnet bool,
accountBalance sdk.Coins,
metadata []byte,
) (uint64, error)
}
Expand Down
1 change: 1 addition & 0 deletions x/campaign/keeper/msg_initialize_mainnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ func (k msgServer) InitializeMainnet(goCtx context.Context, msg *types.MsgInitia
true,
msg.CampaignID,
true,
sdk.NewCoins(), // no enforced default for mainnet
[]byte{},
)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion x/campaign/types/events.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion x/campaign/types/mainnet_account.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion x/campaign/types/params.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion x/campaign/types/query.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 10 additions & 10 deletions x/campaign/types/query.pb.gw.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 21 additions & 2 deletions x/launch/client/cli/tx_create_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"net/http"
neturl "net/url"

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

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/client/tx"
Expand All @@ -18,8 +20,9 @@ import (
)

const (
flagGenesisURL = "genesis-url"
flagCampaignID = "campaign-id"
flagGenesisURL = "genesis-url"
flagCampaignID = "campaign-id"
flagAccountBalance = "account-balance"
)

func CmdCreateChain() *cobra.Command {
Expand Down Expand Up @@ -63,6 +66,19 @@ func CmdCreateChain() *cobra.Command {
}
metadataBytes := []byte(metadata)

balanceCoins := sdk.NewCoins()
balance, err := cmd.Flags().GetString(flagAccountBalance)
if err != nil {
return err
}
if balance != "" {
// parse coins argument
balanceCoins, err = sdk.ParseCoinsNormalized(balance)
if err != nil {
return err
}
}

msg := types.NewMsgCreateChain(
clientCtx.GetFromAddress().String(),
args[0],
Expand All @@ -72,6 +88,7 @@ func CmdCreateChain() *cobra.Command {
genesisHash,
hasCampaign,
campaignID,
balanceCoins,
metadataBytes,
)
if err := msg.ValidateBasic(); err != nil {
Expand All @@ -84,6 +101,8 @@ func CmdCreateChain() *cobra.Command {
cmd.Flags().String(flagGenesisURL, "", "URL for a custom genesis")
cmd.Flags().Int64(flagCampaignID, -1, "The campaign id")
cmd.Flags().String(flagMetadata, "", "Set metadata field for the chain")
cmd.Flags().String(flagAccountBalance, "", "Set the chain account coin balance")

flags.AddTxFlagsToCmd(cmd)

return cmd
Expand Down
2 changes: 2 additions & 0 deletions x/launch/keeper/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ func (k Keeper) CreateNewChain(
hasCampaign bool,
campaignID uint64,
isMainnet bool,
accountBalance sdk.Coins,
metadata []byte,
) (uint64, error) {
coord, found := k.profileKeeper.GetCoordinator(ctx, coordinatorID)
Expand All @@ -40,6 +41,7 @@ func (k Keeper) CreateNewChain(
IsMainnet: isMainnet,
LaunchTriggered: false,
LaunchTimestamp: 0,
AccountBalance: accountBalance,
Metadata: metadata,
}

Expand Down
Loading