-
Notifications
You must be signed in to change notification settings - Fork 207
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: plumb through the genesis data to vpurse initialisation
- Loading branch information
1 parent
43c5db5
commit 8105589
Showing
6 changed files
with
543 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
syntax = "proto3"; | ||
package agoric.vpurse; | ||
|
||
import "gogoproto/gogo.proto"; | ||
|
||
option go_package = "github.com/Agoric/agoric-sdk/golang/cosmos/x/vpurse/types"; | ||
|
||
message GenesisState { | ||
option (gogoproto.equal) = false; | ||
|
||
string bootstrap_address = 1; | ||
string bootstrap_value = 2 [ | ||
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", | ||
(gogoproto.nullable) = false | ||
]; | ||
string donation_value = 3 [ | ||
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", | ||
(gogoproto.nullable) = false | ||
]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package vpurse | ||
|
||
import ( | ||
// "fmt" | ||
|
||
"fmt" | ||
|
||
"github.com/Agoric/agoric-sdk/golang/cosmos/x/vpurse/types" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
abci "github.com/tendermint/tendermint/abci/types" | ||
) | ||
|
||
func NewGenesisState() *types.GenesisState { | ||
return &types.GenesisState{ | ||
BootstrapAddress: "", | ||
BootstrapValue: sdk.NewInt(0), | ||
DonationValue: sdk.NewInt(0), | ||
} | ||
} | ||
|
||
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.