Initialize coin metadata in app4 and fmt
This commit is contained in:
parent
c0445e52b0
commit
e11e469340
|
@ -179,7 +179,7 @@ func handleMsgSend(ctx sdk.Context, key *sdk.KVStoreKey, msg MsgSend) sdk.Result
|
|||
store.Set(msg.To, val)
|
||||
|
||||
return sdk.Result{
|
||||
// TODO: Tags
|
||||
// TODO: Tags
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
package app
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"reflect"
|
||||
|
||||
"github.com/tendermint/go-crypto"
|
||||
cmn "github.com/tendermint/tmlibs/common"
|
||||
dbm "github.com/tendermint/tmlibs/db"
|
||||
"github.com/tendermint/tmlibs/log"
|
||||
"github.com/tendermint/go-crypto"
|
||||
|
||||
bapp "github.com/cosmos/cosmos-sdk/baseapp"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
|
@ -63,10 +63,10 @@ func NewApp2(logger log.Logger, db dbm.DB) *bapp.BaseApp {
|
|||
|
||||
// Coin Metadata
|
||||
type CoinMetadata struct {
|
||||
TotalSupply sdk.Int
|
||||
TotalSupply sdk.Int
|
||||
CurrentSupply sdk.Int
|
||||
Issuer sdk.Address
|
||||
Decimal uint64
|
||||
Issuer sdk.Address
|
||||
Decimal uint64
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------
|
||||
|
@ -75,13 +75,13 @@ type CoinMetadata struct {
|
|||
// Create Output struct to allow single message to issue arbitrary coins to multiple users
|
||||
type Output struct {
|
||||
Address sdk.Address
|
||||
Coins sdk.Coins
|
||||
Coins sdk.Coins
|
||||
}
|
||||
|
||||
// Single permissioned issuer can issue multiple outputs
|
||||
// Implements sdk.Msg Interface
|
||||
type MsgIssue struct {
|
||||
Issuer sdk.Address
|
||||
Issuer sdk.Address
|
||||
Outputs []Output
|
||||
}
|
||||
|
||||
|
@ -91,7 +91,7 @@ func (msg MsgIssue) Type() string { return "bank" }
|
|||
func (msg MsgIssue) ValidateBasic() sdk.Error {
|
||||
if len(msg.Issuer) == 0 {
|
||||
return sdk.ErrInvalidAddress("Issuer address cannot be empty")
|
||||
}
|
||||
}
|
||||
|
||||
for _, o := range msg.Outputs {
|
||||
if len(o.Address) == 0 {
|
||||
|
@ -152,10 +152,10 @@ func handleMsgIssue(ctx sdk.Context, keyMain *sdk.KVStoreKey, keyAcc *sdk.KVStor
|
|||
return sdk.ErrInvalidCoins("Cannot issue that many new coins").Result()
|
||||
}
|
||||
metadata = CoinMetadata{
|
||||
TotalSupply: sdk.NewInt(1000000),
|
||||
TotalSupply: sdk.NewInt(1000000),
|
||||
CurrentSupply: sdk.NewInt(0),
|
||||
Issuer: msg.Issuer,
|
||||
Decimal: 10,
|
||||
Issuer: msg.Issuer,
|
||||
Decimal: 10,
|
||||
}
|
||||
} else {
|
||||
// Decode coin metadata
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
package app
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"reflect"
|
||||
|
||||
cmn "github.com/tendermint/tmlibs/common"
|
||||
dbm "github.com/tendermint/tmlibs/db"
|
||||
|
@ -13,7 +13,6 @@ import (
|
|||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/auth"
|
||||
"github.com/cosmos/cosmos-sdk/x/bank"
|
||||
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -94,7 +93,7 @@ func betterHandleMsgIssue(ctx sdk.Context, metadataMapper MetaDataMapper, accoun
|
|||
// coin doesn't have issuer yet, set issuer to msg issuer
|
||||
metadata.Issuer = msg.Issuer
|
||||
}
|
||||
|
||||
|
||||
// Check that msg Issuer is authorized to issue these coins
|
||||
if !reflect.DeepEqual(metadata.Issuer, msg.Issuer) {
|
||||
return sdk.ErrUnauthorized(fmt.Sprintf("Msg Issuer cannot issue these coins: %s", coin.Denom)).Result()
|
||||
|
@ -122,8 +121,6 @@ func betterHandleMsgIssue(ctx sdk.Context, metadataMapper MetaDataMapper, accoun
|
|||
return sdk.Result{}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//------------------------------------------------------------------
|
||||
// Mapper for Coin Metadata
|
||||
// Example of a very simple user-defined mapper
|
||||
|
|
|
@ -2,13 +2,13 @@ package app
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"reflect"
|
||||
"fmt"
|
||||
"reflect"
|
||||
|
||||
abci "github.com/tendermint/abci/types"
|
||||
cmn "github.com/tendermint/tmlibs/common"
|
||||
dbm "github.com/tendermint/tmlibs/db"
|
||||
"github.com/tendermint/tmlibs/log"
|
||||
abci "github.com/tendermint/abci/types"
|
||||
|
||||
bapp "github.com/cosmos/cosmos-sdk/baseapp"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
|
@ -59,8 +59,8 @@ func NewApp4(logger log.Logger, db dbm.DB) *bapp.BaseApp {
|
|||
}
|
||||
|
||||
type GenesisState struct {
|
||||
Accounts []*GenesisAccount `json:"accounts"`
|
||||
Coins []*GenesisCoin `json:"coins"`
|
||||
Accounts []*GenesisAccount `json:"accounts"`
|
||||
Coins []*GenesisCoin `json:"coins"`
|
||||
}
|
||||
|
||||
// GenesisAccount doesn't need pubkey or sequence
|
||||
|
@ -79,16 +79,17 @@ func (ga *GenesisAccount) ToAccount() (acc *auth.BaseAccount, err error) {
|
|||
|
||||
// GenesisCoin enforces CurrentSupply is 0 at genesis.
|
||||
type GenesisCoin struct {
|
||||
Issuer sdk.Address `json:"issuer"`
|
||||
TotalSupply sdk.Int `json:"total_supply`
|
||||
Decimal uint64 `json:"decimals"`
|
||||
Denom string `json:"denom"`
|
||||
Issuer sdk.Address `json:"issuer"`
|
||||
TotalSupply sdk.Int `json:"total_supply`
|
||||
Decimal uint64 `json:"decimals"`
|
||||
}
|
||||
|
||||
func (gc *GenesisCoin) ToMetaData() CoinMetadata {
|
||||
return CoinMetadata{
|
||||
Issuer: gc.Issuer,
|
||||
func (gc *GenesisCoin) ToMetaData() (string, CoinMetadata) {
|
||||
return gc.Denom, CoinMetadata{
|
||||
Issuer: gc.Issuer,
|
||||
TotalSupply: gc.TotalSupply,
|
||||
Decimal: gc.Decimal,
|
||||
Decimal: gc.Decimal,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -115,6 +116,12 @@ func NewInitChainer(cdc *wire.Codec, accountMapper auth.AccountMapper, metadataM
|
|||
accountMapper.SetAccount(ctx, acc)
|
||||
}
|
||||
|
||||
// Initialize coin metadata.
|
||||
for _, gc := range genesisState.Coins {
|
||||
denom, metadata := gc.ToMetaData()
|
||||
metadataMapper.SetMetaData(ctx, denom, metadata)
|
||||
}
|
||||
|
||||
return abci.ResponseInitChain{}
|
||||
|
||||
}
|
||||
|
@ -170,7 +177,6 @@ func evenBetterHandleMsgIssue(ctx sdk.Context, metadataMapper MetaDataMapper, ac
|
|||
return sdk.Result{}
|
||||
}
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------------------------
|
||||
// Simpler MetaDataMapper no longer able to initalize default CoinMetaData
|
||||
|
||||
|
|
Loading…
Reference in New Issue