-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from emidev98/feat/contract/execution
wip: contract execution
- Loading branch information
Showing
36 changed files
with
2,807 additions
and
249 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
syntax = "proto3"; | ||
package cosmwasmlifecycle; | ||
|
||
import "gogoproto/gogo.proto"; | ||
import "cosmos_proto/cosmos.proto"; | ||
import "cosmos/base/v1beta1/coin.proto"; | ||
import "cosmwasmlifecycle/execution_type.proto"; | ||
|
||
option go_package = "github.com/emidev98/cosmwasm-lifecycle/x/cosmwasmlifecycle/types"; | ||
|
||
// Contract defines the parameters for the module. | ||
message Contract { | ||
// Amount of strikes that the contract has at the moment. | ||
int64 strikes = 1; | ||
|
||
// Contract's execution type | ||
ExecutionType execution_type = 2; | ||
|
||
// Collateral deposited to the contract. | ||
cosmos.base.v1beta1.Coin deposit = 3 [ | ||
(gogoproto.nullable) = false, | ||
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Coin" | ||
]; | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
syntax = "proto3"; | ||
package cosmwasmlifecycle; | ||
|
||
import "cosmos_proto/cosmos.proto"; | ||
option go_package = "github.com/emidev98/cosmwasm-lifecycle/x/cosmwasmlifecycle/types"; | ||
|
||
message ContractDeleteEvent { | ||
string module_name = 1; | ||
string contract_address = 2 [ (cosmos_proto.scalar) = "cosmos.AddressString" ]; | ||
} | ||
|
||
message ContractStrikeEvent { | ||
string module_name = 1; | ||
string contract_address = 2 [ (cosmos_proto.scalar) = "cosmos.AddressString" ]; | ||
int64 current_strike = 3; | ||
string strike_reason = 4; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
syntax = "proto3"; | ||
package cosmwasmlifecycle; | ||
|
||
option go_package = "github.com/emidev98/cosmwasm-lifecycle/x/cosmwasmlifecycle/types"; | ||
|
||
enum ExecutionType { | ||
BEGIN_AND_END_BLOCK = 0; | ||
BEGIN_BLOCK = 1; | ||
END_BLOCK = 2; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
syntax = "proto3"; | ||
package cosmwasmlifecycle; | ||
|
||
import "gogoproto/gogo.proto"; | ||
import "cosmos_proto/cosmos.proto"; | ||
import "cosmwasmlifecycle/params.proto"; | ||
import "cosmwasmlifecycle/contract.proto"; | ||
|
||
option go_package = "github.com/emidev98/cosmwasm-lifecycle/x/cosmwasmlifecycle/types"; | ||
|
||
// GenesisState defines the cosmwasmlifecycle module's genesis state. | ||
message GenesisState { | ||
Params params = 1 [(gogoproto.nullable) = false]; | ||
|
||
// Contracts with their current information | ||
// about the execution state. | ||
repeated Contract contracts = 2 [ (cosmos_proto.scalar) = "cosmos.AddressString" ]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
syntax = "proto3"; | ||
package cosmwasmlifecycle; | ||
|
||
import "gogoproto/gogo.proto"; | ||
import "cosmos/base/v1beta1/coin.proto"; | ||
|
||
option go_package = "github.com/emidev98/cosmwasm-lifecycle/x/cosmwasmlifecycle/types"; | ||
|
||
// Params defines the parameters for the module. | ||
message Params { | ||
option (gogoproto.goproto_stringer) = false; | ||
// Enable or disable executions | ||
// at the begin and end of the block | ||
bool is_enabled = 1; | ||
|
||
// Minimum deposit to enable contract execution at begin block and/or end block | ||
// This deposit will be burned if the contract execution reaches the max strikes. | ||
cosmos.base.v1beta1.Coin min_deposit = 2 [ | ||
(gogoproto.nullable) = false, | ||
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Coin" | ||
]; | ||
|
||
// Amount of strikes that the contract can hold before being | ||
// disabled from end and beging block executions. | ||
// When this happens the min_desposit will also be burned. | ||
int64 strikes_to_disable_execution = 3; | ||
} |
6 changes: 3 additions & 3 deletions
6
...smlifecycle/cosmwasmlifecycle/query.proto → proto/cosmwasmlifecycle/query.proto
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
syntax = "proto3"; | ||
package cosmwasmlifecycle; | ||
import "gogoproto/gogo.proto"; | ||
import "cosmos_proto/cosmos.proto"; | ||
import "cosmwasmlifecycle/execution_type.proto"; | ||
|
||
option go_package = "github.com/emidev98/cosmwasm-lifecycle/x/cosmwasmlifecycle/types"; | ||
|
||
// Msg defines the Msg service. | ||
service Msg { | ||
rpc EnableContractBlockExecution(MsgEnableContractBlockExecution) returns (MsgEnableContractBlockExecutionResponse); | ||
rpc DisableContractBlockExecution(MsgDisableContractBlockExecution) returns (MsgDisableContractBlockExecutionResponse); | ||
} | ||
|
||
message MsgEnableContractBlockExecution { | ||
option (gogoproto.equal) = true; | ||
option (gogoproto.goproto_getters) = true; | ||
|
||
string contract_address = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"]; | ||
ExecutionType execution = 2; | ||
} | ||
message MsgEnableContractBlockExecutionResponse {} | ||
|
||
message MsgDisableContractBlockExecution { | ||
option (gogoproto.equal) = true; | ||
option (gogoproto.goproto_getters) = true; | ||
|
||
string contract_address = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"]; | ||
ExecutionType execution = 2; | ||
} | ||
message MsgDisableContractBlockExecutionResponse {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,13 @@ | ||
# CosmWasm Lifecycle | ||
<center> | ||
<h1>CosmWasm Lifecycle Module</h1> | ||
</center> | ||
|
||
![IMG](./docs/logo.jpg) | ||
|
||
CosmWasm Lifecycle blockchain module leverages [CosmoSDK's lifecycle](https://docs.cosmos.network/main/build/building-modules/beginblock-endblock) to facilitate the execution of smart contracts at the initiation and conclusion of each block. Given the necessity for swift and resource-light execution in both stages, this module mandates [Gov](https://docs.cosmos.network/main/build/modules/gov) voting and demands a collateral deposit for each smart contract on an individual basis. This collateral deposit will be burned if the smart contract fails to execute multiple times. | ||
|
||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package keeper | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/emidev98/cosmwasm-lifecycle/x/cosmwasmlifecycle/types" | ||
) | ||
|
||
func (k Keeper) GetContract(ctx sdk.Context, contractAddr sdk.AccAddress) (d types.Contract, found bool) { | ||
key := types.GetContractKeyByAddress(contractAddr) | ||
b := ctx.KVStore(k.storeKey).Get(key) | ||
if b == nil { | ||
return d, false | ||
} | ||
k.cdc.MustUnmarshal(b, &d) | ||
return d, true | ||
} | ||
|
||
func (k Keeper) SetContract(ctx sdk.Context, contractAddr sdk.AccAddress, contract types.Contract) { | ||
key := types.GetContractKeyByAddress(contractAddr) | ||
b := k.cdc.MustMarshal(&contract) | ||
ctx.KVStore(k.storeKey).Set(key, b) | ||
} | ||
|
||
func (k Keeper) DeleteContract(ctx sdk.Context, contractAddr sdk.AccAddress) { | ||
key := types.GetContractKeyByAddress(contractAddr) | ||
store := ctx.KVStore(k.storeKey) | ||
store.Delete(key) | ||
} | ||
|
||
func (k Keeper) IterateContracts(ctx sdk.Context, cb func(contractAddr sdk.AccAddress, contract types.Contract) error) (err error) { | ||
store := ctx.KVStore(k.storeKey) | ||
iter := sdk.KVStorePrefixIterator(store, types.ContractKey) | ||
defer iter.Close() | ||
for ; iter.Valid(); iter.Next() { | ||
var contract types.Contract | ||
b := iter.Value() | ||
k.cdc.MustUnmarshal(b, &contract) | ||
err = cb(iter.Key(), contract) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
|
||
return nil | ||
} |
Oops, something went wrong.