Skip to content

Commit

Permalink
fix: change the account prefix to "agoric" and app name to Agoric
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelfig committed Apr 4, 2020
1 parent 94b3907 commit 0c14de9
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 30 deletions.
63 changes: 44 additions & 19 deletions packages/cosmic-swingset/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,25 @@ import (
"github.com/Agoric/cosmic-swingset/x/swingset"
)

const appName = "swingset"
const appName = "agoric"

const (
// Bech32MainPrefix defines the Bech32 prefix used by all types
Bech32MainPrefix = "agoric"

// Bech32PrefixAccAddr defines the Bech32 prefix of an account's address
Bech32PrefixAccAddr = Bech32MainPrefix
// Bech32PrefixAccPub defines the Bech32 prefix of an account's public key
Bech32PrefixAccPub = Bech32MainPrefix + sdk.PrefixPublic
// Bech32PrefixValAddr defines the Bech32 prefix of a validator's operator address
Bech32PrefixValAddr = Bech32MainPrefix + sdk.PrefixValidator + sdk.PrefixOperator
// Bech32PrefixValPub defines the Bech32 prefix of a validator's operator public key
Bech32PrefixValPub = Bech32MainPrefix + sdk.PrefixValidator + sdk.PrefixOperator + sdk.PrefixPublic
// Bech32PrefixConsAddr defines the Bech32 prefix of a consensus node address
Bech32PrefixConsAddr = Bech32MainPrefix + sdk.PrefixValidator + sdk.PrefixConsensus
// Bech32PrefixConsPub defines the Bech32 prefix of a consensus node public key
Bech32PrefixConsPub = Bech32MainPrefix + sdk.PrefixValidator + sdk.PrefixConsensus + sdk.PrefixPublic
)

var (
// default home directories for the application CLI
Expand Down Expand Up @@ -63,7 +81,7 @@ var (
}
)

type swingSetApp struct {
type agoricApp struct {
*bam.BaseApp
cdc *codec.Codec

Expand Down Expand Up @@ -93,14 +111,21 @@ type swingSetApp struct {
}

// verify app interface at compile time
var _ simapp.App = (*swingSetApp)(nil)
var _ simapp.App = (*agoricApp)(nil)

// SetConfigDefaults sets the appropriate parameters for the Agoric chain.
func SetConfigDefaults(config *sdk.Config) {
config.SetBech32PrefixForAccount(Bech32PrefixAccAddr, Bech32PrefixAccPub)
config.SetBech32PrefixForValidator(Bech32PrefixValAddr, Bech32PrefixValPub)
config.SetBech32PrefixForConsensusNode(Bech32PrefixConsAddr, Bech32PrefixConsPub)
}

// NewSwingSetApp is a constructor function for swingSetApp
func NewSwingSetApp(
// NewAgoricApp is a constructor function for agoricApp
func NewAgoricApp(
sendToController func(bool, string) (string, error),
logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest bool,
baseAppOptions ...func(*bam.BaseApp),
) *swingSetApp {
) *agoricApp {

// First define the top level codec that will be shared by the different modules
// TODO: remove cdc in favor of appCodec once all modules are migrated.
Expand All @@ -119,7 +144,7 @@ func NewSwingSetApp(
tkeys := sdk.NewTransientStoreKeys(staking.TStoreKey, params.TStoreKey)

// Here you initialize your application with the store keys it requires
var app = &swingSetApp{
var app = &agoricApp{
BaseApp: bApp,
cdc: cdc,
keys: keys,
Expand Down Expand Up @@ -199,7 +224,7 @@ func NewSwingSetApp(

app.ibcKeeper = ibc.NewKeeper(app.cdc, keys[ibc.StoreKey], stakingKeeper)

// The SwingSetKeeper is the Keeper from the Agoric module
// The SwingSetKeeper is the Keeper from the SwingSet module
// It handles interactions with the kvstore and IBC.
swingsetCapKey := app.ibcKeeper.PortKeeper.BindPort(swingset.ModuleName)
app.ssKeeper = swingset.NewKeeper(
Expand Down Expand Up @@ -284,7 +309,7 @@ func NewSwingSetApp(
return app
}

func (app *swingSetApp) InitChainer(ctx sdk.Context, req abci.RequestInitChain) abci.ResponseInitChain {
func (app *agoricApp) InitChainer(ctx sdk.Context, req abci.RequestInitChain) abci.ResponseInitChain {
var genesisState simapp.GenesisState

err := app.cdc.UnmarshalJSON(req.AppStateBytes, &genesisState)
Expand All @@ -295,47 +320,47 @@ func (app *swingSetApp) InitChainer(ctx sdk.Context, req abci.RequestInitChain)
return app.mm.InitGenesis(ctx, app.cdc, genesisState)
}

func (app *swingSetApp) BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock) abci.ResponseBeginBlock {
func (app *agoricApp) BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock) abci.ResponseBeginBlock {
return app.mm.BeginBlock(ctx, req)
}

func (app *swingSetApp) EndBlocker(ctx sdk.Context, req abci.RequestEndBlock) abci.ResponseEndBlock {
func (app *agoricApp) EndBlocker(ctx sdk.Context, req abci.RequestEndBlock) abci.ResponseEndBlock {
return app.mm.EndBlock(ctx, req)
}

func (app *swingSetApp) Commit() abci.ResponseCommit {
func (app *agoricApp) Commit() abci.ResponseCommit {
// Wrap the BaseApp's Commit method
res := app.BaseApp.Commit()
swingset.CommitBlock(app.ssKeeper)
return res
}

// GetKey returns the KVStoreKey for the provided store key
func (app *swingSetApp) GetKey(storeKey string) *sdk.KVStoreKey {
func (app *agoricApp) GetKey(storeKey string) *sdk.KVStoreKey {
return app.keys[storeKey]
}

// GetTKey returns the TransientStoreKey for the provided store key
func (app *swingSetApp) GetTKey(storeKey string) *sdk.TransientStoreKey {
func (app *agoricApp) GetTKey(storeKey string) *sdk.TransientStoreKey {
return app.tkeys[storeKey]
}

func (app *swingSetApp) LoadHeight(height int64) error {
func (app *agoricApp) LoadHeight(height int64) error {
return app.LoadVersion(height, app.keys[bam.MainStoreKey])
}

// Codec returns simapp's codec
func (app *swingSetApp) Codec() *codec.Codec {
func (app *agoricApp) Codec() *codec.Codec {
return app.cdc
}

// SimulationManager implements the SimulationApp interface
func (app *swingSetApp) SimulationManager() *module.SimulationManager {
func (app *agoricApp) SimulationManager() *module.SimulationManager {
return app.sm
}

// ModuleAccountAddrs returns all the app's module account addresses.
func (app *swingSetApp) ModuleAccountAddrs() map[string]bool {
func (app *agoricApp) ModuleAccountAddrs() map[string]bool {
modAccAddrs := make(map[string]bool)
for acc := range maccPerms {
modAccAddrs[supply.NewModuleAddress(acc).String()] = true
Expand All @@ -355,7 +380,7 @@ func GetMaccPerms() map[string][]string {

//_________________________________________________________

func (app *swingSetApp) ExportAppStateAndValidators(forZeroHeight bool, jailWhiteList []string,
func (app *agoricApp) ExportAppStateAndValidators(forZeroHeight bool, jailWhiteList []string,
) (appState json.RawMessage, validators []tmtypes.GenesisValidator, err error) {

// as if they could withdraw from the start of the next block
Expand Down
12 changes: 5 additions & 7 deletions packages/cosmic-swingset/lib/daemon/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,14 @@ func RunWithController(sendToController Sender) {
appCodec := appcodec.NewAppCodec(cdc)

config := sdk.GetConfig()
config.SetBech32PrefixForAccount(sdk.Bech32PrefixAccAddr, sdk.Bech32PrefixAccPub)
config.SetBech32PrefixForValidator(sdk.Bech32PrefixValAddr, sdk.Bech32PrefixValPub)
config.SetBech32PrefixForConsensusNode(sdk.Bech32PrefixConsAddr, sdk.Bech32PrefixConsPub)
app.SetConfigDefaults(config)
config.Seal()

ctx := server.NewDefaultContext()

rootCmd := &cobra.Command{
Use: "ag-chain-cosmos",
Short: "swingset App Daemon (server)",
Short: "Agoric Cosmos Daemon (server)",
PersistentPreRunE: server.PersistentPreRunEFn(ctx),
}
// CLI commands to initialize the chain
Expand Down Expand Up @@ -97,7 +95,7 @@ func makeNewApp(sendToController Sender) func(logger log.Logger, db dbm.DB, trac
}

// fmt.Println("Starting daemon!")
abci := app.NewSwingSetApp(
abci := app.NewAgoricApp(
sendToController, logger, db, traceStore, true,
baseapp.SetPruning(store.NewPruningOptionsFromString(viper.GetString("pruning"))),
baseapp.SetMinGasPrices(viper.GetString(server.FlagMinGasPrices)),
Expand Down Expand Up @@ -127,15 +125,15 @@ func makeExportAppStateAndTMValidators(sendToController Sender) func(
jailWhiteList []string,
) (json.RawMessage, []tmtypes.GenesisValidator, error) {
if height != -1 {
ssApp := app.NewSwingSetApp(sendToController, logger, db, traceStore, false)
ssApp := app.NewAgoricApp(sendToController, logger, db, traceStore, false)
err := ssApp.LoadHeight(height)
if err != nil {
return nil, nil, err
}
return ssApp.ExportAppStateAndValidators(forZeroHeight, jailWhiteList)
}

ssApp := app.NewSwingSetApp(sendToController, logger, db, traceStore, true)
ssApp := app.NewAgoricApp(sendToController, logger, db, traceStore, true)

return ssApp.ExportAppStateAndValidators(forZeroHeight, jailWhiteList)
}
Expand Down
6 changes: 2 additions & 4 deletions packages/cosmic-swingset/lib/helper/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,13 @@ func init() {
authclient.Codec = appCodec
}

// Run is the main program for the SwingSet client
// Run is the main program for the Agoric client
func Run() {
cobra.EnableCommandSorting = false

// Read in the configuration file for the sdk
config := sdk.GetConfig()
config.SetBech32PrefixForAccount(sdk.Bech32PrefixAccAddr, sdk.Bech32PrefixAccPub)
config.SetBech32PrefixForValidator(sdk.Bech32PrefixValAddr, sdk.Bech32PrefixValPub)
config.SetBech32PrefixForConsensusNode(sdk.Bech32PrefixConsAddr, sdk.Bech32PrefixConsPub)
app.SetConfigDefaults(config)
config.Seal()

rootCmd := &cobra.Command{
Expand Down

0 comments on commit 0c14de9

Please sign in to comment.