Skip to content

Commit

Permalink
feat: send AG_COSMOS_INIT supplyCoins instead of vpurse genesis
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelfig committed May 28, 2021
1 parent bd93574 commit 759d6ab
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 234 deletions.
2 changes: 1 addition & 1 deletion golang/cosmos/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ proto-check-breaking: proto-tools
buf check breaking --against-input '.git#branch=master'

TMVER = v0.34.3
COSMOSVER = v0.41.0
COSMOSVER = v0.42.4

TM_URL = https://raw.githubusercontent.com/tendermint/tendermint/$(TMVER)/proto/tendermint
GOGO_PROTO_URL = https://raw.githubusercontent.com/regen-network/protobuf/cosmos
Expand Down
39 changes: 12 additions & 27 deletions golang/cosmos/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -503,14 +503,12 @@ func NewAgoricApp(
}

type cosmosInitAction struct {
Type string `json:"type"`
IBCPort int `json:"ibcPort"`
StoragePort int `json:"storagePort"`
VPursePort int `json:"vpursePort"`
ChainID string `json:"chainID"`
BootstrapAddress string `json:"bootstrapAddress"`
BootstrapValue string `json:"bootstrapValue"`
DonationValue string `json:"donationValue"`
Type string `json:"type"`
ChainID string `json:"chainID"`
IBCPort int `json:"ibcPort"`
StoragePort int `json:"storagePort"`
SupplyCoins sdk.Coins `json:"supplyCoins"`
VPursePort int `json:"vpursePort"`
}

// MakeCodecs constructs the *std.Codec and *codec.LegacyAmino instances used by
Expand All @@ -530,27 +528,14 @@ func (app *GaiaApp) MustInitController(ctx sdk.Context) {
}
app.controllerInited = true

var bootstrapAddr sdk.AccAddress
gs := app.VpurseKeeper.GetGenesis(ctx)
if len(gs.BootstrapAddress) > 0 {
ba, err := sdk.AccAddressFromBech32(gs.BootstrapAddress)
if err != nil {
fmt.Fprintln(os.Stderr, "Cannot get bootstrap addr", err)
os.Exit(1)
}
bootstrapAddr = ba
}

// Begin initializing the controller here.
action := &cosmosInitAction{
Type: "AG_COSMOS_INIT",
VPursePort: app.vpursePort,
IBCPort: app.ibcPort,
StoragePort: swingset.GetPort("storage"),
ChainID: ctx.ChainID(),
BootstrapAddress: bootstrapAddr.String(),
BootstrapValue: gs.BootstrapValue.String(),
DonationValue: gs.DonationValue.String(),
Type: "AG_COSMOS_INIT",
ChainID: ctx.ChainID(),
IBCPort: app.ibcPort,
StoragePort: swingset.GetPort("storage"),
SupplyCoins: app.BankKeeper.GetSupply(ctx).GetTotal(),
VPursePort: app.vpursePort,
}
bz, err := json.Marshal(action)
if err == nil {
Expand Down
17 changes: 0 additions & 17 deletions golang/cosmos/proto/agoric/vpurse/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,4 @@ option go_package = "github.com/Agoric/agoric-sdk/golang/cosmos/x/vpurse/types";
message GenesisState {
option (gogoproto.equal) = false;

// These are passed as part of the AG_COSMOS_INIT message.
// They are plumbed through to configure the bootstrap of the treasury:

// Cosmos-SDK layer bech32 address to receive bootstrap_value urun.
string bootstrap_address = 1;

// Number of urun to have the treasury send to bootstrap_address.
string bootstrap_value = 2 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
];

// Number of urun to send from bootstrap_address to new ag-solo clients.
string donation_value = 3 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
];
}
26 changes: 1 addition & 25 deletions golang/cosmos/x/vpurse/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,51 +11,27 @@ import (
)

func NewGenesisState() *types.GenesisState {
return &types.GenesisState{
BootstrapAddress: "",
BootstrapValue: sdk.NewInt(0),
DonationValue: sdk.NewInt(0),
}
return &types.GenesisState{}
}

func ValidateGenesis(data *types.GenesisState) error {
if data == nil {
return fmt.Errorf("vpurse genesis data cannot be nil")
}
if len(data.BootstrapAddress) > 0 {
if _, err := sdk.AccAddressFromBech32(data.BootstrapAddress); err != nil {
return fmt.Errorf("vpurse genesis invalid bootstrapAdddress %s: %w", data.BootstrapAddress, err)
}
}
if data.BootstrapValue.IsNil() {
return fmt.Errorf("vpurse genesis bootstrapValue cannot be nil")
}
if data.BootstrapValue.IsNegative() {
return fmt.Errorf("vpurse genesis bootstrapValue %s cannot be negative", data.DonationValue.String())
}
if data.DonationValue.IsNil() {
return fmt.Errorf("vpurse genesis donationValue cannot be nil")
}
if data.DonationValue.IsNegative() {
return fmt.Errorf("vpurse genesis donationValue %s cannot be negative", data.DonationValue.String())
}
return nil
}

func DefaultGenesisState() *types.GenesisState {
gs := NewGenesisState()
fmt.Println("default gen", gs)
return gs
}

func InitGenesis(ctx sdk.Context, keeper Keeper, data *types.GenesisState) []abci.ValidatorUpdate {
keeper.SetGenesis(ctx, *data)
fmt.Println("initialising gen", *data)
return []abci.ValidatorUpdate{}
}

func ExportGenesis(ctx sdk.Context, k Keeper) *types.GenesisState {
gs := k.GetGenesis(ctx)
fmt.Println("exporting gen", gs)
return &gs
}
173 changes: 9 additions & 164 deletions golang/cosmos/x/vpurse/types/genesis.pb.go

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

0 comments on commit 759d6ab

Please sign in to comment.