Skip to content

Commit

Permalink
Merge pull request #25 from cosmwasm/cosmwasm-0.6
Browse files Browse the repository at this point in the history
Cosmwasm 0.6
  • Loading branch information
ethanfrey committed Jan 17, 2020
2 parents 09016ea + f206d9a commit de89907
Show file tree
Hide file tree
Showing 17 changed files with 270 additions and 218 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ This code was forked from the `cosmos/gaia` repository and the majority of the c

**Note**: Requires [Go 1.13+](https://golang.org/dl/)

**Compatibility**: Last merge from `cosmos/gaia` was `d6dfa141e2ae38a1ff9f53fca8078c0822671b95`

## Quick Start

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.13

require (
github.com/btcsuite/btcd v0.0.0-20190807005414-4063feeff79a // indirect
github.com/confio/go-cosmwasm v0.4.1
github.com/confio/go-cosmwasm v0.6.0
github.com/cosmos/cosmos-sdk v0.34.4-0.20191114141721-d4c831e63ad3
github.com/cosmos/go-bip39 v0.0.0-20180819234021-555e2067c45d // indirect
github.com/golang/mock v1.3.1 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghf
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/confio/go-cosmwasm v0.4.1 h1:ZqqGlK5MA6iJlYU8LtV0VPmv4mMI1s1cx2xWnDSEzH0=
github.com/confio/go-cosmwasm v0.4.1/go.mod h1:pHipRby+f3cv97QPLELkzOAlNs/s87uDyhc+SnMn7L4=
github.com/confio/go-cosmwasm v0.6.0 h1:6MsfozR4IWb+V9TgVhDoGvcEs0ItBCqHg4pGbMafX1A=
github.com/confio/go-cosmwasm v0.6.0/go.mod h1:pHipRby+f3cv97QPLELkzOAlNs/s87uDyhc+SnMn7L4=
github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk=
github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8NzMklzPG4d5KIOhIy30Tk=
Expand Down
98 changes: 49 additions & 49 deletions x/wasm/alias.go
Original file line number Diff line number Diff line change
@@ -1,51 +1,38 @@
// nolint
// autogenerated code using github.com/rigelrozanski/multitool
// aliases generated for the following subdirectories:
// ALIASGEN: github.com/cosmwasm/wasmd/x/wasm/internal/types
// ALIASGEN: github.com/cosmwasm/wasmd/x/wasm/internal/keeper
package wasm

import (
"github.com/cosmwasm/wasmd/x/wasm/internal/keeper"
"github.com/cosmwasm/wasmd/x/wasm/internal/types"
)

// autogenerated code using github.com/rigelrozanski/multitool
// aliases generated for the following subdirectories:
// ALIASGEN: github.com/cosmwasm/wasmd/x/wasm/internal/keeper/
// ALIASGEN: github.com/cosmwasm/wasmd/x/wasm/internal/types/

const (
GasMultiplier = keeper.GasMultiplier
MaxGas = keeper.MaxGas
QueryListContracts = keeper.QueryListContracts
QueryGetContract = keeper.QueryGetContract
QueryGetContractState = keeper.QueryGetContractState
QueryGetCode = keeper.QueryGetCode
QueryListCode = keeper.QueryListCode
DefaultCodespace = types.DefaultCodespace
CodeCreatedFailed = types.CodeCreatedFailed
CodeAccountExists = types.CodeAccountExists
CodeInstantiateFailed = types.CodeInstantiateFailed
CodeExecuteFailed = types.CodeExecuteFailed
CodeGasLimit = types.CodeGasLimit
ModuleName = types.ModuleName
StoreKey = types.StoreKey
TStoreKey = types.TStoreKey
QuerierRoute = types.QuerierRoute
RouterKey = types.RouterKey
MaxWasmSize = types.MaxWasmSize
ModuleName = types.ModuleName
StoreKey = types.StoreKey
TStoreKey = types.TStoreKey
QuerierRoute = types.QuerierRoute
RouterKey = types.RouterKey
MaxWasmSize = types.MaxWasmSize
GasMultiplier = keeper.GasMultiplier
MaxGas = keeper.MaxGas
QueryListContracts = keeper.QueryListContracts
QueryGetContract = keeper.QueryGetContract
QueryGetContractState = keeper.QueryGetContractState
QueryGetCode = keeper.QueryGetCode
QueryListCode = keeper.QueryListCode
QueryMethodContractStateSmart = keeper.QueryMethodContractStateSmart
QueryMethodContractStateAll = keeper.QueryMethodContractStateAll
QueryMethodContractStateRaw = keeper.QueryMethodContractStateRaw
)

var (
// functions aliases
NewKeeper = keeper.NewKeeper
NewQuerier = keeper.NewQuerier
MakeTestCodec = keeper.MakeTestCodec
CreateTestInput = keeper.CreateTestInput
RegisterCodec = types.RegisterCodec
ErrCreateFailed = types.ErrCreateFailed
ErrAccountExists = types.ErrAccountExists
ErrInstantiateFailed = types.ErrInstantiateFailed
ErrExecuteFailed = types.ErrExecuteFailed
ErrGasLimit = types.ErrGasLimit
ErrInvalidGenesis = types.ErrInvalidGenesis
ValidateGenesis = types.ValidateGenesis
GetCodeKey = types.GetCodeKey
GetContractAddressKey = types.GetContractAddressKey
GetContractStorePrefixKey = types.GetContractStorePrefixKey
Expand All @@ -54,29 +41,42 @@ var (
NewWasmCoins = types.NewWasmCoins
NewContractInfo = types.NewContractInfo
CosmosResult = types.CosmosResult

// genesis aliases
ValidateGenesis = types.ValidateGenesis
InitGenesis = keeper.InitGenesis
ExportGenesis = keeper.ExportGenesis
InitGenesis = keeper.InitGenesis
ExportGenesis = keeper.ExportGenesis
NewKeeper = keeper.NewKeeper
NewQuerier = keeper.NewQuerier
MakeTestCodec = keeper.MakeTestCodec
CreateTestInput = keeper.CreateTestInput

// variable aliases
ModuleCdc = types.ModuleCdc
KeyLastCodeID = types.KeyLastCodeID
KeyLastInstanceID = types.KeyLastInstanceID
CodeKeyPrefix = types.CodeKeyPrefix
ContractKeyPrefix = types.ContractKeyPrefix
ContractStorePrefix = types.ContractStorePrefix
ModuleCdc = types.ModuleCdc
DefaultCodespace = types.DefaultCodespace
ErrCreateFailed = types.ErrCreateFailed
ErrAccountExists = types.ErrAccountExists
ErrInstantiateFailed = types.ErrInstantiateFailed
ErrExecuteFailed = types.ErrExecuteFailed
ErrGasLimit = types.ErrGasLimit
ErrInvalidGenesis = types.ErrInvalidGenesis
ErrNotFound = types.ErrNotFound
ErrQueryFailed = types.ErrQueryFailed
KeyLastCodeID = types.KeyLastCodeID
KeyLastInstanceID = types.KeyLastInstanceID
CodeKeyPrefix = types.CodeKeyPrefix
ContractKeyPrefix = types.ContractKeyPrefix
ContractStorePrefix = types.ContractStorePrefix
)

type (
Keeper = keeper.Keeper
GetCodeResponse = keeper.GetCodeResponse
GenesisState = types.GenesisState
Code = types.Code
Contract = types.Contract
MsgStoreCode = types.MsgStoreCode
MsgInstantiateContract = types.MsgInstantiateContract
MsgExecuteContract = types.MsgExecuteContract
Model = types.Model
CodeInfo = types.CodeInfo
ContractInfo = types.ContractInfo

GenesisState = types.GenesisState
Keeper = keeper.Keeper
GetCodeResponse = keeper.GetCodeResponse
ListCodeResponse = keeper.ListCodeResponse
)
19 changes: 11 additions & 8 deletions x/wasm/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
)

type contractState struct {
}

func TestInitGenesis(t *testing.T) {
data, cleanup := setupTest(t)
defer cleanup()
Expand All @@ -31,8 +34,8 @@ func TestInitGenesis(t *testing.T) {

_, _, bob := keyPubAddr()
initMsg := initMsg{
Verifier: fred.String(),
Beneficiary: bob.String(),
Verifier: fred,
Beneficiary: bob,
}
initMsgBz, err := json.Marshal(initMsg)
require.NoError(t, err)
Expand Down Expand Up @@ -63,9 +66,9 @@ func TestInitGenesis(t *testing.T) {
assertContractList(t, q, data.ctx, []string{contractAddr.String()})
assertContractInfo(t, q, data.ctx, contractAddr, 1, creator)
assertContractState(t, q, data.ctx, contractAddr, state{
Verifier: fred.String(),
Beneficiary: bob.String(),
Funder: creator.String(),
Verifier: []byte(fred),
Beneficiary: []byte(bob),
Funder: []byte(creator),
})

// export into genstate
Expand All @@ -86,8 +89,8 @@ func TestInitGenesis(t *testing.T) {
assertContractList(t, q2, newData.ctx, []string{contractAddr.String()})
assertContractInfo(t, q2, newData.ctx, contractAddr, 1, creator)
assertContractState(t, q2, newData.ctx, contractAddr, state{
Verifier: fred.String(),
Beneficiary: bob.String(),
Funder: creator.String(),
Verifier: []byte(fred),
Beneficiary: []byte(bob),
Funder: []byte(creator),
})
}
6 changes: 3 additions & 3 deletions x/wasm/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func NewHandler(k Keeper) sdk.Handler {
func handleStoreCode(ctx sdk.Context, k Keeper, msg *MsgStoreCode) sdk.Result {
codeID, err := k.Create(ctx, msg.Sender, msg.WASMByteCode)
if err != nil {
return err.Result()
return sdk.ResultFromError(err)
}

ctx.EventManager().EmitEvent(
Expand All @@ -64,7 +64,7 @@ func handleStoreCode(ctx sdk.Context, k Keeper, msg *MsgStoreCode) sdk.Result {
func handleInstantiate(ctx sdk.Context, k Keeper, msg *MsgInstantiateContract) sdk.Result {
contractAddr, err := k.Instantiate(ctx, msg.Sender, msg.Code, msg.InitMsg, msg.InitFunds)
if err != nil {
return err.Result()
return sdk.ResultFromError(err)
}

ctx.EventManager().EmitEvent(
Expand All @@ -87,7 +87,7 @@ func handleInstantiate(ctx sdk.Context, k Keeper, msg *MsgInstantiateContract) s
func handleExecute(ctx sdk.Context, k Keeper, msg *MsgExecuteContract) sdk.Result {
res, err := k.Execute(ctx, msg.Contract, msg.Sender, msg.SentFunds, msg.Msg)
if err != nil {
return err.Result()
return sdk.ResultFromError(err)
}

ctx.EventManager().EmitEvent(
Expand Down
23 changes: 23 additions & 0 deletions x/wasm/internal/keeper/api.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package keeper

import (
"fmt"
cosmwasm "github.com/confio/go-cosmwasm"
sdk "github.com/cosmos/cosmos-sdk/types"
)

func humanAddress(canon []byte) (string, error) {
if len(canon) != sdk.AddrLen {
return "", fmt.Errorf("Expected %d byte address", sdk.AddrLen)
}
return sdk.AccAddress(canon).String(), nil
}

func canonicalAddress(human string) ([]byte, error) {
return sdk.AccAddressFromBech32(human)
}

var cosmwasmAPI = cosmwasm.GoAPI{
HumanAddress: humanAddress,
CanonicalAddress: canonicalAddress,
}
Loading

0 comments on commit de89907

Please sign in to comment.