mirror of https://github.com/certusone/wasmd.git
rename Contract -> ContractInfo
This commit is contained in:
parent
57688babf0
commit
e9c772845f
|
@ -52,7 +52,7 @@ var (
|
||||||
NewCodeInfo = types.NewCodeInfo
|
NewCodeInfo = types.NewCodeInfo
|
||||||
NewParams = types.NewParams
|
NewParams = types.NewParams
|
||||||
NewWasmCoins = types.NewWasmCoins
|
NewWasmCoins = types.NewWasmCoins
|
||||||
NewContract = types.NewContract
|
NewContractInfo = types.NewContractInfo
|
||||||
CosmosResult = types.CosmosResult
|
CosmosResult = types.CosmosResult
|
||||||
|
|
||||||
// genesis aliases
|
// genesis aliases
|
||||||
|
@ -76,7 +76,7 @@ type (
|
||||||
MsgInstantiateContract = types.MsgInstantiateContract
|
MsgInstantiateContract = types.MsgInstantiateContract
|
||||||
MsgExecuteContract = types.MsgExecuteContract
|
MsgExecuteContract = types.MsgExecuteContract
|
||||||
CodeInfo = types.CodeInfo
|
CodeInfo = types.CodeInfo
|
||||||
Contract = types.Contract
|
ContractInfo = types.ContractInfo
|
||||||
|
|
||||||
GenesisState = types.GenesisState
|
GenesisState = types.GenesisState
|
||||||
)
|
)
|
||||||
|
|
|
@ -47,7 +47,7 @@ func ExportGenesis(ctx sdk.Context, keeper Keeper) types.GenesisState {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
keeper.ListContractInfo(ctx, func(addr sdk.AccAddress, contract types.Contract) bool {
|
keeper.ListContractInfo(ctx, func(addr sdk.AccAddress, contract types.ContractInfo) bool {
|
||||||
contractStateIterator := keeper.GetContractState(ctx, addr)
|
contractStateIterator := keeper.GetContractState(ctx, addr)
|
||||||
var state []types.Model
|
var state []types.Model
|
||||||
for ; contractStateIterator.Valid(); contractStateIterator.Next() {
|
for ; contractStateIterator.Valid(); contractStateIterator.Next() {
|
||||||
|
|
|
@ -118,7 +118,7 @@ func (k Keeper) Instantiate(ctx sdk.Context, creator sdk.AccAddress, codeID uint
|
||||||
}
|
}
|
||||||
|
|
||||||
// persist instance
|
// persist instance
|
||||||
instance := types.NewContract(codeID, creator, string(initMsg))
|
instance := types.NewContractInfo(codeID, creator, string(initMsg))
|
||||||
// 0x02 | contractAddress (sdk.AccAddress) -> Instance
|
// 0x02 | contractAddress (sdk.AccAddress) -> Instance
|
||||||
store.Set(types.GetContractAddressKey(contractAddress), k.cdc.MustMarshalBinaryBare(instance))
|
store.Set(types.GetContractAddressKey(contractAddress), k.cdc.MustMarshalBinaryBare(instance))
|
||||||
|
|
||||||
|
@ -129,7 +129,7 @@ func (k Keeper) Instantiate(ctx sdk.Context, creator sdk.AccAddress, codeID uint
|
||||||
func (k Keeper) Execute(ctx sdk.Context, contractAddress sdk.AccAddress, caller sdk.AccAddress, coins sdk.Coins, msgs []byte) (sdk.Result, sdk.Error) {
|
func (k Keeper) Execute(ctx sdk.Context, contractAddress sdk.AccAddress, caller sdk.AccAddress, coins sdk.Coins, msgs []byte) (sdk.Result, sdk.Error) {
|
||||||
store := ctx.KVStore(k.storeKey)
|
store := ctx.KVStore(k.storeKey)
|
||||||
|
|
||||||
var contract types.Contract
|
var contract types.ContractInfo
|
||||||
contractBz := store.Get(types.GetContractAddressKey(contractAddress))
|
contractBz := store.Get(types.GetContractAddressKey(contractAddress))
|
||||||
if contractBz != nil {
|
if contractBz != nil {
|
||||||
k.cdc.MustUnmarshalBinaryBare(contractBz, &contract)
|
k.cdc.MustUnmarshalBinaryBare(contractBz, &contract)
|
||||||
|
@ -167,9 +167,9 @@ func (k Keeper) Execute(ctx sdk.Context, contractAddress sdk.AccAddress, caller
|
||||||
return types.CosmosResult(*res), nil
|
return types.CosmosResult(*res), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (k Keeper) GetContractInfo(ctx sdk.Context, contractAddress sdk.AccAddress) *types.Contract {
|
func (k Keeper) GetContractInfo(ctx sdk.Context, contractAddress sdk.AccAddress) *types.ContractInfo {
|
||||||
store := ctx.KVStore(k.storeKey)
|
store := ctx.KVStore(k.storeKey)
|
||||||
var contract types.Contract
|
var contract types.ContractInfo
|
||||||
contractBz := store.Get(types.GetContractAddressKey(contractAddress))
|
contractBz := store.Get(types.GetContractAddressKey(contractAddress))
|
||||||
if contractBz == nil {
|
if contractBz == nil {
|
||||||
return nil
|
return nil
|
||||||
|
@ -178,16 +178,16 @@ func (k Keeper) GetContractInfo(ctx sdk.Context, contractAddress sdk.AccAddress)
|
||||||
return &contract
|
return &contract
|
||||||
}
|
}
|
||||||
|
|
||||||
func (k Keeper) setContractInfo(ctx sdk.Context, contractAddress sdk.AccAddress, contract types.Contract) {
|
func (k Keeper) setContractInfo(ctx sdk.Context, contractAddress sdk.AccAddress, contract types.ContractInfo) {
|
||||||
store := ctx.KVStore(k.storeKey)
|
store := ctx.KVStore(k.storeKey)
|
||||||
store.Set(types.GetContractAddressKey(contractAddress), k.cdc.MustMarshalBinaryBare(contract))
|
store.Set(types.GetContractAddressKey(contractAddress), k.cdc.MustMarshalBinaryBare(contract))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (k Keeper) ListContractInfo(ctx sdk.Context, cb func(sdk.AccAddress, types.Contract) bool) {
|
func (k Keeper) ListContractInfo(ctx sdk.Context, cb func(sdk.AccAddress, types.ContractInfo) bool) {
|
||||||
prefixStore := prefix.NewStore(ctx.KVStore(k.storeKey), types.ContractKeyPrefix)
|
prefixStore := prefix.NewStore(ctx.KVStore(k.storeKey), types.ContractKeyPrefix)
|
||||||
iter := prefixStore.Iterator(nil, nil)
|
iter := prefixStore.Iterator(nil, nil)
|
||||||
for ; iter.Valid(); iter.Next() {
|
for ; iter.Valid(); iter.Next() {
|
||||||
var contract types.Contract
|
var contract types.ContractInfo
|
||||||
k.cdc.MustUnmarshalBinaryBare(iter.Value(), &contract)
|
k.cdc.MustUnmarshalBinaryBare(iter.Value(), &contract)
|
||||||
// cb returns true to stop early
|
// cb returns true to stop early
|
||||||
if cb(iter.Key(), contract) {
|
if cb(iter.Key(), contract) {
|
||||||
|
|
|
@ -56,7 +56,7 @@ func queryContractInfo(ctx sdk.Context, bech string, req abci.RequestQuery, keep
|
||||||
|
|
||||||
func queryContractList(ctx sdk.Context, req abci.RequestQuery, keeper Keeper) ([]byte, sdk.Error) {
|
func queryContractList(ctx sdk.Context, req abci.RequestQuery, keeper Keeper) ([]byte, sdk.Error) {
|
||||||
var addrs []string
|
var addrs []string
|
||||||
keeper.ListContractInfo(ctx, func(addr sdk.AccAddress, _ types.Contract) bool {
|
keeper.ListContractInfo(ctx, func(addr sdk.AccAddress, _ types.ContractInfo) bool {
|
||||||
addrs = append(addrs, addr.String())
|
addrs = append(addrs, addr.String())
|
||||||
return false
|
return false
|
||||||
})
|
})
|
||||||
|
|
|
@ -19,7 +19,7 @@ type CodeData struct {
|
||||||
// ContractData struct encompasses ContractAddress, ContractInfo, and ContractState
|
// ContractData struct encompasses ContractAddress, ContractInfo, and ContractState
|
||||||
type ContractData struct {
|
type ContractData struct {
|
||||||
ContractAddress sdk.AccAddress `json:"contract_address"`
|
ContractAddress sdk.AccAddress `json:"contract_address"`
|
||||||
ContractInfo Contract `json:"contract_info"`
|
ContractInfo ContractInfo `json:"contract_info"`
|
||||||
ContractState []Model `json:"contract_state"`
|
ContractState []Model `json:"contract_state"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,7 @@ func NewCodeInfo(codeHash []byte, creator sdk.AccAddress) CodeInfo {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Contract stores a WASM contract instance
|
// Contract stores a WASM contract instance
|
||||||
type Contract struct {
|
type ContractInfo struct {
|
||||||
CodeID uint64 `json:"code_id"`
|
CodeID uint64 `json:"code_id"`
|
||||||
Creator sdk.AccAddress `json:"creator"`
|
Creator sdk.AccAddress `json:"creator"`
|
||||||
InitMsg string `json:"init_msg"`
|
InitMsg string `json:"init_msg"`
|
||||||
|
@ -64,9 +64,9 @@ func NewWasmCoins(cosmosCoins sdk.Coins) (wasmCoins []wasmTypes.Coin) {
|
||||||
return wasmCoins
|
return wasmCoins
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewContract creates a new instance of a given WASM contract
|
// NewContractInfo creates a new instance of a given WASM contract info
|
||||||
func NewContract(codeID uint64, creator sdk.AccAddress, initMsg string) Contract {
|
func NewContractInfo(codeID uint64, creator sdk.AccAddress, initMsg string) ContractInfo {
|
||||||
return Contract{
|
return ContractInfo{
|
||||||
CodeID: codeID,
|
CodeID: codeID,
|
||||||
Creator: creator,
|
Creator: creator,
|
||||||
InitMsg: initMsg,
|
InitMsg: initMsg,
|
||||||
|
|
|
@ -417,7 +417,7 @@ func assertContractInfo(t *testing.T, q sdk.Querier, ctx sdk.Context, addr sdk.A
|
||||||
bz, sdkerr := q(ctx, path, abci.RequestQuery{})
|
bz, sdkerr := q(ctx, path, abci.RequestQuery{})
|
||||||
require.NoError(t, sdkerr)
|
require.NoError(t, sdkerr)
|
||||||
|
|
||||||
var res Contract
|
var res ContractInfo
|
||||||
err := json.Unmarshal(bz, &res)
|
err := json.Unmarshal(bz, &res)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue