Skip to content

Commit

Permalink
refactor(network): upgrade spn (#2816)
Browse files Browse the repository at this point in the history
* update go mod

* clock package

* refactor network

* new cmd

* last changes

* typoe

* import

* fix unit test

* fix test 2

* Upgrade for send request

* publish: add balance

* new logic for adding accounts

* format

* change switch

* changelog

* Update ignite/cmd/network_chain_join.go

Co-authored-by: Thomas Bruyelle <[email protected]>

Co-authored-by: Alex Johnson <[email protected]>
Co-authored-by: Thomas Bruyelle <[email protected]>
  • Loading branch information
3 people authored Sep 12, 2022
1 parent e778671 commit 83ab4c8
Show file tree
Hide file tree
Showing 21 changed files with 432 additions and 179 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
- Add nodejs version in the output of ignite version
- Removed `handler.go` from scaffolded module template
- Migrated to `cosmossdk.io` packages for `errors` and `math`
- Upgraded `spn` version
- Vuex stores from the `generate vuex` command use the new TypeScript client
- Upgraded frontend Vue template to v0.3.10

Expand Down
7 changes: 4 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ require (
cosmossdk.io/math v1.0.0-beta.3
github.com/99designs/keyring v1.2.1
github.com/AlecAivazis/survey/v2 v2.1.1
github.com/aws/smithy-go v1.8.0
github.com/blang/semver v3.5.1+incompatible
github.com/briandowns/spinner v1.11.1
github.com/buger/jsonparser v1.1.1
Expand Down Expand Up @@ -48,7 +49,7 @@ require (
github.com/stretchr/testify v1.8.0
github.com/takuoki/gocase v1.0.0
github.com/tendermint/flutter/v2 v2.0.4
github.com/tendermint/spn v0.2.1-0.20220826123316-985b629a92dd
github.com/tendermint/spn v0.2.1-0.20220907161743-aab4d3df1f2b
github.com/tendermint/tendermint v0.34.21
github.com/tendermint/tm-db v0.6.7
github.com/vektra/mockery/v2 v2.14.0
Expand All @@ -58,7 +59,7 @@ require (
golang.org/x/term v0.0.0-20220722155259-a9ba230a4035
golang.org/x/text v0.3.7
golang.org/x/tools v0.1.12
google.golang.org/grpc v1.48.0
google.golang.org/grpc v1.49.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 @@ -237,7 +238,7 @@ require (
golang.org/x/net v0.0.0-20220726230323-06994584191e // indirect
golang.org/x/sys v0.0.0-20220727055044-e65921a090b8 // indirect
golang.org/x/xerrors v0.0.0-20220609144429-65e65417b02f // indirect
google.golang.org/genproto v0.0.0-20220805133916-01dd62135a58 // indirect
google.golang.org/genproto v0.0.0-20220822174746-9e6da59bd2fc // indirect
gopkg.in/ini.v1 v1.66.6 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
22 changes: 10 additions & 12 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ github.com/aws/aws-sdk-go-v2/service/route53 v1.1.1/go.mod h1:rLiOUrPLW/Er5kRcQ7
github.com/aws/aws-sdk-go-v2/service/sso v1.1.1/go.mod h1:SuZJxklHxLAXgLTc1iFXbEWkXs7QRTQpCLGaKIprQW0=
github.com/aws/aws-sdk-go-v2/service/sts v1.1.1/go.mod h1:Wi0EBZwiz/K44YliU0EKxqTCJGUfYTWXrrBwkq736bM=
github.com/aws/smithy-go v1.1.0/go.mod h1:EzMw8dbp/YJL4A5/sbhGddag+NPT7q084agLbB9LgIw=
github.com/aws/smithy-go v1.8.0 h1:AEwwwXQZtUwP5Mz506FeXXrKBe0jA8gVM+1gEcSRooc=
github.com/aws/smithy-go v1.8.0/go.mod h1:SObp3lf9smib00L/v3U2eAKG8FyQ7iLrJnQiAmR5n+E=
github.com/aymerick/douceur v0.2.0 h1:Mv+mAeH1Q+n9Fr+oyamOlAkUNPWPlA8PPGR0QAaYuPk=
github.com/aymerick/douceur v0.2.0/go.mod h1:wlT5vV2O3h55X9m7iVYN0TBM0NH/MmbLnd30/FjWUq4=
github.com/beorn7/perks v0.0.0-20160804104726-4c0e84591b9a/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
Expand Down Expand Up @@ -288,11 +290,7 @@ github.com/cloudflare/cloudflare-go v0.14.0/go.mod h1:EnwdgGMaFOruiPZRFSgn+TsQ3h
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
github.com/cncf/udpa/go v0.0.0-20200629203442-efcf912fb354/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
github.com/cncf/udpa/go v0.0.0-20210930031921-04548b0d99d4/go.mod h1:6pvJx4me5XPnfI9Z40ddWsdw2W/uZgQLFXToKeRcDiI=
github.com/cncf/xds/go v0.0.0-20210312221358-fbca930ec8ed/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
github.com/cncf/xds/go v0.0.0-20210922020428-25de7278fc84/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
github.com/cncf/xds/go v0.0.0-20211001041855-01bcc9b48dfe/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
github.com/cncf/xds/go v0.0.0-20211011173535-cb28da3451f1/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
github.com/cockroachdb/apd/v2 v2.0.2 h1:weh8u7Cneje73dDh+2tEVLUvyBc89iwepWCD8b8034E=
github.com/cockroachdb/datadriven v0.0.0-20190809214429-80d97fb3cbaa/go.mod h1:zn76sxSg3SzpJ0PPJaLDCu+Bu0Lg3sKTORVIj19EIF8=
github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd/go.mod h1:sE/e/2PUdi/liOCUjSTXgM1o87ZssimdTWN964YiIeI=
Expand Down Expand Up @@ -534,7 +532,6 @@ github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1m
github.com/envoyproxy/go-control-plane v0.9.7/go.mod h1:cwu0lG7PUMfa9snN8LXBig5ynNVH9qI8YYLbd1fK2po=
github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk=
github.com/envoyproxy/go-control-plane v0.9.9-0.20210512163311-63b5d3c536b0/go.mod h1:hliV/p42l8fGbc6Y9bQ70uLwIvmJyVE5k4iMKlh8wCQ=
github.com/envoyproxy/go-control-plane v0.10.2-0.20220325020618-49ff273808a1/go.mod h1:KJwIaB5Mv44NWtYuAOFCVOjcI94vtpEz2JU/D2v6IjE=
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/ethereum/go-ethereum v1.10.17/go.mod h1:Lt5WzjM07XlXc95YzrhosmR4J9Ahd6X2wyEV2SvGhk0=
github.com/evanphx/json-patch v4.9.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
Expand Down Expand Up @@ -892,6 +889,7 @@ github.com/iancoleman/strcase v0.2.0 h1:05I4QRnGpI0m37iZQRuskXh+w77mr6Z41lwQzuHL
github.com/iancoleman/strcase v0.2.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47ZCWhYzw7ho=
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/ignite/modules v0.0.0-20220830145312-d006783a7a21 h1:2eqRFOwuBtP5prBIslVokLwLkXqekbY4cENDf2mEyxQ=
github.com/ignite/web v0.3.10 h1:WPKQi1a6gjwZPlaizT5Zq+cyUZ6b0p6VSAHr5L4i2p4=
github.com/ignite/web v0.3.10/go.mod h1:WZWBaBYF8RazN7dE462BLpvXDY8ScacxcJ07BKwX/jY=
github.com/imdario/mergo v0.3.5/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
Expand Down Expand Up @@ -1475,8 +1473,8 @@ github.com/tendermint/flutter/v2 v2.0.4/go.mod h1:hnaVhWhzv2Od1LqZFWrRKwiOHeMons
github.com/tendermint/fundraising v0.3.1 h1:S4uOV/T7YNBqXhsCZnq/TUoHB0d2kM+6tKeTD4WhLN0=
github.com/tendermint/go-amino v0.16.0 h1:GyhmgQKvqF82e2oZeuMSp9JTN0N09emoSZlb2lyGa2E=
github.com/tendermint/go-amino v0.16.0/go.mod h1:TQU0M1i/ImAo+tYpZi73AU3V/dKeCoMC9Sphe2ZwGME=
github.com/tendermint/spn v0.2.1-0.20220826123316-985b629a92dd h1:G50RK8x61pNFGVSAI5UmXaBDA4h/P2+SDdftha9jjSM=
github.com/tendermint/spn v0.2.1-0.20220826123316-985b629a92dd/go.mod h1:5eAAx0g6FEXubQ1Sb7zJcDZqCSjb9yoJMVOQwjEt9qQ=
github.com/tendermint/spn v0.2.1-0.20220907161743-aab4d3df1f2b h1:QqEBIiWRC+uPM8FCXuxcvzTS6isR/lycQJDRHgsmg2c=
github.com/tendermint/spn v0.2.1-0.20220907161743-aab4d3df1f2b/go.mod h1:CMzd3oBkjR9I1h/BEaU1K2V78XqARFWGjxPP9Xy/FIE=
github.com/tendermint/tendermint v0.34.21 h1:UiGGnBFHVrZhoQVQ7EfwSOLuCtarqCSsRf8VrklqB7s=
github.com/tendermint/tendermint v0.34.21/go.mod h1:XDvfg6U7grcFTDx7VkzxnhazQ/bspGJAn4DZ6DcLLjQ=
github.com/tendermint/tm-db v0.6.7 h1:fE00Cbl0jayAoqlExN6oyQJ7fR/ZtoVOmvPJ//+shu8=
Expand Down Expand Up @@ -1736,7 +1734,7 @@ golang.org/x/oauth2 v0.0.0-20201208152858-08078c50e5b5/go.mod h1:KelEdhl1UZF7XfJ
golang.org/x/oauth2 v0.0.0-20210218202405-ba52d332ba99/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A=
golang.org/x/oauth2 v0.0.0-20210514164344-f6687ab2804c/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A=
golang.org/x/oauth2 v0.0.0-20220223155221-ee480838109b/go.mod h1:DAh4E804XQdzx2j+YRIaUnCqCV2RuMz24cGBJ5QYIrc=
golang.org/x/oauth2 v0.0.0-20220722155238-128564f6959c h1:q3gFqPqH7NVofKo3c3yETAP//pPI+G5mvB7qqj1Y5kY=
golang.org/x/oauth2 v0.0.0-20220822191816-0ebed06d0094 h1:2o1E+E8TpNLklK9nHiPiK1uzIYrIHt+cQx3ynCwq9V8=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
Expand Down Expand Up @@ -2056,8 +2054,8 @@ google.golang.org/genproto v0.0.0-20201214200347-8c77b98c765d/go.mod h1:FWY/as6D
google.golang.org/genproto v0.0.0-20210108203827-ffc7fda8c3d7/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no=
google.golang.org/genproto v0.0.0-20210126160654-44e461bb6506/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no=
google.golang.org/genproto v0.0.0-20210226172003-ab064af71705/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no=
google.golang.org/genproto v0.0.0-20220805133916-01dd62135a58 h1:sRT5xdTkj1Kbk30qbYC7VyMj73N5pZYsw6v+Nrzdhno=
google.golang.org/genproto v0.0.0-20220805133916-01dd62135a58/go.mod h1:iHe1svFLAZg9VWz891+QbRMwUv9O/1Ww+/mngYeThbc=
google.golang.org/genproto v0.0.0-20220822174746-9e6da59bd2fc h1:Nf+EdcTLHR8qDNN/KfkQL0u0ssxt9OhbaWCl5C0ucEI=
google.golang.org/genproto v0.0.0-20220822174746-9e6da59bd2fc/go.mod h1:dbqgFATTzChvnt+ujMdZwITVAJHFtfyN1qUhDqEiIlk=
google.golang.org/grpc v0.0.0-20160317175043-d3ddb4469d5a/go.mod h1:yo6s7OP7yaDglbqo1J04qKzAhqBH6lvTonzMVmEdcZw=
google.golang.org/grpc v1.17.0/go.mod h1:6QZJwpn2B+Zp71q/5VxRsJ6NXXVCE5NRUHRo+f3cWCs=
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
Expand Down Expand Up @@ -2086,8 +2084,8 @@ google.golang.org/grpc v1.34.0/go.mod h1:WotjhfgOW/POjDeRt8vscBtXq+2VjORFy659qA5
google.golang.org/grpc v1.35.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU=
google.golang.org/grpc v1.36.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU=
google.golang.org/grpc v1.40.0/go.mod h1:ogyxbiOoUXAkP+4+xa6PZSE9DZgIHtSpzjDTB9KAK34=
google.golang.org/grpc v1.48.0 h1:rQOsyJ/8+ufEDJd/Gdsz7HG220Mh9HAhFHRGnIjda0w=
google.golang.org/grpc v1.48.0/go.mod h1:vN9eftEi1UMyUsIF80+uQXhHjbXYbm0uXoFCACuMGWk=
google.golang.org/grpc v1.49.0 h1:WTLtQzmQori5FUH25Pq4WT22oCsv8USpQ+F6rqtsmxw=
google.golang.org/grpc v1.49.0/go.mod h1:ZgQEeidpAuNRZ8iRrlBKXZQP1ghovWIVhdJRyCDK+GI=
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
Expand Down
55 changes: 34 additions & 21 deletions ignite/cmd/network_chain_join.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,25 @@ import (
"fmt"

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

"github.com/ignite/cli/ignite/pkg/cliui/icons"

"github.com/pkg/errors"
"github.com/rdegges/go-ipify"
"github.com/spf13/cobra"

"github.com/ignite/cli/ignite/pkg/cliui"
"github.com/ignite/cli/ignite/pkg/cliui/cliquiz"
"github.com/ignite/cli/ignite/pkg/cliui/icons"
"github.com/ignite/cli/ignite/pkg/gitpod"
"github.com/ignite/cli/ignite/pkg/xchisel"
"github.com/ignite/cli/ignite/services/network"
"github.com/ignite/cli/ignite/services/network/networkchain"
)

const (
flagGentx = "gentx"
flagAmount = "amount"
flagGentx = "gentx"
flagAmount = "amount"
flagNoAccount = "no-account"
)

// NewNetworkChainJoin creates a new chain join command to join
Expand All @@ -34,7 +37,8 @@ func NewNetworkChainJoin() *cobra.Command {
}

c.Flags().String(flagGentx, "", "Path to a gentx json file")
c.Flags().String(flagAmount, "", "Amount of coins for account request")
c.Flags().String(flagAmount, "", "Amount of coins for account request (ignored if coordinator has fixed the account balances or if --no-acount flag is set)")
c.Flags().Bool(flagNoAccount, false, "Prevent sending a request for a genesis account")
c.Flags().AddFlagSet(flagNetworkFrom())
c.Flags().AddFlagSet(flagSetHome())
c.Flags().AddFlagSet(flagSetKeyringBackend())
Expand All @@ -53,6 +57,7 @@ func networkChainJoinHandler(cmd *cobra.Command, args []string) error {
joinOptions []network.JoinOption
gentxPath, _ = cmd.Flags().GetString(flagGentx)
amount, _ = cmd.Flags().GetString(flagAmount)
noAccount, _ = cmd.Flags().GetBool(flagNoAccount)
)

nb, err := newNetworkBuilder(cmd, CollectEvents(session.EventBus()))
Expand Down Expand Up @@ -116,25 +121,33 @@ func networkChainJoinHandler(cmd *cobra.Command, args []string) error {
}
}

if amount != "" {
// parse the amount.
amountCoins, err := sdk.ParseCoinsNormalized(amount)
if err != nil {
return errors.Wrap(err, "error parsing amount")
}
joinOptions = append(joinOptions, network.WithAccountRequest(amountCoins))
} else {
if !getYes(cmd) {
question := fmt.Sprintf(
"You haven't set the --%s flag and therefore an account request won't be submitted. Do you confirm",
flagAmount,
)
if err := session.AskConfirm(question); err != nil {
return session.PrintSaidNo()
// genesis account request
if !noAccount {
switch {
case c.IsAccountBalanceFixed():
// fixed account balance
joinOptions = append(joinOptions, network.WithAccountRequest(c.AccountBalance()))
case amount != "":
// account balance set by user
amountCoins, err := sdk.ParseCoinsNormalized(amount)
if err != nil {
return errors.Wrap(err, "error parsing amount")
}
joinOptions = append(joinOptions, network.WithAccountRequest(amountCoins))
default:
// fixed balance and no amount entered by the user, we ask if they want to skip account request
if !getYes(cmd) {
question := fmt.Sprintf(
"You haven't set the --%s flag and therefore an account request won't be submitted. Do you confirm",
flagAmount,
)
if err := session.AskConfirm(question); err != nil {
return session.PrintSaidNo()
}
}
}

_ = session.Printf("%s %s\n", icons.Info, "Account request won't be submitted")
_ = session.Printf("%s %s\n", icons.Info, "Account request won't be submitted")
}
}

// create the message to add the validator.
Expand Down
24 changes: 20 additions & 4 deletions ignite/cmd/network_chain_launch.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
package ignitecmd

import (
"time"

timeparser "github.com/aws/smithy-go/time"
"github.com/spf13/cobra"

"github.com/ignite/cli/ignite/pkg/cliui"
"github.com/ignite/cli/ignite/services/network"
)

const (
flagRemainingTime = "remaining-time"
flagLauchTime = "launch-time"
)

// NewNetworkChainLaunch creates a new chain launch command to launch
Expand All @@ -21,7 +24,11 @@ func NewNetworkChainLaunch() *cobra.Command {
RunE: networkChainLaunchHandler,
}

c.Flags().Duration(flagRemainingTime, 0, "Duration of time in seconds before the chain is effectively launched")
c.Flags().String(
flagLauchTime,
"",
"Timestamp the chain is effectively launched (example \"2022-01-01T00:00:00Z\")",
)
c.Flags().AddFlagSet(flagNetworkFrom())
c.Flags().AddFlagSet(flagSetKeyringBackend())
c.Flags().AddFlagSet(flagSetKeyringDir())
Expand All @@ -44,12 +51,21 @@ func networkChainLaunchHandler(cmd *cobra.Command, args []string) error {
return err
}

remainingTime, _ := cmd.Flags().GetDuration(flagRemainingTime)
// parse launch time
var launchTime time.Time
launchTimeStr, _ := cmd.Flags().GetString(flagLauchTime)

if launchTimeStr != "" {
launchTime, err = timeparser.ParseDateTime(launchTimeStr)
if err != nil {
return err
}
}

n, err := nb.Network()
if err != nil {
return err
}

return n.TriggerLaunch(cmd.Context(), launchID, remainingTime)
return n.TriggerLaunch(cmd.Context(), launchID, launchTime)
}
34 changes: 23 additions & 11 deletions ignite/cmd/network_chain_publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,18 @@ import (
)

const (
flagTag = "tag"
flagBranch = "branch"
flagHash = "hash"
flagGenesis = "genesis"
flagCampaign = "campaign"
flagShares = "shares"
flagNoCheck = "no-check"
flagChainID = "chain-id"
flagMainnet = "mainnet"
flagRewardCoins = "reward.coins"
flagRewardHeight = "reward.height"
flagTag = "tag"
flagBranch = "branch"
flagHash = "hash"
flagGenesis = "genesis"
flagCampaign = "campaign"
flagShares = "shares"
flagNoCheck = "no-check"
flagChainID = "chain-id"
flagMainnet = "mainnet"
flagAccountBalance = "account-balance"
flagRewardCoins = "reward.coins"
flagRewardHeight = "reward.height"
)

// NewNetworkChainPublish returns a new command to publish a new chain to start a new network.
Expand All @@ -51,6 +52,7 @@ func NewNetworkChainPublish() *cobra.Command {
c.Flags().String(flagCampaignTotalSupply, "", "Add a total of the mainnet of a campaign")
c.Flags().String(flagShares, "", "Add shares for the campaign")
c.Flags().Bool(flagMainnet, false, "Initialize a mainnet campaign")
c.Flags().String(flagAccountBalance, "", "Balance for each approved genesis account for the chain")
c.Flags().String(flagRewardCoins, "", "Reward coins")
c.Flags().Int64(flagRewardHeight, 0, "Last reward height")
c.Flags().String(flagAmount, "", "Amount of coins for account request")
Expand Down Expand Up @@ -80,6 +82,7 @@ func networkChainPublishHandler(cmd *cobra.Command, args []string) error {
campaignTotalSupplyStr, _ = cmd.Flags().GetString(flagCampaignTotalSupply)
sharesStr, _ = cmd.Flags().GetString(flagShares)
isMainnet, _ = cmd.Flags().GetBool(flagMainnet)
accountBalance, _ = cmd.Flags().GetString(flagAccountBalance)
rewardCoinsStr, _ = cmd.Flags().GetString(flagRewardCoins)
rewardDuration, _ = cmd.Flags().GetInt64(flagRewardHeight)
amount, _ = cmd.Flags().GetString(flagAmount)
Expand All @@ -91,6 +94,11 @@ func networkChainPublishHandler(cmd *cobra.Command, args []string) error {
return errors.Wrap(err, "error parsing amount")
}

accountBalanceCoins, err := sdk.ParseCoinsNormalized(accountBalance)
if err != nil {
return errors.Wrap(err, "error parsing account balance")
}

source, err := xurl.MightHTTPS(args[0])
if err != nil {
return fmt.Errorf("invalid source url format: %w", err)
Expand Down Expand Up @@ -202,6 +210,10 @@ func networkChainPublishHandler(cmd *cobra.Command, args []string) error {
publishOptions = append(publishOptions, network.WithChainID(chainID))
}

if !accountBalanceCoins.IsZero() {
publishOptions = append(publishOptions, network.WithAccountBalance(accountBalanceCoins))
}

if isMainnet {
publishOptions = append(publishOptions, network.Mainnet())
}
Expand Down
49 changes: 49 additions & 0 deletions ignite/pkg/xtime/clock.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package xtime

import "time"

// Clock represents a clock that can retrieve current time
type Clock interface {
Now() time.Time
Add(duration time.Duration)
}

// ClockSystem is a clock that retrieves system time
type ClockSystem struct{}

// NewClockSystem returns a new ClockSystem
func NewClockSystem() ClockSystem {
return ClockSystem{}
}

// Now implements Clock
func (ClockSystem) Now() time.Time {
return time.Now()
}

// Add implements Clock
func (ClockSystem) Add(_ time.Duration) {
panic("Add can't be called for ClockSystem")
}

// ClockMock is a clock mocking time with an internal counter
type ClockMock struct {
t time.Time
}

// NewClockMock returns a new ClockMock
func NewClockMock(originalTime time.Time) *ClockMock {
return &ClockMock{
t: originalTime,
}
}

// Now implements Clock
func (c ClockMock) Now() time.Time {
return c.t
}

// Add implements Clock
func (c *ClockMock) Add(duration time.Duration) {
c.t = c.t.Add(duration)
}
Loading

0 comments on commit 83ab4c8

Please sign in to comment.