Skip to content

Commit

Permalink
Merge pull request #113 from CosmWasm/upgrade-alpha3
Browse files Browse the repository at this point in the history
Upgrade to v0.8.0-alpha3
  • Loading branch information
ethanfrey authored May 19, 2020
2 parents af215d1 + a6bcf8c commit 245f55e
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 36 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/CosmWasm/wasmd
go 1.13

require (
github.com/CosmWasm/go-cosmwasm v0.8.0-alpha2.0.20200518133220-76a4987de98b
github.com/CosmWasm/go-cosmwasm v0.8.0-alpha3
github.com/btcsuite/btcd v0.0.0-20190807005414-4063feeff79a // indirect
github.com/cosmos/cosmos-sdk v0.38.3
github.com/golang/mock v1.4.3 // indirect
Expand Down
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ github.com/CosmWasm/go-cosmwasm v0.8.0-alpha2.0.20200518132754-acf959da37ac h1:8
github.com/CosmWasm/go-cosmwasm v0.8.0-alpha2.0.20200518132754-acf959da37ac/go.mod h1:gAFCwllx97ejI+m9SqJQrmd2SBW7HA0fOjvWWJjM2uc=
github.com/CosmWasm/go-cosmwasm v0.8.0-alpha2.0.20200518133220-76a4987de98b h1:AKCZCqgZAQnmJdCh4mnk23NoLzoyKQIowckBLnhrLlM=
github.com/CosmWasm/go-cosmwasm v0.8.0-alpha2.0.20200518133220-76a4987de98b/go.mod h1:gAFCwllx97ejI+m9SqJQrmd2SBW7HA0fOjvWWJjM2uc=
github.com/CosmWasm/go-cosmwasm v0.8.0-alpha2.0.20200519190110-12d4e604d491 h1:nyFnbmORZp79X7NTJluPqr/ZL8+2julXqbnDzRWDTA4=
github.com/CosmWasm/go-cosmwasm v0.8.0-alpha2.0.20200519190110-12d4e604d491/go.mod h1:gAFCwllx97ejI+m9SqJQrmd2SBW7HA0fOjvWWJjM2uc=
github.com/CosmWasm/go-cosmwasm v0.8.0-alpha2.0.20200519190609-972a954b9b43 h1:K+yLK6FsvVnY+FPu/SYx/WOtDUfLrSbHCA7G9ZvKsCI=
github.com/CosmWasm/go-cosmwasm v0.8.0-alpha2.0.20200519190609-972a954b9b43/go.mod h1:gAFCwllx97ejI+m9SqJQrmd2SBW7HA0fOjvWWJjM2uc=
github.com/CosmWasm/go-cosmwasm v0.8.0-alpha3 h1:pa1gVDCGvM+5TBYepUhP1JHnpfOXwpBbFNSzYcXGXOU=
github.com/CosmWasm/go-cosmwasm v0.8.0-alpha3/go.mod h1:gAFCwllx97ejI+m9SqJQrmd2SBW7HA0fOjvWWJjM2uc=
github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8Leh48TZaKVeNIfJntJ2wa0=
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
github.com/Shopify/sarama v1.19.0/go.mod h1:FVkBWblsNy7DGZRfXLU0O9RCGt5g3g3yEuWXgklEdEo=
Expand Down
2 changes: 1 addition & 1 deletion x/wasm/internal/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ func TestExecute(t *testing.T) {

// make sure gas is properly deducted from ctx
gasAfter := ctx.GasMeter().GasConsumed()
require.Equal(t, uint64(0x7b20), gasAfter-gasBefore)
require.Equal(t, uint64(0x7b22), gasAfter-gasBefore)

// ensure bob now exists and got both payments released
bobAcct = accKeeper.GetAccount(ctx, bob)
Expand Down
88 changes: 54 additions & 34 deletions x/wasm/internal/keeper/query_plugins.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,72 +132,92 @@ func StakingQuerier(keeper staking.Keeper) func(ctx sdk.Context, request *wasmTy
}
return json.Marshal(res)
}
if request.Delegations != nil {
delegator, err := sdk.AccAddressFromBech32(request.Delegations.Delegator)
if request.AllDelegations != nil {
delegator, err := sdk.AccAddressFromBech32(request.AllDelegations.Delegator)
if err != nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, request.Delegations.Delegator)
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, request.AllDelegations.Delegator)
}
var validator sdk.ValAddress
validator, err = sdk.ValAddressFromBech32(request.Delegations.Validator)
if err != nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, request.Delegations.Validator)
}

delegations, err := calculateDelegations(ctx, keeper, delegator, validator)
sdkDels := keeper.GetAllDelegatorDelegations(ctx, delegator)
delegations, err := sdkToDelegations(ctx, keeper, sdkDels)
if err != nil {
return nil, err
}
res := wasmTypes.DelegationsResponse{
res := wasmTypes.AllDelegationsResponse{
Delegations: delegations,
}
return json.Marshal(res)
}
if request.Delegation != nil {
delegator, err := sdk.AccAddressFromBech32(request.Delegation.Delegator)
if err != nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, request.Delegation.Delegator)
}
validator, err := sdk.ValAddressFromBech32(request.Delegation.Validator)
if err != nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, request.Delegation.Validator)
}

var res wasmTypes.DelegationResponse
d, found := keeper.GetDelegation(ctx, delegator, validator)
if found {
res.Delegation, err = sdkToFullDelegation(ctx, keeper, d)
if err != nil {
return nil, err
}
}
return json.Marshal(res)
}
return nil, wasmTypes.UnsupportedRequest{"unknown Staking variant"}
}
}

// calculateDelegations does all queries needed to get validation info
// delegator must be set, if validator is not set, get all delegations by delegator
func calculateDelegations(ctx sdk.Context, keeper staking.Keeper, delegator sdk.AccAddress, validator sdk.ValAddress) (wasmTypes.Delegations, error) {
// get delegations (either by validator, or over all validators)
var sdkDels []staking.Delegation
if len(validator) == 0 {
sdkDels = keeper.GetAllDelegatorDelegations(ctx, delegator)
} else {
d, found := keeper.GetDelegation(ctx, delegator, validator)
if found {
sdkDels = []staking.Delegation{d}
}
}
func sdkToDelegations(ctx sdk.Context, keeper staking.Keeper, delegations []staking.Delegation) (wasmTypes.Delegations, error) {
result := make([]wasmTypes.Delegation, len(delegations))
bondDenom := keeper.BondDenom(ctx)

// convert them to the cosmwasm format, pulling in extra info as needed
delegations := make([]wasmTypes.Delegation, len(sdkDels))
for i, d := range sdkDels {
for i, d := range delegations {
// shares to amount logic comes from here:
// https://github.com/cosmos/cosmos-sdk/blob/v0.38.3/x/staking/keeper/querier.go#L404
val, found := keeper.GetValidator(ctx, d.ValidatorAddress)
if !found {
return nil, sdkerrors.Wrap(staking.ErrNoValidatorFound, "can't load validator for delegation")
}
bondDenom := keeper.BondDenom(ctx)
amount := sdk.NewCoin(bondDenom, val.TokensFromShares(d.Shares).TruncateInt())

// Accumulated Rewards???

// can relegate? other query for redelegations?
// keeper.GetRedelegation

delegations[i] = wasmTypes.Delegation{
result[i] = wasmTypes.Delegation{
Delegator: d.DelegatorAddress.String(),
Validator: d.ValidatorAddress.String(),
Amount: convertSdkCoinToWasmCoin(amount),
// TODO: AccumulatedRewards
AccumulatedRewards: wasmTypes.NewCoin(0, bondDenom),
// TODO: Determine redelegate
CanRedelegate: false,
}
}
return delegations, nil
return result, nil
}

func sdkToFullDelegation(ctx sdk.Context, keeper staking.Keeper, delegation staking.Delegation) (*wasmTypes.FullDelegation, error) {
val, found := keeper.GetValidator(ctx, delegation.ValidatorAddress)
if !found {
return nil, sdkerrors.Wrap(staking.ErrNoValidatorFound, "can't load validator for delegation")
}
bondDenom := keeper.BondDenom(ctx)
amount := sdk.NewCoin(bondDenom, val.TokensFromShares(delegation.Shares).TruncateInt())

// can relegate? other query for redelegations?
// keeper.GetRedelegation

return &wasmTypes.FullDelegation{
Delegator: delegation.DelegatorAddress.String(),
Validator: delegation.ValidatorAddress.String(),
Amount: convertSdkCoinToWasmCoin(amount),
// TODO: AccumulatedRewards
AccumulatedRewards: wasmTypes.NewCoin(0, bondDenom),
// TODO: Determine redelegate
CanRedelegate: wasmTypes.NewCoin(0, bondDenom),
}, nil
}

func WasmQuerier(wasm Keeper) func(ctx sdk.Context, request *wasmTypes.WasmQuery) ([]byte, error) {
Expand Down
Binary file modified x/wasm/internal/keeper/testdata/contract.wasm
Binary file not shown.
Binary file modified x/wasm/internal/keeper/testdata/contract.wasm.gzip
Binary file not shown.
Binary file modified x/wasm/internal/keeper/testdata/reflect.wasm
Binary file not shown.
Binary file modified x/wasm/internal/keeper/testdata/staking.wasm
Binary file not shown.

0 comments on commit 245f55e

Please sign in to comment.