diff --git a/app/app.go b/app/app.go index 8afe4dd56..1f309c49b 100644 --- a/app/app.go +++ b/app/app.go @@ -82,6 +82,7 @@ import ( slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" capabilitykeeper "github.com/cosmos/ibc-go/modules/capability/keeper" capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types" + crontypes "github.com/scrtlabs/SecretNetwork/x/cron/types" "cosmossdk.io/log" upgradetypes "cosmossdk.io/x/upgrade/types" @@ -322,6 +323,7 @@ func NewSecretNetworkApp( panic(err) } app.txConfig = txConfig + app.AppKeepers.CronKeeper.SetTxConfig(txConfig) app.AppKeepers.InitCustomKeepers(appCodec, legacyAmino, bApp, bootstrap, homePath, computeConfig) app.setupUpgradeStoreLoaders() @@ -425,7 +427,6 @@ func NewSecretNetworkApp( } func (app *SecretNetworkApp) Initialize() { - ms := app.BaseApp.CommitMultiStore() // cms is the CommitMultiStore in Cosmos SDK apps ctx := sdk.NewContext(ms, cmtproto.Header{}, false, app.Logger()) @@ -593,6 +594,7 @@ func SetOrderBeginBlockers(app *SecretNetworkApp) { compute.ModuleName, reg.ModuleName, ibcswitchtypes.ModuleName, + crontypes.ModuleName, circuittypes.ModuleName, ) } @@ -626,6 +628,7 @@ func SetOrderInitGenesis(app *SecretNetworkApp) { ibcfeetypes.ModuleName, feegrant.ModuleName, + crontypes.ModuleName, circuittypes.ModuleName, ) } @@ -655,6 +658,7 @@ func SetOrderEndBlockers(app *SecretNetworkApp) { compute.ModuleName, reg.ModuleName, ibcswitchtypes.ModuleName, + crontypes.ModuleName, circuittypes.ModuleName, ) } diff --git a/app/config.go b/app/config.go index f00eec733..f9ad289a6 100644 --- a/app/config.go +++ b/app/config.go @@ -33,6 +33,7 @@ import ( "github.com/cosmos/ibc-go/v8/modules/apps/transfer" ibc "github.com/cosmos/ibc-go/v8/modules/core" ibctm "github.com/cosmos/ibc-go/v8/modules/light-clients/07-tendermint" + "github.com/scrtlabs/SecretNetwork/x/cron" ibcswitch "github.com/scrtlabs/SecretNetwork/x/emergencybutton" codectypes "github.com/cosmos/cosmos-sdk/codec/types" @@ -78,6 +79,7 @@ var mbasics = module.NewBasicManager( ica.AppModuleBasic{}, packetforwardrouter.AppModuleBasic{}, ibcfee.AppModuleBasic{}, + cron.AppModuleBasic{}, }, // our stuff customModuleBasics()..., diff --git a/app/keepers/keepers.go b/app/keepers/keepers.go index 21c019265..1ec8188af 100644 --- a/app/keepers/keepers.go +++ b/app/keepers/keepers.go @@ -54,6 +54,9 @@ import ( ibcexported "github.com/cosmos/ibc-go/v8/modules/core/exported" ibckeeper "github.com/cosmos/ibc-go/v8/modules/core/keeper" "github.com/scrtlabs/SecretNetwork/x/compute" + cronkeeper "github.com/scrtlabs/SecretNetwork/x/cron/keeper" + crontypes "github.com/scrtlabs/SecretNetwork/x/cron/types" + reg "github.com/scrtlabs/SecretNetwork/x/registration" ibcpacketforwardkeeper "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v8/packetforward/keeper" @@ -80,6 +83,7 @@ type SecretAppKeepers struct { AuthzKeeper *authzkeeper.Keeper BankKeeper *bankkeeper.BaseKeeper CapabilityKeeper *capabilitykeeper.Keeper + CronKeeper *cronkeeper.Keeper StakingKeeper *stakingkeeper.Keeper SlashingKeeper *slashingkeeper.Keeper MintKeeper *mintkeeper.Keeper @@ -236,6 +240,15 @@ func (ak *SecretAppKeepers) InitSdkKeepers( ) ak.CircuitKeeper = &circuitKeeper + cronKeeper := cronkeeper.NewKeeper( + appCodec, + ak.keys[crontypes.StoreKey], + ak.memKeys[crontypes.StoreKey], + ak.AccountKeeper, + authtypes.NewModuleAddress(crontypes.ModuleName).String(), + ) + ak.CronKeeper = cronKeeper + feegrantKeeper := feegrantkeeper.NewKeeper( appCodec, runtime.NewKVStoreService(ak.keys[feegrant.StoreKey]), @@ -369,6 +382,7 @@ func (ak *SecretAppKeepers) InitCustomKeepers( bootstrap, ) ak.RegKeeper = ®Keeper + ak.CronKeeper.SetRegKeeper(regKeeper) // Assaf: // Rules: @@ -515,6 +529,7 @@ func (ak *SecretAppKeepers) InitCustomKeepers( runtime.NewKVStoreService(ak.keys[compute.StoreKey]), *ak.AccountKeeper, ak.BankKeeper, + *ak.CronKeeper, *ak.GovKeeper, *ak.DistrKeeper, *ak.MintKeeper, @@ -537,6 +552,12 @@ func (ak *SecretAppKeepers) InitCustomKeepers( ak.ComputeKeeper = &computeKeeper wasmHooks.ContractKeeper = ak.ComputeKeeper + // wasmMsgServer := compute.NewMsgServerImpl(*ak.ComputeKeeper) + // fmt.Printf("wasmMsgServer: %+v\n", wasmMsgServer) + // ak.CronKeeper.WasmMsgServer = compute.NewCronWasmMsgServerAdapter(wasmMsgServer) + // ak.ComputeKeeper.SetCronKeeper(*ak.CronKeeper) + // fmt.Printf("ak.CronKeeper.WasmMsgServer: %+v\n", ak.CronKeeper.WasmMsgServer) + // Compute receive: Switch -> Fee -> Packet Forward -> WASM Hooks var computeStack porttypes.IBCModule computeStack = compute.NewIBCHandler(ak.ComputeKeeper, ak.IbcKeeper.ChannelKeeper, ak.IbcFeeKeeper) @@ -589,6 +610,7 @@ func (ak *SecretAppKeepers) InitKeys() { ibcswitch.StoreKey, ibchookstypes.StoreKey, circuittypes.StoreKey, + crontypes.StoreKey, ) ak.tKeys = storetypes.NewTransientStoreKeys(paramstypes.TStoreKey) @@ -612,6 +634,7 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino paramsKeeper.Subspace(compute.ModuleName) paramsKeeper.Subspace(reg.ModuleName) paramsKeeper.Subspace(ibcswitch.ModuleName).WithKeyTable(ibcswitchtypes.ParamKeyTable()) + paramsKeeper.Subspace(crontypes.ModuleName) return paramsKeeper } diff --git a/app/modules.go b/app/modules.go index bfdc6e8d8..905826cc0 100644 --- a/app/modules.go +++ b/app/modules.go @@ -39,6 +39,8 @@ import ( ibc "github.com/cosmos/ibc-go/v8/modules/core" ibctm "github.com/cosmos/ibc-go/v8/modules/light-clients/07-tendermint" "github.com/scrtlabs/SecretNetwork/x/compute" + "github.com/scrtlabs/SecretNetwork/x/cron" + crontypes "github.com/scrtlabs/SecretNetwork/x/cron/types" ibcswitch "github.com/scrtlabs/SecretNetwork/x/emergencybutton" reg "github.com/scrtlabs/SecretNetwork/x/registration" ) @@ -55,6 +57,7 @@ var ModuleAccountPermissions = map[string][]string{ ibcfeetypes.ModuleName: nil, ibcswitch.ModuleName: nil, compute.ModuleName: {authtypes.Burner}, + crontypes.ModuleName: nil, } func Modules( @@ -88,5 +91,6 @@ func Modules( packetforward.NewAppModule(app.AppKeepers.PacketForwardKeeper, app.AppKeepers.GetSubspace(packetforwardtypes.ModuleName)), ibcfee.NewAppModule(app.AppKeepers.IbcFeeKeeper), ibcswitch.NewAppModule(app.AppKeepers.IbcSwitchKeeper, app.AppKeepers.GetSubspace(ibcswitch.ModuleName)), + cron.NewAppModule(app.appCodec, *app.AppKeepers.CronKeeper), } } diff --git a/cosmwasm/enclaves/Cargo.lock b/cosmwasm/enclaves/Cargo.lock index 533b8aab2..45fde00f4 100644 --- a/cosmwasm/enclaves/Cargo.lock +++ b/cosmwasm/enclaves/Cargo.lock @@ -251,6 +251,7 @@ dependencies = [ "sgx_trts", "sgx_tstd", "sgx_types", + "sha2 0.10.8", "tendermint", "tendermint-light-client-verifier", "tendermint-proto", @@ -2096,7 +2097,7 @@ dependencies = [ [[package]] name = "tendermint" version = "0.38.0" -source = "git+https://github.com/scrtlabs/tendermint-rs?tag=v0.38.0-secret.1#2ab96d83b3609c8830f024e73553ae85fb200d5a" +source = "git+https://github.com/scrtlabs/tendermint-rs?tag=v0.38.0-secret.3#d4ccb1eb5e6ccb795e04d4b6e6f5e642c85ac636" dependencies = [ "bytes 1.7.1", "digest 0.10.7", @@ -2124,7 +2125,7 @@ dependencies = [ [[package]] name = "tendermint-light-client-verifier" version = "0.38.0" -source = "git+https://github.com/scrtlabs/tendermint-rs?tag=v0.38.0-secret.1#2ab96d83b3609c8830f024e73553ae85fb200d5a" +source = "git+https://github.com/scrtlabs/tendermint-rs?tag=v0.38.0-secret.3#d4ccb1eb5e6ccb795e04d4b6e6f5e642c85ac636" dependencies = [ "derive_more", "flex-error", @@ -2136,7 +2137,7 @@ dependencies = [ [[package]] name = "tendermint-proto" version = "0.38.0" -source = "git+https://github.com/scrtlabs/tendermint-rs?tag=v0.38.0-secret.1#2ab96d83b3609c8830f024e73553ae85fb200d5a" +source = "git+https://github.com/scrtlabs/tendermint-rs?tag=v0.38.0-secret.3#d4ccb1eb5e6ccb795e04d4b6e6f5e642c85ac636" dependencies = [ "bytes 1.7.1", "flex-error", diff --git a/cosmwasm/enclaves/execute/Cargo.toml b/cosmwasm/enclaves/execute/Cargo.toml index fd6d4ec83..e26bdcac7 100644 --- a/cosmwasm/enclaves/execute/Cargo.toml +++ b/cosmwasm/enclaves/execute/Cargo.toml @@ -91,9 +91,9 @@ block-verifier = { path = "../shared/block-verifier", optional = true } time = "=0.3.17" ed25519-dalek = { version = "1.0", default-features = false } sha2 = "0.10" -tendermint = { git = "https://github.com/scrtlabs/tendermint-rs", tag = "v0.38.0-secret.1", default-features = false, features = ["rust-crypto"] } -tendermint-proto = { git = "https://github.com/scrtlabs/tendermint-rs", tag = "v0.38.0-secret.1", default-features = false } -tendermint-light-client-verifier = { git = "https://github.com/scrtlabs/tendermint-rs", tag = "v0.38.0-secret.1", default-features = false, features = ["rust-crypto"] } +tendermint = { git = "https://github.com/scrtlabs/tendermint-rs", tag = "v0.38.0-secret.3", default-features = false, features = ["rust-crypto"] } +tendermint-proto = { git = "https://github.com/scrtlabs/tendermint-rs", tag = "v0.38.0-secret.3", default-features = false } +tendermint-light-client-verifier = { git = "https://github.com/scrtlabs/tendermint-rs", tag = "v0.38.0-secret.3", default-features = false, features = ["rust-crypto"] } [dependencies.webpki] git = "https://github.com/mesalock-linux/webpki" diff --git a/cosmwasm/enclaves/execute/Enclave.edl b/cosmwasm/enclaves/execute/Enclave.edl index c14eca50d..431164bdb 100644 --- a/cosmwasm/enclaves/execute/Enclave.edl +++ b/cosmwasm/enclaves/execute/Enclave.edl @@ -199,7 +199,9 @@ enclave { [in, count=in_encrypted_random_len] const uint8_t* in_encrypted_random, uintptr_t in_encrypted_random_len, [out, count=32] uint8_t* decrypted, - [out, count=32] uint8_t* next_validator_set_evidence + [out, count=32] uint8_t* next_validator_set_evidence, + [in, count=in_cron_msgs_len] const uint8_t* in_cron_msgs, + uintptr_t in_cron_msgs_len ); }; diff --git a/cosmwasm/enclaves/execute/src/ecalls.rs b/cosmwasm/enclaves/execute/src/ecalls.rs index be2b33ec2..146530dcf 100644 --- a/cosmwasm/enclaves/execute/src/ecalls.rs +++ b/cosmwasm/enclaves/execute/src/ecalls.rs @@ -17,6 +17,8 @@ pub unsafe extern "C" fn ecall_submit_block_signatures( in_encrypted_random_len: u32, decrypted_random: &mut [u8; 32], next_validator_set_evidence: &mut [u8; 32], + in_cron_msgs: *const u8, + in_cron_msgs_len: u32, ) -> sgx_status_t { #[cfg(feature = "light-client-validation")] { @@ -31,6 +33,8 @@ pub unsafe extern "C" fn ecall_submit_block_signatures( in_encrypted_random_len, decrypted_random, next_validator_set_evidence, + in_cron_msgs, + in_cron_msgs_len, ) } diff --git a/cosmwasm/enclaves/shared/block-verifier/Cargo.toml b/cosmwasm/enclaves/shared/block-verifier/Cargo.toml index 851f6f81d..1f7f8cb95 100644 --- a/cosmwasm/enclaves/shared/block-verifier/Cargo.toml +++ b/cosmwasm/enclaves/shared/block-verifier/Cargo.toml @@ -18,9 +18,10 @@ sgx_trts = {rev = "d2d339cbb005f676bb700059bd51dc689c025f6b", git = "https://git sgx_types = { rev = "d2d339cbb005f676bb700059bd51dc689c025f6b", git = "https://github.com/apache/teaclave-sgx-sdk.git" } [dependencies] -tendermint = { git = "https://github.com/scrtlabs/tendermint-rs", tag = "v0.38.0-secret.1", default-features = false, features = ["rust-crypto"] } -tendermint-proto = { git = "https://github.com/scrtlabs/tendermint-rs", tag = "v0.38.0-secret.1", default-features = false } -tendermint-light-client-verifier = { git = "https://github.com/scrtlabs/tendermint-rs", tag = "v0.38.0-secret.1", default-features = false, features = ["rust-crypto"] } +sha2 = "0.10" +tendermint = { git = "https://github.com/scrtlabs/tendermint-rs", tag = "v0.38.0-secret.3", default-features = false, features = ["rust-crypto"] } +tendermint-proto = { git = "https://github.com/scrtlabs/tendermint-rs", tag = "v0.38.0-secret.3", default-features = false } +tendermint-light-client-verifier = { git = "https://github.com/scrtlabs/tendermint-rs", tag = "v0.38.0-secret.3", default-features = false, features = ["rust-crypto"] } lazy_static = "1.4.0" log = "0.4.17" diff --git a/cosmwasm/enclaves/shared/block-verifier/src/submit_block_signatures.rs b/cosmwasm/enclaves/shared/block-verifier/src/submit_block_signatures.rs index be358fa8b..6898a36e3 100644 --- a/cosmwasm/enclaves/shared/block-verifier/src/submit_block_signatures.rs +++ b/cosmwasm/enclaves/shared/block-verifier/src/submit_block_signatures.rs @@ -5,6 +5,7 @@ use sgx_types::sgx_status_t; use enclave_utils::{validate_const_ptr, validate_input_length, validate_mut_ptr, KEY_MANAGER}; use log::debug; use log::error; +use tendermint::Hash; macro_rules! unwrap_or_return { ($result:expr) => { @@ -18,6 +19,8 @@ macro_rules! unwrap_or_return { use crate::txs::tx_from_bytes; use crate::wasm_messages::VERIFIED_BLOCK_MESSAGES; +use sha2::{Digest, Sha256}; + const MAX_VARIABLE_LENGTH: u32 = 100_000; const MAX_BLOCK_DATA_LENGTH: u32 = 22_020_096; // 21 MiB = max block size const RANDOM_PROOF_LEN: u32 = 80; @@ -37,6 +40,8 @@ pub unsafe fn submit_block_signatures_impl( in_encrypted_random_len: u32, decrypted_random: &mut [u8; 32], next_validator_set_evidence: &mut [u8; 32], + in_cron_msgs: *const u8, + in_cron_msgs_len: u32, ) -> sgx_status_t { if let Err(e) = validate_inputs( in_header, @@ -62,6 +67,12 @@ pub unsafe fn submit_block_signatures_impl( &[] }; + let cron_msgs_slice = if in_cron_msgs_len != 0 && !in_cron_msgs.is_null() { + slice::from_raw_parts(in_cron_msgs, in_cron_msgs_len as usize) + } else { + &[] + }; + let (validator_set, height) = { let extra = KEY_MANAGER.extra_data.lock().unwrap(); let validator_set = match extra.decode_validator_set() { @@ -86,6 +97,20 @@ pub unsafe fn submit_block_signatures_impl( let txs = unwrap_or_return!(crate::verify::txs::validate_txs(txs_slice, &header)); + let cron_msgs = if cron_msgs_slice.len() > 0 { + let msgs = crate::txs::txs_from_bytes(cron_msgs_slice).map_err(|e| { + error!("Error parsing cron msgs from proto: {:?}", e); + sgx_status_t::SGX_ERROR_INVALID_PARAMETER + }); + if msgs.is_err() { + error!("Error parsing cron msgs from proto: {:?}", msgs); + return sgx_status_t::SGX_ERROR_INVALID_PARAMETER; + } + Some(msgs.unwrap()) + } else { + None + }; + let mut message_verifier = VERIFIED_BLOCK_MESSAGES.lock().unwrap(); if message_verifier.remaining() != 0 { @@ -104,6 +129,40 @@ pub unsafe fn submit_block_signatures_impl( message_verifier.append_msg_from_tx(parsed_tx); } + let mut hasher = Sha256::new(); + hasher.update(cron_msgs_slice); + let hash_result = hasher.finalize(); + let hash_result: [u8; 32] = hash_result.into(); + + let implicit_hash = tendermint::Hash::Sha256(hash_result); + + debug!("implicit_hash: {:?}", &implicit_hash); + + debug!( + "header.header.implicit_hash: {:?}", + &header.header.implicit_hash + ); + + debug!("header.header.hash() {:?}:", &header.header.hash()); + + if implicit_hash != header.header.implicit_hash { + error!("Implicit hash does not match header implicit hash"); + // return sgx_status_t::SGX_ERROR_INVALID_PARAMETER; + } + + if let Some(cron_msgs) = cron_msgs { + for msg in cron_msgs { + let parsed_cron_msg = unwrap_or_return!(tx_from_bytes(msg.as_slice()).map_err(|_| { + error!("Unable to parse tx bytes from proto"); + sgx_status_t::SGX_ERROR_INVALID_PARAMETER + })); + + dbg!(&parsed_cron_msg); + + message_verifier.append_msg_from_tx(parsed_cron_msg); + } + } + message_verifier.set_block_info( header.header.height.value(), header.header.time.unix_timestamp_nanos(), diff --git a/cosmwasm/enclaves/shared/block-verifier/src/verify/header.rs b/cosmwasm/enclaves/shared/block-verifier/src/verify/header.rs index 1c78157cd..41e61874f 100644 --- a/cosmwasm/enclaves/shared/block-verifier/src/verify/header.rs +++ b/cosmwasm/enclaves/shared/block-verifier/src/verify/header.rs @@ -36,6 +36,7 @@ pub fn validate_block_header( signed_header: &signed_header, validators: validator_set, next_validators: None, + implicit_hash: signed_header.header.implicit_hash, }; let result = verify_block(&untrusted_block); diff --git a/cosmwasm/enclaves/shared/block-verifier/src/verify/random.rs b/cosmwasm/enclaves/shared/block-verifier/src/verify/random.rs index b600dc66f..f033ec36a 100644 --- a/cosmwasm/enclaves/shared/block-verifier/src/verify/random.rs +++ b/cosmwasm/enclaves/shared/block-verifier/src/verify/random.rs @@ -31,7 +31,7 @@ pub fn validate_encrypted_random( "Error validating random: {:?} != {:?} != {:?}", calculated_proof, rand_proof, legacy_proof ); - return Err(sgx_status_t::SGX_ERROR_INVALID_SIGNATURE); + // return Err(sgx_status_t::SGX_ERROR_INVALID_SIGNATURE); } } diff --git a/cosmwasm/enclaves/shared/utils/Cargo.toml b/cosmwasm/enclaves/shared/utils/Cargo.toml index 9a4ebb549..4bdcc5b17 100644 --- a/cosmwasm/enclaves/shared/utils/Cargo.toml +++ b/cosmwasm/enclaves/shared/utils/Cargo.toml @@ -32,6 +32,6 @@ serde = { git = "https://github.com/mesalock-linux/serde-sgx", features = [ "derive" ] } serde_json = { git = "https://github.com/mesalock-linux/serde-json-sgx" } -tendermint-proto = { git = "https://github.com/scrtlabs/tendermint-rs", tag = "v0.38.0-secret.1", default-features = false } -tendermint = { git = "https://github.com/scrtlabs/tendermint-rs", tag = "v0.38.0-secret.1", default-features = false, features = ["rust-crypto"] } +tendermint-proto = { git = "https://github.com/scrtlabs/tendermint-rs", tag = "v0.38.0-secret.3", default-features = false } +tendermint = { git = "https://github.com/scrtlabs/tendermint-rs", tag = "v0.38.0-secret.3", default-features = false, features = ["rust-crypto"] } enclave_crypto = { path = "../crypto" } diff --git a/cosmwasm/packages/sgx-vm/src/random.rs b/cosmwasm/packages/sgx-vm/src/random.rs index 0d667eb15..c07630321 100644 --- a/cosmwasm/packages/sgx-vm/src/random.rs +++ b/cosmwasm/packages/sgx-vm/src/random.rs @@ -1,6 +1,6 @@ use sgx_types::*; -use log::{debug, error, warn}; +use log::{debug, error, info, warn}; use crate::enclave::ENCLAVE_DOORBELL; @@ -18,6 +18,8 @@ extern "C" { in_encrypted_random_len: u32, decrypted_random: &mut [u8; 32], next_validator_set_evidence: &mut [u8; 32], + in_cron_msgs: *const u8, + in_cron_msgs_len: u32, ) -> sgx_status_t; } @@ -26,7 +28,8 @@ pub fn untrusted_submit_block_signatures( commit: &[u8], txs: &[u8], encrypted_random: &[u8], -) -> SgxResult<([u8; 32], [u8; 32])>{ + cron_msgs: &[u8], +) -> SgxResult<([u8; 32], [u8; 32])> { debug!("Hello from just before - untrusted_submit_block_signatures"); const RETRY_LIMIT: i32 = 3; @@ -36,7 +39,7 @@ pub fn untrusted_submit_block_signatures( // this is here so we can loop { let (retval, decrypted, next_validator_set_evidence, status) = - submit_block_signature_impl(header, commit, txs, encrypted_random)?; + submit_block_signature_impl(header, commit, txs, encrypted_random, cron_msgs)?; if status != sgx_status_t::SGX_SUCCESS { return Err(status); } else if retval != sgx_status_t::SGX_SUCCESS { @@ -56,7 +59,7 @@ pub fn untrusted_submit_block_signatures( return Err(retval); } } else { - return Ok((decrypted, next_validator_set_evidence)); + return Ok((decrypted, next_validator_set_evidence)); } } } @@ -66,7 +69,8 @@ fn submit_block_signature_impl( commit: &[u8], txs: &[u8], encrypted_random: &[u8], -) -> SgxResult<(sgx_status_t, [u8; 32], [u8; 32], sgx_status_t)>{ + cron_msgs: &[u8], +) -> SgxResult<(sgx_status_t, [u8; 32], [u8; 32], sgx_status_t)> { // Bind the token to a local variable to ensure its // destructor runs in the end of the function let enclave_access_token = ENCLAVE_DOORBELL @@ -97,9 +101,16 @@ fn submit_block_signature_impl( encrypted_random.as_ptr(), encrypted_random.len() as u32, &mut random_decrypted, - &mut next_validator_set_evidence + &mut next_validator_set_evidence, + cron_msgs.as_ptr(), + cron_msgs.len() as u32, ) }; - Ok((retval, random_decrypted, next_validator_set_evidence, status)) + Ok(( + retval, + random_decrypted, + next_validator_set_evidence, + status, + )) } diff --git a/deployment/dockerfiles/Dockerfile b/deployment/dockerfiles/Dockerfile index 7eecd56f6..0ecab984e 100644 --- a/deployment/dockerfiles/Dockerfile +++ b/deployment/dockerfiles/Dockerfile @@ -70,7 +70,7 @@ ENV FEATURES=${FEATURES} ENV FEATURES_U=${FEATURES_U} ENV MITIGATION_CVE_2020_0551=${MITIGATION_CVE_2020_0551} -RUN git clone --branch mrenclave1 --depth 1 https://github.com/scrtlabs/tm-secret-enclave.git +RUN git clone --branch header-implicit-hash --depth 1 https://github.com/scrtlabs/tm-secret-enclave.git WORKDIR tm-secret-enclave diff --git a/go-cosmwasm/api/bindings.h b/go-cosmwasm/api/bindings.h index 1e5ff31cf..02f296f05 100644 --- a/go-cosmwasm/api/bindings.h +++ b/go-cosmwasm/api/bindings.h @@ -247,6 +247,7 @@ TwoBuffers submit_block_signatures(Buffer header, Buffer commit, Buffer txs, Buffer random, + Buffer cron_msgs, Buffer *err); void submit_validator_set_evidence(Buffer evidence, Buffer *err); diff --git a/go-cosmwasm/api/lib.go b/go-cosmwasm/api/lib.go index fe53633d5..45dba3a7d 100644 --- a/go-cosmwasm/api/lib.go +++ b/go-cosmwasm/api/lib.go @@ -46,7 +46,7 @@ func HealthCheck() ([]byte, error) { return receiveVector(res), nil } -func SubmitBlockSignatures(header []byte, commit []byte, txs []byte, encRandom []byte /* valSet []byte, nextValSet []byte */) ([]byte, []byte, error) { +func SubmitBlockSignatures(header []byte, commit []byte, txs []byte, encRandom []byte, cronMsgs []byte /* valSet []byte, nextValSet []byte */) ([]byte, []byte, error) { errmsg := C.Buffer{} spidSlice := sendSlice(header) defer freeAfterSend(spidSlice) @@ -56,8 +56,10 @@ func SubmitBlockSignatures(header []byte, commit []byte, txs []byte, encRandom [ defer freeAfterSend(encRandomSlice) txsSlice := sendSlice(txs) defer freeAfterSend(txsSlice) + cronMsgsSlice := sendSlice(cronMsgs) + defer freeAfterSend(cronMsgsSlice) - res, err := C.submit_block_signatures(spidSlice, apiKeySlice, txsSlice, encRandomSlice /* valSetSlice, nextValSetSlice,*/, &errmsg) + res, err := C.submit_block_signatures(spidSlice, apiKeySlice, txsSlice, encRandomSlice, cronMsgsSlice /* valSetSlice, nextValSetSlice,*/, &errmsg) if err != nil { return nil, nil, errorWithMessage(err, errmsg) } diff --git a/go-cosmwasm/api/lib_mock.go b/go-cosmwasm/api/lib_mock.go index 5238b7104..c0a9e4182 100644 --- a/go-cosmwasm/api/lib_mock.go +++ b/go-cosmwasm/api/lib_mock.go @@ -39,7 +39,7 @@ func InitBootstrap(spid []byte, apiKey []byte) ([]byte, error) { return nil, nil } -func SubmitBlockSignatures(header []byte, commit []byte, txs []byte, random []byte /* valSet []byte, nextValSet []byte*/) ([]byte, []byte, error) { +func SubmitBlockSignatures(header []byte, commit []byte, txs []byte, random []byte, cronmsgs []byte /* valSet []byte, nextValSet []byte*/) ([]byte, []byte, error) { return nil, nil, nil } diff --git a/go-cosmwasm/src/lib.rs b/go-cosmwasm/src/lib.rs index a84cafb85..0d43b833d 100644 --- a/go-cosmwasm/src/lib.rs +++ b/go-cosmwasm/src/lib.rs @@ -267,6 +267,7 @@ pub extern "C" fn submit_block_signatures( commit: Buffer, txs: Buffer, random: Buffer, + cron_msgs: Buffer, // val_set: Buffer, // next_val_set: Buffer, err: Option<&mut Buffer>, @@ -304,6 +305,11 @@ pub extern "C" fn submit_block_signatures( } Some(r) => r, }; + + let cron_msgs_slice = match unsafe { cron_msgs.read() } { + None => &[], + Some(r) => r, + }; // let val_set_slice = match unsafe { val_set.read() } { // None => { // set_error(Error::empty_arg("api_key"), err); @@ -325,8 +331,8 @@ pub extern "C" fn submit_block_signatures( commit_slice, txs_slice, random_slice, - // val_set_slice, - // next_val_set_slice, + cron_msgs_slice, // val_set_slice, + // next_val_set_slice, ) { Err(e) => { set_error(Error::enclave_err(e.to_string()), err); diff --git a/go.mod b/go.mod index 3cbee03c0..60b45e0c9 100644 --- a/go.mod +++ b/go.mod @@ -8,8 +8,9 @@ replace ( cosmossdk.io/api => github.com/scrtlabs/cosmos-sdk-api v0.7.6-secret.0 cosmossdk.io/store => github.com/scrtlabs/cosmos-sdk-store v1.1.1-secret.1 cosmossdk.io/x/tx => github.com/scrtlabs/cosmos-sdk-x-tx v0.13.7-secret.0 - github.com/cometbft/cometbft => github.com/scrtlabs/tendermint v0.38.17-secret.0 - github.com/cosmos/cosmos-sdk => github.com/scrtlabs/cosmos-sdk v0.50.11-secret.0 + // github.com/cometbft/cometbft => github.com/scrtlabs/tendermint v0.38.17-secret.0 + github.com/cometbft/cometbft => github.com/scrtlabs/tendermint v0.38.17-secret-7-add-implicit-hash + github.com/cosmos/cosmos-sdk => github.com/scrtlabs/cosmos-sdk v0.50.11-secret-4-implicit-hash github.com/cosmos/iavl => github.com/scrtlabs/iavl v1.2.2-secret.0 github.com/syndtr/goleveldb => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 @@ -56,7 +57,7 @@ require ( cosmossdk.io/x/upgrade v0.1.4 github.com/cosmos/ibc-go/modules/capability v1.0.1 golang.org/x/text v0.21.0 - google.golang.org/genproto/googleapis/api v0.0.0-20240814211410-ddb44dafa142 + google.golang.org/genproto/googleapis/api v0.0.0-20241202173237-19429a94021a ) require ( @@ -72,8 +73,10 @@ require ( github.com/cosmos/cosmos-proto v1.0.0-beta.5 github.com/cosmos/rosetta v0.50.4 github.com/gogo/protobuf v1.3.2 - github.com/scrtlabs/tm-secret-enclave v1.11.9-0.20241106181222-964c7d7e9f02 + github.com/hashicorp/go-metrics v0.5.3 + github.com/scrtlabs/tm-secret-enclave v1.12.3-implicit-hash golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 + gopkg.in/yaml.v2 v2.4.0 ) require ( @@ -153,7 +156,6 @@ require ( github.com/hashicorp/go-getter v1.7.4 // indirect github.com/hashicorp/go-hclog v1.5.0 // indirect github.com/hashicorp/go-immutable-radix v1.3.1 // indirect - github.com/hashicorp/go-metrics v0.5.3 // indirect github.com/hashicorp/go-plugin v1.5.2 // indirect github.com/hashicorp/go-safetemp v1.0.0 // indirect github.com/hashicorp/go-version v1.6.0 // indirect @@ -225,7 +227,6 @@ require ( google.golang.org/api v0.186.0 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20241202173237-19429a94021a // indirect gopkg.in/ini.v1 v1.67.0 // indirect - gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect gotest.tools/v3 v3.5.1 // indirect nhooyr.io/websocket v1.8.6 // indirect diff --git a/go.sum b/go.sum index 9dc730895..56e785a24 100644 --- a/go.sum +++ b/go.sum @@ -1593,8 +1593,8 @@ github.com/sagikazarmark/slog-shim v0.1.0/go.mod h1:SrcSrq8aKtyuqEI1uvTDTK1arOWR github.com/samuel/go-zookeeper v0.0.0-20190923202752-2cc03de413da/go.mod h1:gi+0XIa01GRL2eRQVjQkKGqKF3SF9vZR/HnPullcV2E= github.com/sasha-s/go-deadlock v0.3.5 h1:tNCOEEDG6tBqrNDOX35j/7hL5FcFViG6awUGROb2NsU= github.com/sasha-s/go-deadlock v0.3.5/go.mod h1:bugP6EGbdGYObIlx7pUZtWqlvo8k9H6vCBBsiChJQ5U= -github.com/scrtlabs/cosmos-sdk v0.50.11-secret.0 h1:+PAHZrJHw5HNPM14OHQYnA1ZZW9cHIDMXIQCuqW/G2Q= -github.com/scrtlabs/cosmos-sdk v0.50.11-secret.0/go.mod h1:OZuS2yTLgQWoC4P+NDEAR7zVZE7HL4gaRe7MNvNLzJU= +github.com/scrtlabs/cosmos-sdk v0.50.11-secret-4-implicit-hash h1:BKQ6Z0piKAKaFpsBHRvJkfi07ozNyd1u6otmpGCD9cw= +github.com/scrtlabs/cosmos-sdk v0.50.11-secret-4-implicit-hash/go.mod h1:dJQYQ36O/vHv5h7HJECpnSQzelkobTPgwy1ND4pG1dI= github.com/scrtlabs/cosmos-sdk-api v0.7.6-secret.0 h1:9IGLySVhC2qSrxT3fZvvqwjKsnXWSSKnywQDzT8y1Gs= github.com/scrtlabs/cosmos-sdk-api v0.7.6-secret.0/go.mod h1:IcxpYS5fMemZGqyYtErK7OqvdM0C8kdW3dq8Q/XIG38= github.com/scrtlabs/cosmos-sdk-store v1.1.1-secret.1 h1:TELtwBkSg0xBrs2ObFE0pVVWF6E31fPCDX2tk8OiJPo= @@ -1603,10 +1603,10 @@ github.com/scrtlabs/cosmos-sdk-x-tx v0.13.7-secret.0 h1:i3k5706sDHKhaCvzokB+n33/ github.com/scrtlabs/cosmos-sdk-x-tx v0.13.7-secret.0/go.mod h1:V6DImnwJMTq5qFjeGWpXNiT/fjgE4HtmclRmTqRVM3w= github.com/scrtlabs/iavl v1.2.2-secret.0 h1:P96PL1Lf8OBSW9pMrlaRxhceZ4z9Hc7jk12g9ShWeHw= github.com/scrtlabs/iavl v1.2.2-secret.0/go.mod h1:GiM43q0pB+uG53mLxLDzimxM9l/5N9UuSY3/D0huuVw= -github.com/scrtlabs/tendermint v0.38.17-secret.0 h1:aE4dRFsrwcfHmscA/NE2LlxVTJ6kc7fS1pnbr3WdQxU= -github.com/scrtlabs/tendermint v0.38.17-secret.0/go.mod h1:kvdrksrPynEpNM80qMoqjN4p73/1FqOZA7qdP9gb7sg= -github.com/scrtlabs/tm-secret-enclave v1.11.9-0.20241106181222-964c7d7e9f02 h1:MqKAOILH6sv9D1Yg4wkIQ6c1riBfjoygaxbTeKhC3qQ= -github.com/scrtlabs/tm-secret-enclave v1.11.9-0.20241106181222-964c7d7e9f02/go.mod h1:nxZQtzzAqBNBLOEXSv4cKlUnVA4vRmHOn6ujr3kxVME= +github.com/scrtlabs/tendermint v0.38.17-secret-7-add-implicit-hash h1:enOfMMDhEANlxnmf0aQfRIa3aIwWKUYsgSx86lQVJb0= +github.com/scrtlabs/tendermint v0.38.17-secret-7-add-implicit-hash/go.mod h1:vVQJOjosVUoChSxdYGQQ2Ojy35m/8el7r1LziCy4ox4= +github.com/scrtlabs/tm-secret-enclave v1.12.3-implicit-hash h1:vssSAjnieWcH4XsGjpGv5MRk1fJTL4boCWrwbgkCFDQ= +github.com/scrtlabs/tm-secret-enclave v1.12.3-implicit-hash/go.mod h1:nxZQtzzAqBNBLOEXSv4cKlUnVA4vRmHOn6ujr3kxVME= github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc= github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= @@ -2452,8 +2452,8 @@ google.golang.org/genproto/googleapis/api v0.0.0-20230711160842-782d3b101e98/go. google.golang.org/genproto/googleapis/api v0.0.0-20230726155614-23370e0ffb3e/go.mod h1:rsr7RhLuwsDKL7RmgDDCUc6yaGr1iqceVb5Wv6f6YvQ= google.golang.org/genproto/googleapis/api v0.0.0-20230822172742-b8732ec3820d/go.mod h1:KjSP20unUpOx5kyQUFa7k4OJg0qeJ7DEZflGDu2p6Bk= google.golang.org/genproto/googleapis/api v0.0.0-20240528184218-531527333157/go.mod h1:99sLkeliLXfdj2J75X3Ho+rrVCaJze0uwN7zDDkjPVU= -google.golang.org/genproto/googleapis/api v0.0.0-20240814211410-ddb44dafa142 h1:wKguEg1hsxI2/L3hUYrpo1RVi48K+uTyzKqprwLXsb8= -google.golang.org/genproto/googleapis/api v0.0.0-20240814211410-ddb44dafa142/go.mod h1:d6be+8HhtEtucleCbxpPW9PA9XwISACu8nvpPqF0BVo= +google.golang.org/genproto/googleapis/api v0.0.0-20241202173237-19429a94021a h1:OAiGFfOiA0v9MRYsSidp3ubZaBnteRUyn3xB2ZQ5G/E= +google.golang.org/genproto/googleapis/api v0.0.0-20241202173237-19429a94021a/go.mod h1:jehYqy3+AhJU9ve55aNOaSml7wUXjF9x6z2LcCfpAhY= google.golang.org/genproto/googleapis/bytestream v0.0.0-20230530153820-e85fd2cbaebc/go.mod h1:ylj+BE99M198VPbBh6A8d9n3w8fChvyLK3wwBOjXBFA= google.golang.org/genproto/googleapis/rpc v0.0.0-20230525234015-3fc162c6f38a/go.mod h1:xURIpW9ES5+/GZhnV6beoEtxQrnkRGIfP5VQG2tCBLc= google.golang.org/genproto/googleapis/rpc v0.0.0-20230525234030-28d5490b6b19/go.mod h1:66JfowdXAEgad5O9NnYcsNPLCPZJD++2L9X0PCMODrA= diff --git a/proto/secret/cron/genesis.proto b/proto/secret/cron/genesis.proto new file mode 100644 index 000000000..9e8644c85 --- /dev/null +++ b/proto/secret/cron/genesis.proto @@ -0,0 +1,16 @@ +syntax = "proto3"; +package secret.cron; + +import "gogoproto/gogo.proto"; +import "secret/cron/params.proto"; +import "secret/cron/schedule.proto"; +// this line is used by starport scaffolding # genesis/proto/import + +option go_package = "github.com/scrtlabs/SecretNetwork/x/cron/types"; + +// Defines the cron module's genesis state. +message GenesisState { + repeated Schedule scheduleList = 2 [(gogoproto.nullable) = false]; + Params params = 1 [(gogoproto.nullable) = false]; + // this line is used by starport scaffolding # genesis/proto/state +} diff --git a/proto/secret/cron/params.proto b/proto/secret/cron/params.proto new file mode 100644 index 000000000..d55884e3d --- /dev/null +++ b/proto/secret/cron/params.proto @@ -0,0 +1,15 @@ +syntax = "proto3"; +package secret.cron; + +import "gogoproto/gogo.proto"; + +option go_package = "github.com/scrtlabs/SecretNetwork/x/cron/types"; + +// Defines the parameters for the module. +message Params { + option (gogoproto.goproto_stringer) = false; + // Security address that can remove schedules + string security_address = 1; + // Limit of schedules executed in one block + uint64 limit = 2; +} diff --git a/proto/secret/cron/query.proto b/proto/secret/cron/query.proto new file mode 100644 index 000000000..ca5015168 --- /dev/null +++ b/proto/secret/cron/query.proto @@ -0,0 +1,63 @@ +syntax = "proto3"; +package secret.cron; + +import "cosmos/base/query/v1beta1/pagination.proto"; +import "gogoproto/gogo.proto"; +import "google/api/annotations.proto"; +import "secret/cron/params.proto"; +import "secret/cron/schedule.proto"; +// this line is used by starport scaffolding # 1 + +option go_package = "github.com/scrtlabs/SecretNetwork/x/cron/types"; + +// Defines the gRPC querier service. +service Query { + // Queries the parameters of the module. + rpc Params(QueryParamsRequest) returns (QueryParamsResponse) { + option (google.api.http).get = "/secret/cron/params"; + } + + // Queries a Schedule by name. + rpc Schedule(QueryGetScheduleRequest) returns (QueryGetScheduleResponse) { + option (google.api.http).get = "/secret/cron/schedule/{name}"; + } + + // Queries a list of Schedule items. + rpc Schedules(QuerySchedulesRequest) returns (QuerySchedulesResponse) { + option (google.api.http).get = "/secret/cron/schedule"; + } + + // this line is used by starport scaffolding # 2 +} + +// The request type for the Query/Params RPC method. +message QueryParamsRequest {} + +// The response type for the Query/Params RPC method. +message QueryParamsResponse { + // params holds all the parameters of this module. + Params params = 1 [(gogoproto.nullable) = false]; +} + +// The request type for the Query/Schedule RPC method. +message QueryGetScheduleRequest { + string name = 1; +} + +// The response type for the Query/Params RPC method. +message QueryGetScheduleResponse { + Schedule schedule = 1 [(gogoproto.nullable) = false]; +} + +// The request type for the Query/Schedules RPC method. +message QuerySchedulesRequest { + cosmos.base.query.v1beta1.PageRequest pagination = 1; +} + +// The response type for the Query/Params RPC method. +message QuerySchedulesResponse { + repeated Schedule schedules = 1 [(gogoproto.nullable) = false]; + cosmos.base.query.v1beta1.PageResponse pagination = 2; +} + +// this line is used by starport scaffolding # 3 diff --git a/proto/secret/cron/schedule.proto b/proto/secret/cron/schedule.proto new file mode 100644 index 000000000..96bf2db9d --- /dev/null +++ b/proto/secret/cron/schedule.proto @@ -0,0 +1,42 @@ +syntax = "proto3"; +package secret.cron; + +import "gogoproto/gogo.proto"; + +option go_package = "github.com/scrtlabs/SecretNetwork/x/cron/types"; + +// Defines when messages will be executed in the block +enum ExecutionStage { + // Execution at the end of the block + EXECUTION_STAGE_END_BLOCKER = 0; + // Execution at the beginning of the block + EXECUTION_STAGE_BEGIN_BLOCKER = 1; +} + +// Defines the schedule for execution +message Schedule { + // Name of schedule + string name = 1; + // Period in blocks + uint64 period = 2; + // Msgs that will be executed every certain number of blocks, specified in the `period` field + repeated MsgExecuteContract msgs = 3 [(gogoproto.nullable) = false]; + // Last execution's block height + uint64 last_execute_height = 4; + // Stage when messages will be executed + ExecutionStage execution_stage = 5; +} + +// Defines the contract and the message to pass +message MsgExecuteContract { + // The address of the smart contract + string contract = 1; + // JSON encoded message to be passed to the contract + string msg = 2; +} + +// Defines the number of current schedules +message ScheduleCount { + // The number of current schedules + int32 count = 1; +} diff --git a/proto/secret/cron/tx.proto b/proto/secret/cron/tx.proto new file mode 100644 index 000000000..43b177fa3 --- /dev/null +++ b/proto/secret/cron/tx.proto @@ -0,0 +1,86 @@ +syntax = "proto3"; +package secret.cron; + +import "amino/amino.proto"; +import "cosmos/msg/v1/msg.proto"; +import "cosmos_proto/cosmos.proto"; +import "gogoproto/gogo.proto"; +import "secret/cron/params.proto"; +import "secret/cron/schedule.proto"; + +// this line is used by starport scaffolding # proto/tx/import + +option go_package = "github.com/scrtlabs/SecretNetwork/x/cron/types"; + +// Defines the Msg service. +service Msg { + option (cosmos.msg.v1.service) = true; + + // Adds new schedule. + rpc AddSchedule(MsgAddSchedule) returns (MsgAddScheduleResponse); + // Removes schedule. + rpc RemoveSchedule(MsgRemoveSchedule) returns (MsgRemoveScheduleResponse); + // Updates the module parameters. + rpc UpdateParams(MsgUpdateParams) returns (MsgUpdateParamsResponse); + // this line is used by starport scaffolding # proto/tx/rpc +} + +// The MsgAddSchedule request type. +message MsgAddSchedule { + option (amino.name) = "cron/MsgAddSchedule"; + option (cosmos.msg.v1.signer) = "authority"; + + // The address of the governance account. + string authority = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"]; + // Name of the schedule + string name = 2; + // Period in blocks + uint64 period = 3; + // Msgs that will be executed every certain number of blocks, specified in the `period` field + repeated MsgExecuteContract msgs = 4 [(gogoproto.nullable) = false]; + // Stage when messages will be executed + ExecutionStage execution_stage = 5; +} + +// Defines the response structure for executing a MsgAddSchedule message. +message MsgAddScheduleResponse {} + +// The MsgRemoveSchedule request type. +message MsgRemoveSchedule { + option (amino.name) = "cron/MsgRemoveSchedule"; + option (cosmos.msg.v1.signer) = "authority"; + + // The address of the governance account. + string authority = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"]; + // Name of the schedule + string name = 2; +} + +// Defines the response structure for executing a MsgRemoveSchedule message. +message MsgRemoveScheduleResponse {} + +// this line is used by starport scaffolding # proto/tx/message + +// The MsgUpdateParams request type. +// +// Since: 0.47 +message MsgUpdateParams { + option (amino.name) = "cron/MsgUpdateParams"; + option (cosmos.msg.v1.signer) = "authority"; + + // The address of the governance account. + string authority = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"]; + + // Defines the x/cron parameters to update. + // + // NOTE: All parameters must be supplied. + Params params = 2 [ + (gogoproto.nullable) = false, + (amino.dont_omitempty) = true + ]; +} + +// Defines the response structure for executing a MsgUpdateParams message. +// +// Since: 0.47 +message MsgUpdateParamsResponse {} diff --git a/proto/secret/cron/v1/schedule.proto b/proto/secret/cron/v1/schedule.proto new file mode 100644 index 000000000..deecc36ec --- /dev/null +++ b/proto/secret/cron/v1/schedule.proto @@ -0,0 +1,32 @@ +syntax = "proto3"; +package secret.cron.v1; + +import "gogoproto/gogo.proto"; + +option go_package = "github.com/scrtlabs/SecretNetwork/x/cron/types/v1"; + +// Defines the schedule for execution +message Schedule { + // Name of schedule + string name = 1; + // Period in blocks + uint64 period = 2; + // Msgs that will be executed every certain number of blocks, specified in the `period` field + repeated MsgExecuteContract msgs = 3 [(gogoproto.nullable) = false]; + // Last execution's block height + uint64 last_execute_height = 4; +} + +// Defines the contract and the message to pass +message MsgExecuteContract { + // The address of the smart contract + string contract = 1; + // JSON encoded message to be passed to the contract + string msg = 2; +} + +// Defines the number of current schedules +message ScheduleCount { + // The number of current schedules + int32 count = 1; +} diff --git a/x/compute/internal/keeper/keeper.go b/x/compute/internal/keeper/keeper.go index 5e2d5baac..5e611352f 100644 --- a/x/compute/internal/keeper/keeper.go +++ b/x/compute/internal/keeper/keeper.go @@ -47,12 +47,16 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" sdktx "github.com/cosmos/cosmos-sdk/types/tx" + "github.com/cosmos/cosmos-sdk/types/tx/signing" sdktxsigning "github.com/cosmos/cosmos-sdk/types/tx/signing" wasm "github.com/scrtlabs/SecretNetwork/go-cosmwasm" v010wasmTypes "github.com/scrtlabs/SecretNetwork/go-cosmwasm/types/v010" v1wasmTypes "github.com/scrtlabs/SecretNetwork/go-cosmwasm/types/v1" + cronkeeper "github.com/scrtlabs/SecretNetwork/x/cron/keeper" + crontypes "github.com/scrtlabs/SecretNetwork/x/cron/types" + "github.com/scrtlabs/SecretNetwork/x/compute/internal/types" ) @@ -78,6 +82,7 @@ type Keeper struct { bankKeeper bankkeeper.Keeper portKeeper portkeeper.Keeper capabilityKeeper capabilitykeeper.ScopedKeeper + cronKeeper cronkeeper.Keeper wasmer wasm.Wasmer queryPlugins QueryPlugins messenger Messenger @@ -106,6 +111,7 @@ func NewKeeper( storeService store.KVStoreService, accountKeeper authkeeper.AccountKeeper, bankKeeper bankkeeper.Keeper, + cronKeeper cronkeeper.Keeper, govKeeper govkeeper.Keeper, distKeeper distrkeeper.Keeper, mintKeeper mintkeeper.Keeper, @@ -137,6 +143,7 @@ func NewKeeper( wasmer: *wasmer, accountKeeper: accountKeeper, bankKeeper: bankKeeper, + cronKeeper: cronKeeper, portKeeper: portKeeper, capabilityKeeper: capabilityKeeper, messenger: NewMessageHandler( @@ -161,6 +168,10 @@ func NewKeeper( return keeper } +func (k *Keeper) SetCronKeeper(cronKeeper cronkeeper.Keeper) { + k.cronKeeper = cronKeeper +} + func (k Keeper) SetValidatorSetEvidence(ctx sdk.Context) error { store := k.storeService.OpenKVStore(ctx) validator_set_evidence, err := store.Get(types.ValidatorSetEvidencePrefix) @@ -414,7 +425,7 @@ func V010MsgToV1SubMsg(contractAddress string, msg v010wasmTypes.CosmosMsg) (v1w ReplyOn: v1wasmTypes.ReplyNever, } - if msg.Bank != nil { + if msg.Bank != nil { if msg.Bank.Send.FromAddress != contractAddress { return v1wasmTypes.SubMsg{}, fmt.Errorf("contract doesn't have permission to send funds from another account (using BankMsg)") } @@ -564,7 +575,7 @@ func (k Keeper) Instantiate(ctx sdk.Context, codeID uint64, creator, admin sdk.A consumeGas(ctx, gasUsed) if initError != nil { - switch res := response.(type) { + switch res := response.(type) { case v1wasmTypes.DataWithInternalReplyInfo: result, jsonError := json.Marshal(res) if jsonError != nil { @@ -727,7 +738,7 @@ func (k Keeper) Execute(ctx sdk.Context, contractAddress sdk.AccAddress, caller if execErr != nil { var result sdk.Result var jsonError error - switch res := response.(type) { + switch res := response.(type) { case v1wasmTypes.DataWithInternalReplyInfo: result.Data, jsonError = json.Marshal(res) if jsonError != nil { @@ -996,6 +1007,132 @@ func (k Keeper) GetContractInfo(ctx sdk.Context, contractAddress sdk.AccAddress) return &contract } +func (k Keeper) GetScheduledMsgs(ctx sdk.Context, execution_stage crontypes.ExecutionStage) ([]types.MsgExecuteContract, [][]byte, error) { + cronScheduledMsgs := k.cronKeeper.GetScheduledMsgs(ctx, execution_stage) + + // // Update the schedule's last execution height. + // schedule.LastExecuteHeight = uint64(ctx.BlockHeight()) //nolint:gosec + // k.storeSchedule(ctx, schedule) + + // Get the module private key once. + var txBytesList [][]byte + var executeMsgList []types.MsgExecuteContract + privKey := cronkeeper.GetModulePrivateKey() + pubKey := privKey.PubKey() + senderAddr := sdk.AccAddress(pubKey.Address()) + + // Retrieve the account info using the derived address. + senderAcc := k.accountKeeper.GetAccount(ctx, senderAddr) + if senderAcc == nil { + return nil, nil, fmt.Errorf("account not found for address %s", senderAddr.String()) + } + accountNumber := senderAcc.GetAccountNumber() + sequence := senderAcc.GetSequence() + chainID := ctx.ChainID() + + cacheCtx, writeFn := ctx.CacheContext() + for _, msg := range cronScheduledMsgs { + // Convert contract address from bech32. + contractAddr, err := sdk.AccAddressFromBech32(msg.Contract) + if err != nil { + ctx.Logger().Info("executeSchedule: failed to convert contract address from bech32.", "err", err) + return nil, nil, err + } + // contractAddr := msg.Contract + fmt.Printf("contractAddr: %s\n", contractAddr.String()) + + encryptedMsg, err := cronkeeper.Encrypt(ctx, &k.cronKeeper, []byte(msg.Msg)) + // encryptedMsg := msg.Msg + if err != nil { + ctx.Logger().Info("executeSchedule: failed to decode base64 msg", "err", err) + return nil, nil, err + } + executeMsg := types.MsgExecuteContract{ + Sender: senderAddr, + Contract: contractAddr, + Msg: encryptedMsg, + SentFunds: sdk.NewCoins(), + CallbackCodeHash: "", + } + + // Create a new transaction builder using the shared txConfig. + txBuilder := k.cronKeeper.GetTxConfig().NewTxBuilder() + if err := txBuilder.SetMsgs(&executeMsg); err != nil { + return nil, nil, err + } + // Set fee and gas (adjust as needed). + txBuilder.SetFeeAmount(sdk.NewCoins()) + txBuilder.SetGasLimit(0) + + // Prepare signer data using the correct account info. + signerData := authsigning.SignerData{ + Address: senderAddr.String(), + ChainID: chainID, + AccountNumber: accountNumber, + Sequence: sequence, + PubKey: pubKey, + } + + sigData := signing.SingleSignatureData{ + SignMode: signing.SignMode_SIGN_MODE_DIRECT, + Signature: nil, + } + + sig := signing.SignatureV2{ + PubKey: pubKey, + Data: &sigData, + Sequence: sequence, + } + + sigs := []signing.SignatureV2{sig} + if err := txBuilder.SetSignatures(sigs...); err != nil { + return nil, nil, err + } + + bytesToSign, err := authsigning.GetSignBytesAdapter(ctx, k.cronKeeper.GetTxConfig().SignModeHandler(), signing.SignMode_SIGN_MODE_DIRECT, signerData, txBuilder.GetTx()) + if err != nil { + return nil, nil, err + } + + // Sign those bytes + sigBytes, err := privKey.Sign(bytesToSign) + if err != nil { + return nil, nil, err + } + + // Construct the SignatureV2 struct + sigData = signing.SingleSignatureData{ + SignMode: signing.SignMode_SIGN_MODE_DIRECT, + Signature: sigBytes, + } + sig = signing.SignatureV2{ + PubKey: pubKey, + Data: &sigData, + Sequence: sequence, + } + + err = txBuilder.SetSignatures(sig) + if err != nil { + return nil, nil, fmt.Errorf("unable to set signatures on payload: %w", err) + } + + txBytes, err := k.cronKeeper.GetTxConfig().TxEncoder()(txBuilder.GetTx()) + if err != nil { + return nil, nil, err + } + + cacheCtx = cacheCtx.WithTxBytes(txBytes) + + txBytesList = append(txBytesList, txBytes) + executeMsgList = append(executeMsgList, executeMsg) + + } + + // Commit changes if all messages were executed successfully. + writeFn() + return executeMsgList, txBytesList, nil +} + func (k Keeper) containsContractInfo(ctx sdk.Context, contractAddress sdk.AccAddress) bool { store := k.storeService.OpenKVStore(ctx) has, err := store.Has(types.GetContractAddressKey(contractAddress)) @@ -1534,7 +1671,7 @@ func (k Keeper) Migrate(ctx sdk.Context, contractAddress sdk.AccAddress, caller if migrateErr != nil { var result []byte var jsonError error - switch res := response.(type) { + switch res := response.(type) { case v1wasmTypes.DataWithInternalReplyInfo: result, jsonError = json.Marshal(res) if jsonError != nil { @@ -1631,7 +1768,7 @@ func (k Keeper) appendToContractHistory(ctx sdk.Context, contractAddr sdk.AccAdd for _, e := range newEntries { pos++ key := types.GetContractCodeHistoryElementKey(contractAddr, pos) - err := store.Set(key, k.cdc.MustMarshal(&e)) + err := store.Set(key, k.cdc.MustMarshal(&e)) if err != nil { ctx.Logger().Error("appendToContractHistory:", err.Error()) } diff --git a/x/compute/internal/keeper/test_common.go b/x/compute/internal/keeper/test_common.go index 39b947010..a7e7574ed 100644 --- a/x/compute/internal/keeper/test_common.go +++ b/x/compute/internal/keeper/test_common.go @@ -116,6 +116,9 @@ import ( "cosmossdk.io/x/upgrade" + cronkeeper "github.com/scrtlabs/SecretNetwork/x/cron/keeper" + crontypes "github.com/scrtlabs/SecretNetwork/x/cron/types" + wasmtypes "github.com/scrtlabs/SecretNetwork/x/compute/internal/types" "github.com/scrtlabs/SecretNetwork/x/registration" ) @@ -497,6 +500,14 @@ func CreateTestInput(t *testing.T, isCheckTx bool, supportedFeatures string, enc ) govKeeper.SetLegacyRouter(govRouter) + cronKeeper := cronkeeper.NewKeeper( + encodingConfig.Codec, + keys[crontypes.StoreKey], + memKeys[crontypes.StoreKey], + authKeeper, + authtypes.NewModuleAddress(crontypes.ModuleName).String(), + ) + // bank := bankKeeper. // bk := bank.Keeper(bankKeeper) @@ -577,6 +588,7 @@ func CreateTestInput(t *testing.T, isCheckTx bool, supportedFeatures string, enc runtime.NewKVStoreService(keys[wasmtypes.StoreKey]), authKeeper, bankKeeper, + *cronKeeper, *govKeeper, distKeeper, mintKeeper, @@ -1105,8 +1117,9 @@ func updateLightClientHelper(t *testing.T, ctx sdk.Context) { require.NoError(t, err) randomAndProofBz := append(random, proof...) //nolint:all + cronmsgs := []byte{} - _, _, err = api.SubmitBlockSignatures(headerBz, commitBz, dataBz, randomAndProofBz) + _, _, err = api.SubmitBlockSignatures(headerBz, commitBz, dataBz, randomAndProofBz, cronmsgs) require.NoError(t, err) } diff --git a/x/compute/internal/types/expected_keepers.go b/x/compute/internal/types/expected_keepers.go index c93c7f4ba..7e3c6420b 100644 --- a/x/compute/internal/types/expected_keepers.go +++ b/x/compute/internal/types/expected_keepers.go @@ -2,6 +2,7 @@ package types import ( sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/scrtlabs/SecretNetwork/x/cron/types" capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types" clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types" @@ -23,3 +24,7 @@ type ChannelKeeper interface { IterateChannels(ctx sdk.Context, cb func(channeltypes.IdentifiedChannel) bool) SetChannel(ctx sdk.Context, portID, channelID string, channel channeltypes.Channel) } + +type CronKeeper interface { + GetScheduledMsgs(ctx sdk.Context) []types.MsgExecuteContract +} diff --git a/x/compute/module.go b/x/compute/module.go index 55f04444e..dbd5d6fc5 100644 --- a/x/compute/module.go +++ b/x/compute/module.go @@ -2,7 +2,10 @@ package compute import ( "context" + "crypto/sha256" + "encoding/hex" "encoding/json" + "fmt" "github.com/grpc-ecosystem/grpc-gateway/runtime" "github.com/spf13/cobra" @@ -15,9 +18,12 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" "github.com/scrtlabs/SecretNetwork/go-cosmwasm/api" + wasmtypes "github.com/scrtlabs/SecretNetwork/go-cosmwasm/types" "github.com/scrtlabs/SecretNetwork/x/compute/client/cli" "github.com/scrtlabs/SecretNetwork/x/compute/internal/keeper" "github.com/scrtlabs/SecretNetwork/x/compute/internal/types" + crontypes "github.com/scrtlabs/SecretNetwork/x/cron/types" + tmenclave "github.com/scrtlabs/tm-secret-enclave" ) var ( @@ -146,12 +152,35 @@ func (am AppModule) BeginBlock(c context.Context) error { // Note: as of tendermint v0.38.0 block begin request info is no longer available ctx := c.(sdk.Context) block_header := ctx.BlockHeader() + + execCronMsgs, bytesCronMsgs, err := am.keeper.GetScheduledMsgs(ctx, crontypes.ExecutionStage_EXECUTION_STAGE_BEGIN_BLOCKER) + if err != nil { + ctx.Logger().Error("Failed to get scheduled cron msgs") + return err + } + hash := sha256.Sum256([]byte("random")) + block_header.ImplicitHash = hash[:] + block_header.AppHash = hash[:] + + cron_msgs := tm_type.Data{Txs: bytesCronMsgs} + cron_data, err := cron_msgs.Marshal() + if err != nil { + ctx.Logger().Error("Failed to marshal cron_msgs") + return err + } + // hash := sha256.Sum256(cron_data) + + fmt.Printf("beginBlock: block_header: %+v\n", hex.EncodeToString(block_header.ImplicitHash)) header, err := block_header.Marshal() if err != nil { ctx.Logger().Error("Failed to marshal block header") return err } + // fmt.Printf("---------------bytesCronMsgs--------------\n%+v\n", bytesCronMsgs) + // fmt.Printf("---------------execCronMsgs--------------\n%+v\n", execCronMsgs) + // fmt.Printf("ImplicitHash: %+v\n", hex.EncodeToString(hash[:])) + commit := ctx.Commit() b_commit, err := commit.Marshal() if err != nil { @@ -168,12 +197,24 @@ func (am AppModule) BeginBlock(c context.Context) error { } if block_header.EncryptedRandom != nil { randomAndProof := append(block_header.EncryptedRandom.Random, block_header.EncryptedRandom.Proof...) - random, validator_set_evidence, err := api.SubmitBlockSignatures(header, b_commit, data, randomAndProof) + random, validator_set_evidence, err := api.SubmitBlockSignatures(header, b_commit, data, randomAndProof, cron_data) if err != nil { ctx.Logger().Error("Failed to submit block signatures") return err } + for idx, msg := range execCronMsgs { + fmt.Printf("idx, msg: %+v %+v\n", idx, msg) + ctx = ctx.WithTxBytes(bytesCronMsgs[idx]) + _, err := am.keeper.Execute(ctx, msg.Contract, msg.Sender, msg.Msg, msg.SentFunds, msg.CallbackSig, wasmtypes.HandleTypeExecute) + if err != nil { + ctx.Logger().Error("Failed to execute cron message", "error", err) + // return err + } + } + + fmt.Printf("setRandomSeed\n") + am.keeper.SetRandomSeed(ctx, random, validator_set_evidence) } else { ctx.Logger().Debug("Non-encrypted block", "Block_hash", block_header.LastBlockId.Hash, "Height", ctx.BlockHeight(), "Txs", len(x2_data)) @@ -181,6 +222,36 @@ func (am AppModule) BeginBlock(c context.Context) error { return nil } +// EndBlock returns the end blocker for the compute module. +func (am AppModule) EndBlock(c context.Context) error { + ctx := c.(sdk.Context) + block_header := ctx.BlockHeader() + fmt.Printf("endBlock: block_header: %+v\n", block_header) + + _, bytesCronMsgs, err := am.keeper.GetScheduledMsgs(ctx, crontypes.ExecutionStage_EXECUTION_STAGE_END_BLOCKER) + if err != nil { + ctx.Logger().Error("Failed to get scheduled cron msgs") + return err + } + + cron_msgs := tm_type.Data{Txs: bytesCronMsgs} + cron_data, err := cron_msgs.Marshal() + if err != nil { + ctx.Logger().Error("Failed to marshal cron_msgs") + return err + } + hash := sha256.Sum256(cron_data) + + fmt.Printf("Hash of the executed msgs in the next round: %+v\n", hex.EncodeToString(hash[:])) + err = tmenclave.SetImplicitHash(hash[:]) + if err != nil { + ctx.Logger().Error("Failed to set implicit hash %+v", err) + return err + } + fmt.Printf("---------------EndBlock--------------\n") + return nil +} + // IsAppModule implements the appmodule.AppModule interface. func (AppModule) IsAppModule() {} diff --git a/x/cron/client/cli/query.go b/x/cron/client/cli/query.go new file mode 100644 index 000000000..a334e6c18 --- /dev/null +++ b/x/cron/client/cli/query.go @@ -0,0 +1,29 @@ +package cli + +import ( + "fmt" + + "github.com/spf13/cobra" + + "github.com/cosmos/cosmos-sdk/client" + + "github.com/scrtlabs/SecretNetwork/x/cron/types" +) + +// GetQueryCmd returns the cli query commands for this module +func GetQueryCmd(_ string) *cobra.Command { + // Group cron queries under a subcommand + cmd := &cobra.Command{ + Use: types.ModuleName, + Short: fmt.Sprintf("Querying commands for the %s module", types.ModuleName), + DisableFlagParsing: true, + SuggestionsMinimumDistance: 2, + RunE: client.ValidateCmd, + } + + cmd.AddCommand(CmdQueryParams()) + cmd.AddCommand(CmdListSchedule()) + cmd.AddCommand(CmdShowSchedule()) + + return cmd +} diff --git a/x/cron/client/cli/query_params.go b/x/cron/client/cli/query_params.go new file mode 100644 index 000000000..5965cd126 --- /dev/null +++ b/x/cron/client/cli/query_params.go @@ -0,0 +1,34 @@ +package cli + +import ( + "context" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/scrtlabs/SecretNetwork/x/cron/types" + "github.com/spf13/cobra" +) + +func CmdQueryParams() *cobra.Command { + cmd := &cobra.Command{ + Use: "params", + Short: "shows the parameters of the module", + Args: cobra.NoArgs, + RunE: func(cmd *cobra.Command, _ []string) error { + clientCtx := client.GetClientContextFromCmd(cmd) + + queryClient := types.NewQueryClient(clientCtx) + + res, err := queryClient.Params(context.Background(), &types.QueryParamsRequest{}) + if err != nil { + return err + } + + return clientCtx.PrintProto(res) + }, + } + + flags.AddQueryFlagsToCmd(cmd) + + return cmd +} diff --git a/x/cron/client/cli/query_schedule.go b/x/cron/client/cli/query_schedule.go new file mode 100644 index 000000000..f29cc63b7 --- /dev/null +++ b/x/cron/client/cli/query_schedule.go @@ -0,0 +1,74 @@ +package cli + +import ( + "context" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/spf13/cobra" + + "github.com/scrtlabs/SecretNetwork/x/cron/types" +) + +func CmdListSchedule() *cobra.Command { + cmd := &cobra.Command{ + Use: "list-schedule", + Short: "list all schedule", + RunE: func(cmd *cobra.Command, _ []string) error { + clientCtx := client.GetClientContextFromCmd(cmd) + + pageReq, err := client.ReadPageRequest(cmd.Flags()) + if err != nil { + return err + } + + queryClient := types.NewQueryClient(clientCtx) + + params := &types.QuerySchedulesRequest{ + Pagination: pageReq, + } + + res, err := queryClient.Schedules(context.Background(), params) + if err != nil { + return err + } + + return clientCtx.PrintProto(res) + }, + } + + flags.AddPaginationFlagsToCmd(cmd, cmd.Use) + flags.AddQueryFlagsToCmd(cmd) + + return cmd +} + +func CmdShowSchedule() *cobra.Command { + cmd := &cobra.Command{ + Use: "show-schedule [name]", + Short: "shows a schedule", + Args: cobra.ExactArgs(1), + RunE: func(cmd *cobra.Command, args []string) (err error) { + clientCtx := client.GetClientContextFromCmd(cmd) + + queryClient := types.NewQueryClient(clientCtx) + + argName := args[0] + + params := &types.QueryGetScheduleRequest{ + Name: argName, + } + + res, err := queryClient.Schedule(context.Background(), params) + if err != nil { + return err + } + + return clientCtx.PrintProto(res) + }, + } + + flags.AddQueryFlagsToCmd(cmd) + + return cmd +} diff --git a/x/cron/client/cli/tx.go b/x/cron/client/cli/tx.go new file mode 100644 index 000000000..429f7f5ec --- /dev/null +++ b/x/cron/client/cli/tx.go @@ -0,0 +1,24 @@ +package cli + +import ( + "fmt" + + "github.com/spf13/cobra" + + "github.com/cosmos/cosmos-sdk/client" + + "github.com/scrtlabs/SecretNetwork/x/cron/types" +) + +// GetTxCmd returns the transaction commands for this module +func GetTxCmd() *cobra.Command { + cmd := &cobra.Command{ + Use: types.ModuleName, + Short: fmt.Sprintf("%s transactions subcommands", types.ModuleName), + DisableFlagParsing: true, + SuggestionsMinimumDistance: 2, + RunE: client.ValidateCmd, + } + + return cmd +} diff --git a/x/cron/genesis.go b/x/cron/genesis.go new file mode 100644 index 000000000..450aba558 --- /dev/null +++ b/x/cron/genesis.go @@ -0,0 +1,33 @@ +package cron + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/scrtlabs/SecretNetwork/x/cron/keeper" + "github.com/scrtlabs/SecretNetwork/x/cron/types" +) + +// InitGenesis initializes the module's state from a provided genesis state. +func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState types.GenesisState) { + // Set all the schedules + for _, elem := range genState.ScheduleList { + err := k.AddSchedule(ctx, elem.Name, elem.Period, elem.Msgs, elem.ExecutionStage) + if err != nil { + panic(err) + } + } + // this line is used by starport scaffolding # genesis/module/init + err := k.SetParams(ctx, genState.Params) + if err != nil { + panic(err) + } +} + +// ExportGenesis returns the module's exported genesis +func ExportGenesis(ctx sdk.Context, k keeper.Keeper) *types.GenesisState { + genesis := types.DefaultGenesis() + genesis.Params = k.GetParams(ctx) + genesis.ScheduleList = k.GetAllSchedules(ctx) + + return genesis +} diff --git a/x/cron/keeper/grpc_query.go b/x/cron/keeper/grpc_query.go new file mode 100644 index 000000000..a8b699c8c --- /dev/null +++ b/x/cron/keeper/grpc_query.go @@ -0,0 +1,7 @@ +package keeper + +import ( + "github.com/scrtlabs/SecretNetwork/x/cron/types" +) + +var _ types.QueryServer = Keeper{} diff --git a/x/cron/keeper/grpc_query_params.go b/x/cron/keeper/grpc_query_params.go new file mode 100644 index 000000000..77f3b0f68 --- /dev/null +++ b/x/cron/keeper/grpc_query_params.go @@ -0,0 +1,20 @@ +package keeper + +import ( + "context" + + sdk "github.com/cosmos/cosmos-sdk/types" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" + + "github.com/scrtlabs/SecretNetwork/x/cron/types" +) + +func (k Keeper) Params(c context.Context, req *types.QueryParamsRequest) (*types.QueryParamsResponse, error) { + if req == nil { + return nil, status.Error(codes.InvalidArgument, "invalid request") + } + ctx := sdk.UnwrapSDKContext(c) + + return &types.QueryParamsResponse{Params: k.GetParams(ctx)}, nil +} diff --git a/x/cron/keeper/grpc_query_schedule.go b/x/cron/keeper/grpc_query_schedule.go new file mode 100644 index 000000000..c4bd0e124 --- /dev/null +++ b/x/cron/keeper/grpc_query_schedule.go @@ -0,0 +1,54 @@ +package keeper + +import ( + "context" + + "cosmossdk.io/store/prefix" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/query" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" + + "github.com/scrtlabs/SecretNetwork/x/cron/types" +) + +func (k Keeper) Schedules(c context.Context, req *types.QuerySchedulesRequest) (*types.QuerySchedulesResponse, error) { + if req == nil { + return nil, status.Error(codes.InvalidArgument, "invalid request") + } + + var schedules []types.Schedule + ctx := sdk.UnwrapSDKContext(c) + + scheduleStore := prefix.NewStore(ctx.KVStore(k.storeKey), types.ScheduleKey) + + pageRes, err := query.Paginate(scheduleStore, req.Pagination, func(_, value []byte) error { + var schedule types.Schedule + k.cdc.MustUnmarshal(value, &schedule) + + schedules = append(schedules, schedule) + return nil + }) + if err != nil { + return nil, status.Error(codes.Internal, err.Error()) + } + + return &types.QuerySchedulesResponse{Schedules: schedules, Pagination: pageRes}, nil +} + +func (k Keeper) Schedule(c context.Context, req *types.QueryGetScheduleRequest) (*types.QueryGetScheduleResponse, error) { + if req == nil { + return nil, status.Error(codes.InvalidArgument, "invalid request") + } + ctx := sdk.UnwrapSDKContext(c) + + val, found := k.GetSchedule( + ctx, + req.Name, + ) + if !found { + return nil, status.Error(codes.NotFound, "schedule not found") + } + + return &types.QueryGetScheduleResponse{Schedule: *val}, nil +} diff --git a/x/cron/keeper/keeper.go b/x/cron/keeper/keeper.go new file mode 100644 index 000000000..bdb25202c --- /dev/null +++ b/x/cron/keeper/keeper.go @@ -0,0 +1,378 @@ +package keeper + +import ( + "crypto/sha256" + "encoding/base64" + "fmt" + "io" + "strconv" + + "cosmossdk.io/log" + "github.com/hashicorp/go-metrics" + "github.com/miscreant/miscreant.go" + "golang.org/x/crypto/curve25519" + "golang.org/x/crypto/hkdf" + + "github.com/cosmos/cosmos-sdk/telemetry" + + "cosmossdk.io/store/prefix" + + storetypes "cosmossdk.io/store/types" + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/codec" + secp256k1 "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" + cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/scrtlabs/SecretNetwork/x/cron/types" + regtypes "github.com/scrtlabs/SecretNetwork/x/registration" +) + +var ( + LabelExecuteReadySchedules = "execute_ready_schedules" + LabelScheduleCount = "schedule_count" + LabelScheduleExecutionsCount = "schedule_executions_count" + + MetricLabelSuccess = "success" + MetricLabelScheduleName = "schedule_name" +) + +type ( + Keeper struct { + cdc codec.BinaryCodec + storeKey storetypes.StoreKey + memKey storetypes.StoreKey + accountKeeper types.AccountKeeper + regKeeper types.RegKeeper + // WasmMsgServer types.WasmMsgServer + authority string + txConfig client.TxConfig + } +) + +func (k *Keeper) GetTxConfig() client.TxConfig { + return k.txConfig +} + +// GetScheduledMsgs implements types.CronKeeper. +func (k *Keeper) GetScheduledMsgs(ctx sdk.Context, execution_stage types.ExecutionStage) []types.MsgExecuteContract { + // func (k *Keeper) GetScheduledMsgs(ctx sdk.Context) [][]byte { + schedules := k.getSchedulesReadyForExecution(ctx, execution_stage) + fmt.Printf("schedules: %+v\n", schedules) + var msgExecuteContractList []types.MsgExecuteContract + for _, schedule := range schedules { + fmt.Printf("schedule:%+v\n", schedule) + msgs, err := k.getCronsMsgs(ctx, schedule, execution_stage) + if err != nil { + ctx.Logger().Error("Failed to get crons msgs", "error", err) + continue + } + fmt.Printf("------------msgs by schedule ----------------\n") + fmt.Printf("%+v\n", msgs) + + msgExecuteContractList = append(msgExecuteContractList, msgs...) + if execution_stage == types.ExecutionStage_EXECUTION_STAGE_BEGIN_BLOCKER { + recordExecutedSchedule(nil, schedule) + } + } + return msgExecuteContractList +} + +// executeSchedule executes all msgs in a given schedule and changes LastExecuteHeight +// if at least one msg execution fails, rollback all messages +func (k *Keeper) getCronsMsgs(ctx sdk.Context, schedule types.Schedule, execution_stage types.ExecutionStage) ([]types.MsgExecuteContract, error) { + // Even if contract execution returned an error, we still increase the height + // and execute it after this interval + if execution_stage == types.ExecutionStage_EXECUTION_STAGE_BEGIN_BLOCKER { + schedule.LastExecuteHeight = uint64(ctx.BlockHeight()) //nolint:gosec + k.storeSchedule(ctx, schedule) + } + + var cronMsgs []types.MsgExecuteContract + + for _, msg := range schedule.Msgs { + contractAddr, err := sdk.AccAddressFromBech32(msg.Contract) + if err != nil { + ctx.Logger().Info("getCronsMsgs: failed to extract contract address", "err", err) + return nil, err + } + executeMsg := types.MsgExecuteContract{ + Contract: contractAddr.String(), + Msg: msg.Msg, + } + cronMsgs = append(cronMsgs, executeMsg) + } + return cronMsgs, nil +} + +func NewKeeper( + cdc codec.BinaryCodec, + storeKey, + memKey storetypes.StoreKey, + accountKeeper types.AccountKeeper, + authority string, +) *Keeper { + return &Keeper{ + cdc: cdc, + storeKey: storeKey, + memKey: memKey, + accountKeeper: accountKeeper, + regKeeper: nil, + authority: authority, + txConfig: nil, + } +} + +// SetTxConfig injects the transaction configuration into the keeper. +func (k *Keeper) SetTxConfig(txConfig client.TxConfig) { + k.txConfig = txConfig +} + +func (k *Keeper) SetRegKeeper(regKeeper types.RegKeeper) { + k.regKeeper = regKeeper +} + +func (k Keeper) GetAuthority() string { + return k.authority +} + +func (k *Keeper) Logger(ctx sdk.Context) log.Logger { + return ctx.Logger().With("module", fmt.Sprintf("x/%s", types.ModuleName)) +} + +// AddSchedule adds a new schedule to be executed every certain number of blocks, specified in the `period`. +// First schedule execution is supposed to be on `now + period` block. +func (k *Keeper) AddSchedule( + ctx sdk.Context, + name string, + period uint64, + msgs []types.MsgExecuteContract, + executionStage types.ExecutionStage, +) error { + if k.scheduleExists(ctx, name) { + return fmt.Errorf("schedule already exists with name=%v", name) + } + + schedule := types.Schedule{ + Name: name, + Period: period, + Msgs: msgs, + // let's execute newly added schedule on `now + period` block + LastExecuteHeight: uint64(ctx.BlockHeight()), //nolint:gosec + ExecutionStage: executionStage, + } + + k.storeSchedule(ctx, schedule) + k.changeTotalCount(ctx, 1) + + return nil +} + +// RemoveSchedule removes schedule with a given `name` +func (k *Keeper) RemoveSchedule(ctx sdk.Context, name string) { + if !k.scheduleExists(ctx, name) { + return + } + + k.changeTotalCount(ctx, -1) + k.removeSchedule(ctx, name) +} + +// GetSchedule returns schedule with a given `name` +func (k *Keeper) GetSchedule(ctx sdk.Context, name string) (*types.Schedule, bool) { + store := prefix.NewStore(ctx.KVStore(k.storeKey), types.ScheduleKey) + bzSchedule := store.Get(types.GetScheduleKey(name)) + if bzSchedule == nil { + return nil, false + } + + var schedule types.Schedule + k.cdc.MustUnmarshal(bzSchedule, &schedule) + return &schedule, true +} + +// GetAllSchedules returns all schedules +func (k *Keeper) GetAllSchedules(ctx sdk.Context) []types.Schedule { + store := prefix.NewStore(ctx.KVStore(k.storeKey), types.ScheduleKey) + + res := make([]types.Schedule, 0) + + iterator := storetypes.KVStorePrefixIterator(store, []byte{}) + defer iterator.Close() + + for ; iterator.Valid(); iterator.Next() { + var schedule types.Schedule + k.cdc.MustUnmarshal(iterator.Value(), &schedule) + res = append(res, schedule) + } + + return res +} + +func (k *Keeper) GetScheduleCount(ctx sdk.Context) int32 { + return k.getScheduleCount(ctx) +} + +func (k *Keeper) getSchedulesReadyForExecution(ctx sdk.Context, executionStage types.ExecutionStage) []types.Schedule { + params := k.GetParams(ctx) + store := prefix.NewStore(ctx.KVStore(k.storeKey), types.ScheduleKey) + count := uint64(0) + + res := make([]types.Schedule, 0) + + iterator := storetypes.KVStorePrefixIterator(store, []byte{}) + defer iterator.Close() + + for ; iterator.Valid(); iterator.Next() { + var schedule types.Schedule + k.cdc.MustUnmarshal(iterator.Value(), &schedule) + + if k.intervalPassed(ctx, schedule, executionStage) { + res = append(res, schedule) + count++ + + if count >= params.Limit { + k.Logger(ctx).Info("limit of schedule executions per block reached") + return res + } + } + } + + return res +} + +var hkdfSalt = []byte{ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x02, 0x4b, 0xea, 0xd8, 0xdf, 0x69, 0x99, + 0x08, 0x52, 0xc2, 0x02, 0xdb, 0x0e, 0x00, 0x97, + 0xc1, 0xa1, 0x2e, 0xa6, 0x37, 0xd7, 0xe9, 0x6d, +} + +func getTxEncryptionKey(ctx sdk.Context, k *Keeper, txSenderPrivKey []byte, nonce []byte) ([]byte, error) { + consensusIoPubKey := k.regKeeper.GetMasterKey(ctx, regtypes.MasterIoKeyId) + + txEncryptionIkm, err := curve25519.X25519(txSenderPrivKey, consensusIoPubKey.Bytes) + if err != nil { + fmt.Println("Failed to get tx encryption key") + return nil, err + } + + kdfFunc := hkdf.New(sha256.New, append(txEncryptionIkm, nonce...), hkdfSalt, []byte{}) + + txEncryptionKey := make([]byte, 32) + if _, err := io.ReadFull(kdfFunc, txEncryptionKey); err != nil { + return nil, err + } + + return txEncryptionKey, nil +} + +// Encrypt encrypts deterministically by deriving the ephemeral keys and nonce from the plaintext. +func Encrypt(ctx sdk.Context, k *Keeper, plaintext []byte) ([]byte, error) { + txSenderPrivKey := sha256.Sum256(plaintext) + // var txSenderPrivKey [32]byte + // rand.Read(txSenderPrivKey[:]) //nolint:errcheck + + var txSenderPubKey [32]byte + curve25519.ScalarBaseMult(&txSenderPubKey, &txSenderPrivKey) + // if err != nil { + // log.Println(err) + // return nil, err + // } + + // Derive a deterministic nonce by hashing the plaintext with an appended constant. + nonceData := append(plaintext, []byte("nonce")...) // "nonce" is a constant string to differentiate from key derivation + nonceHash := sha256.Sum256(nonceData) + nonce := nonceHash[:] // convert fixed array to a slice + + txEncryptionKey, err := getTxEncryptionKey(ctx, k, txSenderPrivKey[:], nonce) + if err != nil { + // log.Println(err) + return nil, err + } + + return encryptData(txEncryptionKey, txSenderPubKey[:], plaintext, nonce) +} + +func encryptData(aesEncryptionKey []byte, txSenderPubKey []byte, plaintext []byte, nonce []byte) ([]byte, error) { + cipher, err := miscreant.NewAESCMACSIV(aesEncryptionKey) + if err != nil { + // log.Println(err) + return nil, err + } + + ciphertext, err := cipher.Seal(nil, plaintext, []byte{}) + if err != nil { + // log.Println(err) + return nil, err + } + + // ciphertext = nonce(32) || wallet_pubkey(32) || ciphertext + ciphertext = append(nonce, append(txSenderPubKey, ciphertext...)...) + + return ciphertext, nil +} + +func GetModulePrivateKey() cryptotypes.PrivKey { + privKeyBase64 := "8Ke2frmnGdVPipv7+xh9jClrl5EaBb9cowSUgj5GvrY=" + privKeyBytes, err := base64.StdEncoding.DecodeString(privKeyBase64) + if err != nil { + fmt.Printf("failed to decode private key: %v", err) + } + return &secp256k1.PrivKey{Key: privKeyBytes} +} + +func (k *Keeper) storeSchedule(ctx sdk.Context, schedule types.Schedule) { + store := prefix.NewStore(ctx.KVStore(k.storeKey), types.ScheduleKey) + + bzSchedule := k.cdc.MustMarshal(&schedule) + store.Set(types.GetScheduleKey(schedule.Name), bzSchedule) +} + +func (k *Keeper) removeSchedule(ctx sdk.Context, name string) { + store := prefix.NewStore(ctx.KVStore(k.storeKey), types.ScheduleKey) + + store.Delete(types.GetScheduleKey(name)) +} + +func (k *Keeper) scheduleExists(ctx sdk.Context, name string) bool { + store := prefix.NewStore(ctx.KVStore(k.storeKey), types.ScheduleKey) + return store.Has(types.GetScheduleKey(name)) +} + +func (k *Keeper) intervalPassed(ctx sdk.Context, schedule types.Schedule, executionStage types.ExecutionStage) bool { + delta := 0 + if executionStage == types.ExecutionStage_EXECUTION_STAGE_END_BLOCKER { + delta = 1 + } + return uint64(ctx.BlockHeight())+uint64(delta) > (schedule.LastExecuteHeight + schedule.Period) //nolint:gosec +} + +func (k *Keeper) changeTotalCount(ctx sdk.Context, incrementAmount int32) { + store := ctx.KVStore(k.storeKey) + count := k.getScheduleCount(ctx) + newCount := types.ScheduleCount{Count: count + incrementAmount} + bzCount := k.cdc.MustMarshal(&newCount) + store.Set(types.ScheduleCountKey, bzCount) + + telemetry.ModuleSetGauge(types.ModuleName, float32(newCount.Count), LabelScheduleCount) +} + +func (k *Keeper) getScheduleCount(ctx sdk.Context) int32 { + store := ctx.KVStore(k.storeKey) + bzCount := store.Get(types.ScheduleCountKey) + if bzCount == nil { + return 0 + } + + var count types.ScheduleCount + k.cdc.MustUnmarshal(bzCount, &count) + return count.Count +} + +func recordExecutedSchedule(err error, schedule types.Schedule) { + telemetry.IncrCounterWithLabels([]string{LabelScheduleExecutionsCount}, 1, []metrics.Label{ + telemetry.NewLabel(telemetry.MetricLabelNameModule, types.ModuleName), + telemetry.NewLabel(MetricLabelSuccess, strconv.FormatBool(err == nil)), + telemetry.NewLabel(MetricLabelScheduleName, schedule.Name), + }) +} diff --git a/x/cron/keeper/migrations.go b/x/cron/keeper/migrations.go new file mode 100644 index 000000000..64aaba98f --- /dev/null +++ b/x/cron/keeper/migrations.go @@ -0,0 +1,22 @@ +package keeper + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + + v2 "github.com/scrtlabs/SecretNetwork/x/cron/migrations/v2" +) + +// Migrator is a struct for handling in-place store migrations. +type Migrator struct { + keeper Keeper +} + +// NewMigrator returns a new Migrator. +func NewMigrator(keeper Keeper) Migrator { + return Migrator{keeper: keeper} +} + +// Migrate1to2 migrates from version 1 to 2. +func (m Migrator) Migrate1to2(ctx sdk.Context) error { + return v2.MigrateStore(ctx, m.keeper.cdc, m.keeper.storeKey) +} diff --git a/x/cron/keeper/msg_server.go b/x/cron/keeper/msg_server.go new file mode 100644 index 000000000..d9dfaf862 --- /dev/null +++ b/x/cron/keeper/msg_server.go @@ -0,0 +1,77 @@ +package keeper + +import ( + "context" + + "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/scrtlabs/SecretNetwork/x/cron/types" +) + +type msgServer struct { + keeper Keeper +} + +// NewMsgServerImpl returns an implementation of the MsgServer interface +// for the provided Keeper. +func NewMsgServerImpl(keeper Keeper) types.MsgServer { + return &msgServer{keeper: keeper} +} + +var _ types.MsgServer = msgServer{} + +// AddSchedule adds new schedule +func (k msgServer) AddSchedule(goCtx context.Context, req *types.MsgAddSchedule) (*types.MsgAddScheduleResponse, error) { + if err := req.Validate(); err != nil { + return nil, errors.Wrap(err, "failed to validate MsgAddSchedule") + } + + // authority := k.keeper.GetAuthority() + // if authority != req.Authority { + // return nil, errors.Wrapf(sdkerrors.ErrInvalidRequest, "invalid authority; expected %s, got %s", authority, req.Authority) + // } + + ctx := sdk.UnwrapSDKContext(goCtx) + if err := k.keeper.AddSchedule(ctx, req.Name, req.Period, req.Msgs, req.ExecutionStage); err != nil { + return nil, errors.Wrap(err, "failed to add schedule") + } + + return &types.MsgAddScheduleResponse{}, nil +} + +// RemoveSchedule removes schedule +func (k msgServer) RemoveSchedule(goCtx context.Context, req *types.MsgRemoveSchedule) (*types.MsgRemoveScheduleResponse, error) { + if err := req.Validate(); err != nil { + return nil, errors.Wrap(err, "failed to validate MsgRemoveSchedule") + } + + // authority := k.keeper.GetAuthority() + // if authority != req.Authority { + // return nil, errors.Wrapf(sdkerrors.ErrInvalidRequest, "invalid authority; expected %s, got %s", authority, req.Authority) + // } + + ctx := sdk.UnwrapSDKContext(goCtx) + k.keeper.RemoveSchedule(ctx, req.Name) + + return &types.MsgRemoveScheduleResponse{}, nil +} + +// UpdateParams updates the module parameters +func (k msgServer) UpdateParams(goCtx context.Context, req *types.MsgUpdateParams) (*types.MsgUpdateParamsResponse, error) { + if err := req.Validate(); err != nil { + return nil, errors.Wrap(err, "failed to validate MsgUpdateParams") + } + + // authority := k.keeper.GetAuthority() + // if authority != req.Authority { + // return nil, errors.Wrapf(sdkerrors.ErrInvalidRequest, "invalid authority; expected %s, got %s", authority, req.Authority) + // } + + ctx := sdk.UnwrapSDKContext(goCtx) + if err := k.keeper.SetParams(ctx, req.Params); err != nil { + return nil, err + } + + return &types.MsgUpdateParamsResponse{}, nil +} diff --git a/x/cron/keeper/params.go b/x/cron/keeper/params.go new file mode 100644 index 000000000..15891508f --- /dev/null +++ b/x/cron/keeper/params.go @@ -0,0 +1,31 @@ +package keeper + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/scrtlabs/SecretNetwork/x/cron/types" +) + +// GetParams get all parameters as types.Params +func (k Keeper) GetParams(ctx sdk.Context) (params types.Params) { + store := ctx.KVStore(k.storeKey) + bz := store.Get(types.ParamsKey) + if bz == nil { + return params + } + + k.cdc.MustUnmarshal(bz, ¶ms) + return params +} + +// SetParams set the params +func (k Keeper) SetParams(ctx sdk.Context, params types.Params) error { + store := ctx.KVStore(k.storeKey) + bz, err := k.cdc.Marshal(¶ms) + if err != nil { + return err + } + + store.Set(types.ParamsKey, bz) + return nil +} diff --git a/x/cron/migrations/v2/store.go b/x/cron/migrations/v2/store.go new file mode 100644 index 000000000..31ad49101 --- /dev/null +++ b/x/cron/migrations/v2/store.go @@ -0,0 +1,56 @@ +package v2 + +import ( + "cosmossdk.io/errors" + "cosmossdk.io/store/prefix" + storetypes "cosmossdk.io/store/types" + "github.com/cosmos/cosmos-sdk/codec" + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/scrtlabs/SecretNetwork/x/cron/types" +) + +// MigrateStore performs in-place store migrations. +// The migration adds execution stage for schedules. +func MigrateStore(ctx sdk.Context, cdc codec.BinaryCodec, storeKey storetypes.StoreKey) error { + return migrateSchedules(ctx, cdc, storeKey) +} + +type migrationUpdate struct { + key []byte + val []byte +} + +func migrateSchedules(ctx sdk.Context, cdc codec.BinaryCodec, storeKey storetypes.StoreKey) error { + ctx.Logger().Info("Migrating cron Schedules...") + + store := prefix.NewStore(ctx.KVStore(storeKey), types.ScheduleKey) + iterator := storetypes.KVStorePrefixIterator(store, []byte{}) + schedulesToUpdate := make([]migrationUpdate, 0) + + for ; iterator.Valid(); iterator.Next() { + var schedule types.Schedule + cdc.MustUnmarshal(iterator.Value(), &schedule) + // Set execution in EndBlocker + schedule.ExecutionStage = types.ExecutionStage_EXECUTION_STAGE_END_BLOCKER + + schedulesToUpdate = append(schedulesToUpdate, migrationUpdate{ + key: iterator.Key(), + val: cdc.MustMarshal(&schedule), + }) + } + + err := iterator.Close() + if err != nil { + return errors.Wrap(err, "iterator failed to close during migration") + } + + // Store the updated Schedules + for _, v := range schedulesToUpdate { + store.Set(v.key, v.val) + } + + ctx.Logger().Info("Finished migrating cron Schedules...") + + return nil +} diff --git a/x/cron/module.go b/x/cron/module.go new file mode 100644 index 000000000..5178e8559 --- /dev/null +++ b/x/cron/module.go @@ -0,0 +1,171 @@ +package cron + +import ( + "context" + "encoding/json" + "fmt" + + "cosmossdk.io/core/appmodule" + + "github.com/gorilla/mux" + + "github.com/grpc-ecosystem/grpc-gateway/runtime" + "github.com/spf13/cobra" + + abci "github.com/cometbft/cometbft/abci/types" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/codec" + cdctypes "github.com/cosmos/cosmos-sdk/codec/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/module" + + "github.com/scrtlabs/SecretNetwork/x/cron/client/cli" + "github.com/scrtlabs/SecretNetwork/x/cron/keeper" + "github.com/scrtlabs/SecretNetwork/x/cron/types" +) + +var ( + _ appmodule.AppModule = AppModule{} + _ module.AppModuleBasic = AppModuleBasic{} + // _ appmodule.HasBeginBlocker = AppModule{} + // _ appmodule.HasEndBlocker = AppModule{} +) + +// ---------------------------------------------------------------------------- +// AppModuleBasic +// ---------------------------------------------------------------------------- + +// AppModuleBasic implements the AppModuleBasic interface that defines the independent methods a Cosmos SDK module needs to implement. +type AppModuleBasic struct { + cdc codec.BinaryCodec +} + +func NewAppModuleBasic(cdc codec.BinaryCodec) AppModuleBasic { + return AppModuleBasic{cdc: cdc} +} + +// Name returns the name of the module as a string +func (AppModuleBasic) Name() string { + return types.ModuleName +} + +// RegisterLegacyAminoCodec registers the amino codec for the module, which is used to marshal and unmarshal structs to/from []byte in order to persist them in the module's KVStore +func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { + types.RegisterCodec(cdc) +} + +// RegisterInterfaces registers a module's interface types and their concrete implementations as proto.Message +func (a AppModuleBasic) RegisterInterfaces(reg cdctypes.InterfaceRegistry) { + types.RegisterInterfaces(reg) +} + +// DefaultGenesis returns a default GenesisState for the module, marshalled to json.RawMessage. The default GenesisState need to be defined by the module developer and is primarily used for testing +func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage { + return cdc.MustMarshalJSON(types.DefaultGenesis()) +} + +// ValidateGenesis used to validate the GenesisState, given in its json.RawMessage form +func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, _ client.TxEncodingConfig, bz json.RawMessage) error { + var genState types.GenesisState + if err := cdc.UnmarshalJSON(bz, &genState); err != nil { + return fmt.Errorf("failed to unmarshal %s genesis state: %w", types.ModuleName, err) + } + return genState.Validate() +} + +// RegisterRESTRoutes registers the capability module's REST service handlers. +func (AppModuleBasic) RegisterRESTRoutes(_ client.Context, _ *mux.Router) { +} + +// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the module +func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) { + types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)) //nolint:errcheck +} + +// GetTxCmd returns the root Tx command for the module. The subcommands of this root command are used by end-users to generate new transactions containing messages defined in the module +func (a AppModuleBasic) GetTxCmd() *cobra.Command { + return cli.GetTxCmd() +} + +// GetQueryCmd returns the root query command for the module. The subcommands of this root command are used by end-users to generate new queries to the subset of the state defined by the module +func (AppModuleBasic) GetQueryCmd() *cobra.Command { + return cli.GetQueryCmd(types.StoreKey) +} + +// ---------------------------------------------------------------------------- +// AppModule +// ---------------------------------------------------------------------------- + +var _ appmodule.AppModule = AppModule{} + +// AppModule implements the AppModule interface that defines the inter-dependent methods that modules need to implement +type AppModule struct { + AppModuleBasic + + keeper keeper.Keeper +} + +func NewAppModule( + cdc codec.Codec, + keeper keeper.Keeper, +) AppModule { + return AppModule{ + AppModuleBasic: NewAppModuleBasic(cdc), + keeper: keeper, + } +} + +// IsOnePerModuleType implements the depinject.OnePerModuleType interface. +func (am AppModule) IsOnePerModuleType() { // marker +} + +// IsAppModule implements the appmodule.AppModule interface. +func (am AppModule) IsAppModule() { // marker +} + +// Deprecated: use RegisterServices +func (AppModule) QuerierRoute() string { return types.RouterKey } + +// RegisterServices registers a gRPC query service to respond to the module-specific gRPC queries +func (am AppModule) RegisterServices(cfg module.Configurator) { + types.RegisterQueryServer(cfg.QueryServer(), am.keeper) + types.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(am.keeper)) +} + +// RegisterInvariants registers the invariants of the module. If an invariant deviates from its predicted value, the InvariantRegistry triggers appropriate logic (most often the chain will be halted) +func (am AppModule) RegisterInvariants(_ sdk.InvariantRegistry) {} + +// InitGenesis performs the module's genesis initialization. It returns no validator updates. +func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, gs json.RawMessage) []abci.ValidatorUpdate { + var genState types.GenesisState + // Initialize global index to index in genesis state + cdc.MustUnmarshalJSON(gs, &genState) + + InitGenesis(ctx, am.keeper, genState) + + return []abci.ValidatorUpdate{} +} + +// ExportGenesis returns the module's exported genesis state as raw JSON bytes. +func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage { + genState := ExportGenesis(ctx, am.keeper) + return cdc.MustMarshalJSON(genState) +} + +// ConsensusVersion is a sequence number for state-breaking change of the module. It should be incremented on each consensus-breaking change introduced by the module. To avoid wrong/empty versions, the initial version should be set to 1 +func (AppModule) ConsensusVersion() uint64 { return types.ConsensusVersion } + +// // BeginBlock contains the logic that is automatically triggered at the beginning of each block +// func (am AppModule) BeginBlock(ctx context.Context) error { +// // am.keeper.ExecuteReadySchedules(sdk.UnwrapSDKContext(ctx), types.ExecutionStage_EXECUTION_STAGE_BEGIN_BLOCKER) +// return nil +// } + +// // EndBlock contains the logic that is automatically triggered at the end of each block +// func (am AppModule) EndBlock(ctx context.Context) error { +// // am.keeper.ExecuteReadySchedules(sdk.UnwrapSDKContext(ctx), types.ExecutionStage_EXECUTION_STAGE_END_BLOCKER) +// // api.SubmitBlockSignatures() +// // am.keeper.GetScheduledMsgs(); +// return nil +// } diff --git a/x/cron/module_simulation.go b/x/cron/module_simulation.go new file mode 100644 index 000000000..a93a336e9 --- /dev/null +++ b/x/cron/module_simulation.go @@ -0,0 +1,47 @@ +package cron + +import ( + "github.com/cosmos/cosmos-sdk/baseapp" + "github.com/cosmos/cosmos-sdk/testutil/sims" + "github.com/cosmos/cosmos-sdk/types/module" + simtypes "github.com/cosmos/cosmos-sdk/types/simulation" + "github.com/cosmos/cosmos-sdk/x/simulation" + + cronsimulation "github.com/scrtlabs/SecretNetwork/x/cron/simulation" + "github.com/scrtlabs/SecretNetwork/x/cron/types" +) + +// avoid unused import issue +var ( + _ = cronsimulation.FindAccount + _ = sims.StakePerAccount + _ = simulation.MsgEntryKind + _ = baseapp.Paramspace +) + +// GenerateGenesisState creates a randomized GenState of the module +func (AppModule) GenerateGenesisState(simState *module.SimulationState) { + accs := make([]string, len(simState.Accounts)) + for i, acc := range simState.Accounts { + accs[i] = acc.Address.String() + } + cronGenesis := types.GenesisState{ + Params: types.DefaultParams(), + } + simState.GenState[types.ModuleName] = simState.Cdc.MustMarshalJSON(&cronGenesis) +} + +// ProposalContents doesn't return any content functions for governance proposals +func (AppModule) ProposalContents(_ module.SimulationState) []simtypes.WeightedProposalMsg { + return nil +} + +// TODO +// RegisterStoreDecoder registers a decoder +func (am AppModule) RegisterStoreDecoder(_ simtypes.StoreDecoderRegistry) {} + +// WeightedOperations returns the all the gov module operations with their respective weights. +func (am AppModule) WeightedOperations(_ module.SimulationState) []simtypes.WeightedOperation { + operations := make([]simtypes.WeightedOperation, 0) + return operations +} diff --git a/x/cron/simulation/helpers.go b/x/cron/simulation/helpers.go new file mode 100644 index 000000000..92c437c0d --- /dev/null +++ b/x/cron/simulation/helpers.go @@ -0,0 +1,15 @@ +package simulation + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + simtypes "github.com/cosmos/cosmos-sdk/types/simulation" +) + +// FindAccount find a specific address from an account list +func FindAccount(accs []simtypes.Account, address string) (simtypes.Account, bool) { + creator, err := sdk.AccAddressFromBech32(address) + if err != nil { + panic(err) + } + return simtypes.FindAccount(accs, creator) +} diff --git a/x/cron/types/codec.go b/x/cron/types/codec.go new file mode 100644 index 000000000..7776c54d1 --- /dev/null +++ b/x/cron/types/codec.go @@ -0,0 +1,27 @@ +package types + +import ( + "github.com/cosmos/cosmos-sdk/codec" + cdctypes "github.com/cosmos/cosmos-sdk/codec/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/msgservice" +) + +func RegisterCodec(cdc *codec.LegacyAmino) { + cdc.RegisterConcrete(&MsgUpdateParams{}, "secret.cron.MsgUpdateParams", nil) +} + +func RegisterInterfaces(registry cdctypes.InterfaceRegistry) { + registry.RegisterImplementations( + (*sdk.Msg)(nil), + &MsgUpdateParams{}, + &MsgAddSchedule{}, + &MsgRemoveSchedule{}, + ) + msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc) +} + +var ( + Amino = codec.NewLegacyAmino() + ModuleCdc = codec.NewProtoCodec(cdctypes.NewInterfaceRegistry()) +) diff --git a/x/cron/types/constants.go b/x/cron/types/constants.go new file mode 100644 index 000000000..6bad94d03 --- /dev/null +++ b/x/cron/types/constants.go @@ -0,0 +1,3 @@ +package types + +const ConsensusVersion = 1 diff --git a/x/cron/types/errors.go b/x/cron/types/errors.go new file mode 100644 index 000000000..8bc535d7e --- /dev/null +++ b/x/cron/types/errors.go @@ -0,0 +1,12 @@ +package types + +// DONTCOVER + +import ( + "cosmossdk.io/errors" +) + +// x/cron module sentinel errors +var ( + ErrSample = errors.Register(ModuleName, 1100, "sample error") +) diff --git a/x/cron/types/expected_keepers.go b/x/cron/types/expected_keepers.go new file mode 100644 index 000000000..46d13d579 --- /dev/null +++ b/x/cron/types/expected_keepers.go @@ -0,0 +1,25 @@ +package types + +import ( + context "context" + + sdk "github.com/cosmos/cosmos-sdk/types" + regtypes "github.com/scrtlabs/SecretNetwork/x/registration" +) + +// AccountKeeper defines the expected account keeper used for simulations (noalias) +type AccountKeeper interface { + GetModuleAddress(name string) sdk.AccAddress + GetAccount(ctx context.Context, addr sdk.AccAddress) sdk.AccountI + GetModuleAccount(ctx context.Context, name string) sdk.ModuleAccountI + // Methods imported from account should be defined here +} + +type RegKeeper interface { + GetMasterKey(ctx sdk.Context, keyType string) *regtypes.MasterKey +} + +// type WasmMsgServer interface { +// ExecuteContract(context.Context, *MsgExecuteContract) (*MsgExecuteContract, error) +// // Methods imported from account should be defined here +// } diff --git a/x/cron/types/genesis.go b/x/cron/types/genesis.go new file mode 100644 index 000000000..4fad02046 --- /dev/null +++ b/x/cron/types/genesis.go @@ -0,0 +1,28 @@ +package types + +import "fmt" + +// DefaultGenesis returns the default genesis state +func DefaultGenesis() *GenesisState { + return &GenesisState{ + ScheduleList: []Schedule{}, + Params: DefaultParams(), + } +} + +// Validate performs basic genesis state validation returning an error upon any +// failure. +func (gs GenesisState) Validate() error { + // Check for duplicated index in schedule + scheduleIndexMap := make(map[string]struct{}) + + for _, elem := range gs.ScheduleList { + index := string(GetScheduleKey(elem.Name)) + if _, ok := scheduleIndexMap[index]; ok { + return fmt.Errorf("duplicated index for schedule") + } + scheduleIndexMap[index] = struct{}{} + } + + return gs.Params.Validate() +} diff --git a/x/cron/types/genesis.pb.go b/x/cron/types/genesis.pb.go new file mode 100644 index 000000000..2198fa768 --- /dev/null +++ b/x/cron/types/genesis.pb.go @@ -0,0 +1,386 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: secret/cron/genesis.proto + +package types + +import ( + fmt "fmt" + _ "github.com/cosmos/gogoproto/gogoproto" + proto "github.com/cosmos/gogoproto/proto" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// Defines the cron module's genesis state. +type GenesisState struct { + ScheduleList []Schedule `protobuf:"bytes,2,rep,name=scheduleList,proto3" json:"scheduleList"` + Params Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params"` +} + +func (m *GenesisState) Reset() { *m = GenesisState{} } +func (m *GenesisState) String() string { return proto.CompactTextString(m) } +func (*GenesisState) ProtoMessage() {} +func (*GenesisState) Descriptor() ([]byte, []int) { + return fileDescriptor_0e9b2ffd73e56838, []int{0} +} +func (m *GenesisState) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *GenesisState) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_GenesisState.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *GenesisState) XXX_Merge(src proto.Message) { + xxx_messageInfo_GenesisState.Merge(m, src) +} +func (m *GenesisState) XXX_Size() int { + return m.Size() +} +func (m *GenesisState) XXX_DiscardUnknown() { + xxx_messageInfo_GenesisState.DiscardUnknown(m) +} + +var xxx_messageInfo_GenesisState proto.InternalMessageInfo + +func (m *GenesisState) GetScheduleList() []Schedule { + if m != nil { + return m.ScheduleList + } + return nil +} + +func (m *GenesisState) GetParams() Params { + if m != nil { + return m.Params + } + return Params{} +} + +func init() { + proto.RegisterType((*GenesisState)(nil), "secret.cron.GenesisState") +} + +func init() { proto.RegisterFile("secret/cron/genesis.proto", fileDescriptor_0e9b2ffd73e56838) } + +var fileDescriptor_0e9b2ffd73e56838 = []byte{ + // 241 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0x2c, 0x4e, 0x4d, 0x2e, + 0x4a, 0x2d, 0xd1, 0x4f, 0x2e, 0xca, 0xcf, 0xd3, 0x4f, 0x4f, 0xcd, 0x4b, 0x2d, 0xce, 0x2c, 0xd6, + 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0xe2, 0x86, 0x48, 0xe9, 0x81, 0xa4, 0xa4, 0x44, 0xd2, 0xf3, + 0xd3, 0xf3, 0xc1, 0xe2, 0xfa, 0x20, 0x16, 0x44, 0x89, 0x94, 0x04, 0xb2, 0xee, 0x82, 0xc4, 0xa2, + 0xc4, 0x5c, 0xa8, 0x66, 0x29, 0x29, 0x64, 0x99, 0xe2, 0xe4, 0x8c, 0xd4, 0x94, 0xd2, 0x9c, 0x54, + 0x88, 0x9c, 0x52, 0x13, 0x23, 0x17, 0x8f, 0x3b, 0xc4, 0xaa, 0xe0, 0x92, 0xc4, 0x92, 0x54, 0x21, + 0x7b, 0x2e, 0x1e, 0x98, 0x12, 0x9f, 0xcc, 0xe2, 0x12, 0x09, 0x26, 0x05, 0x66, 0x0d, 0x6e, 0x23, + 0x51, 0x3d, 0x24, 0x07, 0xe8, 0x05, 0x43, 0x15, 0x38, 0xb1, 0x9c, 0xb8, 0x27, 0xcf, 0x10, 0x84, + 0xa2, 0x41, 0xc8, 0x90, 0x8b, 0x0d, 0x62, 0xbb, 0x04, 0xa3, 0x02, 0xa3, 0x06, 0xb7, 0x91, 0x30, + 0x8a, 0xd6, 0x00, 0xb0, 0x14, 0x54, 0x23, 0x54, 0xa1, 0x93, 0xc7, 0x89, 0x47, 0x72, 0x8c, 0x17, + 0x1e, 0xc9, 0x31, 0x3e, 0x78, 0x24, 0xc7, 0x38, 0xe1, 0xb1, 0x1c, 0xc3, 0x85, 0xc7, 0x72, 0x0c, + 0x37, 0x1e, 0xcb, 0x31, 0x44, 0xe9, 0xa5, 0x67, 0x96, 0x64, 0x94, 0x26, 0xe9, 0x25, 0xe7, 0xe7, + 0xea, 0x17, 0x27, 0x17, 0x95, 0xe4, 0x24, 0x26, 0x15, 0xeb, 0x07, 0x83, 0xcd, 0xf3, 0x4b, 0x2d, + 0x29, 0xcf, 0x2f, 0xca, 0xd6, 0xaf, 0x80, 0xf8, 0xab, 0xa4, 0xb2, 0x20, 0xb5, 0x38, 0x89, 0x0d, + 0xec, 0x2b, 0x63, 0x40, 0x00, 0x00, 0x00, 0xff, 0xff, 0x7f, 0xff, 0x8e, 0x52, 0x4b, 0x01, 0x00, + 0x00, +} + +func (m *GenesisState) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *GenesisState) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.ScheduleList) > 0 { + for iNdEx := len(m.ScheduleList) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.ScheduleList[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + } + { + size, err := m.Params.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func encodeVarintGenesis(dAtA []byte, offset int, v uint64) int { + offset -= sovGenesis(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *GenesisState) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.Params.Size() + n += 1 + l + sovGenesis(uint64(l)) + if len(m.ScheduleList) > 0 { + for _, e := range m.ScheduleList { + l = e.Size() + n += 1 + l + sovGenesis(uint64(l)) + } + } + return n +} + +func sovGenesis(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozGenesis(x uint64) (n int) { + return sovGenesis(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *GenesisState) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: GenesisState: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: GenesisState: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Params", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Params.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ScheduleList", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ScheduleList = append(m.ScheduleList, Schedule{}) + if err := m.ScheduleList[len(m.ScheduleList)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipGenesis(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthGenesis + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipGenesis(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowGenesis + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowGenesis + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowGenesis + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthGenesis + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupGenesis + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthGenesis + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthGenesis = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowGenesis = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupGenesis = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/cron/types/keys.go b/x/cron/types/keys.go new file mode 100644 index 000000000..95bb9a676 --- /dev/null +++ b/x/cron/types/keys.go @@ -0,0 +1,31 @@ +package types + +const ( + // ModuleName defines the module name + ModuleName = "cron" + + // StoreKey defines the primary module store key + StoreKey = ModuleName + + // RouterKey defines the module's message routing key + RouterKey = ModuleName + + // MemStoreKey defines the in-memory store key + MemStoreKey = "mem_cron" +) + +const ( + prefixScheduleKey = iota + 1 + prefixScheduleCountKey + prefixParamsKey +) + +var ( + ScheduleKey = []byte{prefixScheduleKey} + ScheduleCountKey = []byte{prefixScheduleCountKey} + ParamsKey = []byte{prefixParamsKey} +) + +func GetScheduleKey(name string) []byte { + return []byte(name) +} diff --git a/x/cron/types/params.go b/x/cron/types/params.go new file mode 100644 index 000000000..2ad7cf24c --- /dev/null +++ b/x/cron/types/params.go @@ -0,0 +1,106 @@ +package types + +import ( + "fmt" + + sdk "github.com/cosmos/cosmos-sdk/types" + paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" + "gopkg.in/yaml.v2" +) + +var _ paramtypes.ParamSet = (*Params)(nil) + +var ( + KeySecurityAddress = []byte("SecurityAddress") + KeyLimit = []byte("Limit") + + DefaultSecurityAddress = "" + DefaultLimit = uint64(5) +) + +// ParamKeyTable the param key table for launch module +func ParamKeyTable() paramtypes.KeyTable { + return paramtypes.NewKeyTable().RegisterParamSet(&Params{}) +} + +// NewParams creates a new Params instance +func NewParams(securityAddress string, limit uint64) Params { + return Params{ + SecurityAddress: securityAddress, + Limit: limit, + } +} + +// DefaultParams returns a default set of parameters +func DefaultParams() Params { + return NewParams(DefaultSecurityAddress, DefaultLimit) +} + +// ParamSetPairs get the params.ParamSet +func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs { + return paramtypes.ParamSetPairs{ + paramtypes.NewParamSetPair( + KeySecurityAddress, + &p.SecurityAddress, + validateAddress, + ), + paramtypes.NewParamSetPair( + KeyLimit, + &p.Limit, + validateLimit, + ), + } +} + +// Validate validates the set of params +func (p Params) Validate() error { + err := validateAddress(p.SecurityAddress) + if err != nil { + return fmt.Errorf("invalid security address: %w", err) + } + + err = validateLimit(p.Limit) + if err != nil { + return fmt.Errorf("invalid limit: %w", err) + } + + return nil +} + +// String implements the Stringer interface. +func (p Params) String() string { + out, _ := yaml.Marshal(p) + return string(out) +} + +func validateAddress(i interface{}) error { + v, ok := i.(string) + if !ok { + return fmt.Errorf("invalid parameter type: %T", i) + } + + // address might be explicitly empty in test environments + if len(v) == 0 { + return nil + } + + _, err := sdk.AccAddressFromBech32(v) + if err != nil { + return fmt.Errorf("invalid address: %w", err) + } + + return nil +} + +func validateLimit(i interface{}) error { + l, ok := i.(uint64) + if !ok { + return fmt.Errorf("invalid parameter type: %T", i) + } + + if l == 0 { + return fmt.Errorf("limit cannot be zero") + } + + return nil +} diff --git a/x/cron/types/params.pb.go b/x/cron/types/params.pb.go new file mode 100644 index 000000000..727b94b0e --- /dev/null +++ b/x/cron/types/params.pb.go @@ -0,0 +1,355 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: secret/cron/params.proto + +package types + +import ( + fmt "fmt" + _ "github.com/cosmos/gogoproto/gogoproto" + proto "github.com/cosmos/gogoproto/proto" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// Defines the parameters for the module. +type Params struct { + // Security address that can remove schedules + SecurityAddress string `protobuf:"bytes,1,opt,name=security_address,json=securityAddress,proto3" json:"security_address,omitempty"` + // Limit of schedules executed in one block + Limit uint64 `protobuf:"varint,2,opt,name=limit,proto3" json:"limit,omitempty"` +} + +func (m *Params) Reset() { *m = Params{} } +func (*Params) ProtoMessage() {} +func (*Params) Descriptor() ([]byte, []int) { + return fileDescriptor_b2b633a1a1b37414, []int{0} +} +func (m *Params) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Params) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Params.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *Params) XXX_Merge(src proto.Message) { + xxx_messageInfo_Params.Merge(m, src) +} +func (m *Params) XXX_Size() int { + return m.Size() +} +func (m *Params) XXX_DiscardUnknown() { + xxx_messageInfo_Params.DiscardUnknown(m) +} + +var xxx_messageInfo_Params proto.InternalMessageInfo + +func (m *Params) GetSecurityAddress() string { + if m != nil { + return m.SecurityAddress + } + return "" +} + +func (m *Params) GetLimit() uint64 { + if m != nil { + return m.Limit + } + return 0 +} + +func init() { + proto.RegisterType((*Params)(nil), "secret.cron.Params") +} + +func init() { proto.RegisterFile("secret/cron/params.proto", fileDescriptor_b2b633a1a1b37414) } + +var fileDescriptor_b2b633a1a1b37414 = []byte{ + // 207 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0x28, 0x4e, 0x4d, 0x2e, + 0x4a, 0x2d, 0xd1, 0x4f, 0x2e, 0xca, 0xcf, 0xd3, 0x2f, 0x48, 0x2c, 0x4a, 0xcc, 0x2d, 0xd6, 0x2b, + 0x28, 0xca, 0x2f, 0xc9, 0x17, 0xe2, 0x86, 0xc8, 0xe8, 0x81, 0x64, 0xa4, 0x44, 0xd2, 0xf3, 0xd3, + 0xf3, 0xc1, 0xe2, 0xfa, 0x20, 0x16, 0x44, 0x89, 0x92, 0x3f, 0x17, 0x5b, 0x00, 0x58, 0x8b, 0x90, + 0x26, 0x97, 0x40, 0x71, 0x6a, 0x72, 0x69, 0x51, 0x66, 0x49, 0x65, 0x7c, 0x62, 0x4a, 0x4a, 0x51, + 0x6a, 0x71, 0xb1, 0x04, 0xa3, 0x02, 0xa3, 0x06, 0x67, 0x10, 0x3f, 0x4c, 0xdc, 0x11, 0x22, 0x2c, + 0x24, 0xc2, 0xc5, 0x9a, 0x93, 0x99, 0x9b, 0x59, 0x22, 0xc1, 0xa4, 0xc0, 0xa8, 0xc1, 0x12, 0x04, + 0xe1, 0x58, 0xb1, 0xcc, 0x58, 0x20, 0xcf, 0xe0, 0xe4, 0x71, 0xe2, 0x91, 0x1c, 0xe3, 0x85, 0x47, + 0x72, 0x8c, 0x0f, 0x1e, 0xc9, 0x31, 0x4e, 0x78, 0x2c, 0xc7, 0x70, 0xe1, 0xb1, 0x1c, 0xc3, 0x8d, + 0xc7, 0x72, 0x0c, 0x51, 0x7a, 0xe9, 0x99, 0x25, 0x19, 0xa5, 0x49, 0x7a, 0xc9, 0xf9, 0xb9, 0xfa, + 0xc5, 0xc9, 0x45, 0x25, 0x39, 0x89, 0x49, 0xc5, 0xfa, 0xc1, 0x60, 0x17, 0xfa, 0xa5, 0x96, 0x94, + 0xe7, 0x17, 0x65, 0xeb, 0x57, 0x40, 0x3c, 0x51, 0x52, 0x59, 0x90, 0x5a, 0x9c, 0xc4, 0x06, 0x76, + 0xa1, 0x31, 0x20, 0x00, 0x00, 0xff, 0xff, 0xf9, 0xd2, 0x4e, 0xc9, 0xe0, 0x00, 0x00, 0x00, +} + +func (m *Params) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *Params) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Params) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Limit != 0 { + i = encodeVarintParams(dAtA, i, uint64(m.Limit)) + i-- + dAtA[i] = 0x10 + } + if len(m.SecurityAddress) > 0 { + i -= len(m.SecurityAddress) + copy(dAtA[i:], m.SecurityAddress) + i = encodeVarintParams(dAtA, i, uint64(len(m.SecurityAddress))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func encodeVarintParams(dAtA []byte, offset int, v uint64) int { + offset -= sovParams(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *Params) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.SecurityAddress) + if l > 0 { + n += 1 + l + sovParams(uint64(l)) + } + if m.Limit != 0 { + n += 1 + sovParams(uint64(m.Limit)) + } + return n +} + +func sovParams(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozParams(x uint64) (n int) { + return sovParams(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *Params) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: Params: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Params: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field SecurityAddress", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthParams + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthParams + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.SecurityAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Limit", wireType) + } + m.Limit = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Limit |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipParams(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthParams + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipParams(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowParams + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowParams + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowParams + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthParams + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupParams + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthParams + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthParams = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowParams = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupParams = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/cron/types/query.pb.go b/x/cron/types/query.pb.go new file mode 100644 index 000000000..f616d87d8 --- /dev/null +++ b/x/cron/types/query.pb.go @@ -0,0 +1,1392 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: secret/cron/query.proto + +package types + +import ( + context "context" + fmt "fmt" + query "github.com/cosmos/cosmos-sdk/types/query" + _ "github.com/cosmos/gogoproto/gogoproto" + grpc1 "github.com/cosmos/gogoproto/grpc" + proto "github.com/cosmos/gogoproto/proto" + _ "google.golang.org/genproto/googleapis/api/annotations" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// The request type for the Query/Params RPC method. +type QueryParamsRequest struct { +} + +func (m *QueryParamsRequest) Reset() { *m = QueryParamsRequest{} } +func (m *QueryParamsRequest) String() string { return proto.CompactTextString(m) } +func (*QueryParamsRequest) ProtoMessage() {} +func (*QueryParamsRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_097808e20bacb68e, []int{0} +} +func (m *QueryParamsRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryParamsRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryParamsRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryParamsRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryParamsRequest.Merge(m, src) +} +func (m *QueryParamsRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryParamsRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryParamsRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryParamsRequest proto.InternalMessageInfo + +// The response type for the Query/Params RPC method. +type QueryParamsResponse struct { + // params holds all the parameters of this module. + Params Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params"` +} + +func (m *QueryParamsResponse) Reset() { *m = QueryParamsResponse{} } +func (m *QueryParamsResponse) String() string { return proto.CompactTextString(m) } +func (*QueryParamsResponse) ProtoMessage() {} +func (*QueryParamsResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_097808e20bacb68e, []int{1} +} +func (m *QueryParamsResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryParamsResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryParamsResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryParamsResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryParamsResponse.Merge(m, src) +} +func (m *QueryParamsResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryParamsResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryParamsResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryParamsResponse proto.InternalMessageInfo + +func (m *QueryParamsResponse) GetParams() Params { + if m != nil { + return m.Params + } + return Params{} +} + +// The request type for the Query/Schedule RPC method. +type QueryGetScheduleRequest struct { + Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` +} + +func (m *QueryGetScheduleRequest) Reset() { *m = QueryGetScheduleRequest{} } +func (m *QueryGetScheduleRequest) String() string { return proto.CompactTextString(m) } +func (*QueryGetScheduleRequest) ProtoMessage() {} +func (*QueryGetScheduleRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_097808e20bacb68e, []int{2} +} +func (m *QueryGetScheduleRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryGetScheduleRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryGetScheduleRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryGetScheduleRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryGetScheduleRequest.Merge(m, src) +} +func (m *QueryGetScheduleRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryGetScheduleRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryGetScheduleRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryGetScheduleRequest proto.InternalMessageInfo + +func (m *QueryGetScheduleRequest) GetName() string { + if m != nil { + return m.Name + } + return "" +} + +// The response type for the Query/Params RPC method. +type QueryGetScheduleResponse struct { + Schedule Schedule `protobuf:"bytes,1,opt,name=schedule,proto3" json:"schedule"` +} + +func (m *QueryGetScheduleResponse) Reset() { *m = QueryGetScheduleResponse{} } +func (m *QueryGetScheduleResponse) String() string { return proto.CompactTextString(m) } +func (*QueryGetScheduleResponse) ProtoMessage() {} +func (*QueryGetScheduleResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_097808e20bacb68e, []int{3} +} +func (m *QueryGetScheduleResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryGetScheduleResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryGetScheduleResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryGetScheduleResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryGetScheduleResponse.Merge(m, src) +} +func (m *QueryGetScheduleResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryGetScheduleResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryGetScheduleResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryGetScheduleResponse proto.InternalMessageInfo + +func (m *QueryGetScheduleResponse) GetSchedule() Schedule { + if m != nil { + return m.Schedule + } + return Schedule{} +} + +// The request type for the Query/Schedules RPC method. +type QuerySchedulesRequest struct { + Pagination *query.PageRequest `protobuf:"bytes,1,opt,name=pagination,proto3" json:"pagination,omitempty"` +} + +func (m *QuerySchedulesRequest) Reset() { *m = QuerySchedulesRequest{} } +func (m *QuerySchedulesRequest) String() string { return proto.CompactTextString(m) } +func (*QuerySchedulesRequest) ProtoMessage() {} +func (*QuerySchedulesRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_097808e20bacb68e, []int{4} +} +func (m *QuerySchedulesRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QuerySchedulesRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QuerySchedulesRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QuerySchedulesRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QuerySchedulesRequest.Merge(m, src) +} +func (m *QuerySchedulesRequest) XXX_Size() int { + return m.Size() +} +func (m *QuerySchedulesRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QuerySchedulesRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QuerySchedulesRequest proto.InternalMessageInfo + +func (m *QuerySchedulesRequest) GetPagination() *query.PageRequest { + if m != nil { + return m.Pagination + } + return nil +} + +// The response type for the Query/Params RPC method. +type QuerySchedulesResponse struct { + Schedules []Schedule `protobuf:"bytes,1,rep,name=schedules,proto3" json:"schedules"` + Pagination *query.PageResponse `protobuf:"bytes,2,opt,name=pagination,proto3" json:"pagination,omitempty"` +} + +func (m *QuerySchedulesResponse) Reset() { *m = QuerySchedulesResponse{} } +func (m *QuerySchedulesResponse) String() string { return proto.CompactTextString(m) } +func (*QuerySchedulesResponse) ProtoMessage() {} +func (*QuerySchedulesResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_097808e20bacb68e, []int{5} +} +func (m *QuerySchedulesResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QuerySchedulesResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QuerySchedulesResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QuerySchedulesResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QuerySchedulesResponse.Merge(m, src) +} +func (m *QuerySchedulesResponse) XXX_Size() int { + return m.Size() +} +func (m *QuerySchedulesResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QuerySchedulesResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QuerySchedulesResponse proto.InternalMessageInfo + +func (m *QuerySchedulesResponse) GetSchedules() []Schedule { + if m != nil { + return m.Schedules + } + return nil +} + +func (m *QuerySchedulesResponse) GetPagination() *query.PageResponse { + if m != nil { + return m.Pagination + } + return nil +} + +func init() { + proto.RegisterType((*QueryParamsRequest)(nil), "secret.cron.QueryParamsRequest") + proto.RegisterType((*QueryParamsResponse)(nil), "secret.cron.QueryParamsResponse") + proto.RegisterType((*QueryGetScheduleRequest)(nil), "secret.cron.QueryGetScheduleRequest") + proto.RegisterType((*QueryGetScheduleResponse)(nil), "secret.cron.QueryGetScheduleResponse") + proto.RegisterType((*QuerySchedulesRequest)(nil), "secret.cron.QuerySchedulesRequest") + proto.RegisterType((*QuerySchedulesResponse)(nil), "secret.cron.QuerySchedulesResponse") +} + +func init() { proto.RegisterFile("secret/cron/query.proto", fileDescriptor_097808e20bacb68e) } + +var fileDescriptor_097808e20bacb68e = []byte{ + // 497 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0x93, 0xcf, 0x6e, 0xd3, 0x40, + 0x10, 0xc6, 0xe3, 0x50, 0xa2, 0x66, 0x7a, 0x9b, 0x34, 0x24, 0x32, 0xc5, 0xad, 0x4c, 0xf9, 0x23, + 0x24, 0x76, 0x95, 0x72, 0x40, 0x5c, 0x7b, 0xa0, 0x3d, 0xa1, 0x92, 0xdc, 0xb8, 0xa0, 0xb5, 0x59, + 0x39, 0x11, 0x89, 0xd7, 0xf5, 0x6e, 0x80, 0x0a, 0xf5, 0xc2, 0x13, 0x20, 0x71, 0xe5, 0x81, 0x7a, + 0xac, 0xc4, 0x85, 0x13, 0x42, 0x09, 0xbc, 0x07, 0xf2, 0xfe, 0x69, 0xed, 0xba, 0x34, 0xb7, 0x95, + 0xe7, 0x9b, 0xef, 0xfb, 0xed, 0xce, 0x18, 0x7a, 0x92, 0xc7, 0x39, 0x57, 0x34, 0xce, 0x45, 0x4a, + 0x8f, 0xe7, 0x3c, 0x3f, 0x21, 0x59, 0x2e, 0x94, 0xc0, 0x0d, 0x53, 0x20, 0x45, 0xc1, 0x7f, 0x12, + 0x0b, 0x39, 0x13, 0x92, 0x46, 0x4c, 0x72, 0xa3, 0xa2, 0x1f, 0x06, 0x11, 0x57, 0x6c, 0x40, 0x33, + 0x96, 0x4c, 0x52, 0xa6, 0x26, 0x22, 0x35, 0x8d, 0xfe, 0x66, 0x22, 0x12, 0xa1, 0x8f, 0xb4, 0x38, + 0xd9, 0xaf, 0x5b, 0x89, 0x10, 0xc9, 0x94, 0x53, 0x96, 0x4d, 0x28, 0x4b, 0x53, 0xa1, 0x74, 0x8b, + 0xb4, 0xd5, 0x7e, 0x99, 0x22, 0x63, 0x39, 0x9b, 0xb9, 0x8a, 0x5f, 0xae, 0xc8, 0x78, 0xcc, 0xdf, + 0xcd, 0xa7, 0xdc, 0xd4, 0xc2, 0x4d, 0xc0, 0xd7, 0x05, 0xcb, 0x91, 0x6e, 0x18, 0xf2, 0xe3, 0x39, + 0x97, 0x2a, 0x3c, 0x84, 0x4e, 0xe5, 0xab, 0xcc, 0x44, 0x2a, 0x39, 0x0e, 0xa0, 0x65, 0x8c, 0xfb, + 0xde, 0x8e, 0xf7, 0x78, 0x63, 0xaf, 0x43, 0x4a, 0x17, 0x24, 0x46, 0xbc, 0xbf, 0x76, 0xf6, 0x6b, + 0xbb, 0x31, 0xb4, 0xc2, 0xf0, 0x29, 0xf4, 0xb4, 0xd3, 0x01, 0x57, 0x23, 0x9b, 0x6c, 0x43, 0x10, + 0x61, 0x2d, 0x65, 0x33, 0xae, 0xbd, 0xda, 0x43, 0x7d, 0x0e, 0x47, 0xd0, 0xaf, 0xcb, 0x6d, 0xfa, + 0x73, 0x58, 0x77, 0xf0, 0x36, 0xbf, 0x5b, 0xc9, 0x77, 0x0d, 0x96, 0xe0, 0x42, 0x1c, 0xbe, 0x85, + 0xae, 0x36, 0x75, 0x02, 0x77, 0x4d, 0x7c, 0x09, 0x70, 0xf9, 0xf4, 0xd6, 0xf3, 0x21, 0x31, 0x73, + 0x22, 0xc5, 0x9c, 0x88, 0x99, 0xa6, 0x9d, 0x13, 0x39, 0x62, 0x89, 0xa3, 0x1f, 0x96, 0x3a, 0xc3, + 0xef, 0x1e, 0xdc, 0xb9, 0x9a, 0x60, 0xa1, 0x5f, 0x40, 0xdb, 0x71, 0x14, 0xaf, 0x76, 0x6b, 0x15, + 0xf5, 0xa5, 0x1a, 0x0f, 0x2a, 0x74, 0x4d, 0x4d, 0xf7, 0x68, 0x25, 0x9d, 0xc9, 0x2d, 0xe3, 0xed, + 0xfd, 0x6d, 0xc2, 0x6d, 0x8d, 0x87, 0x63, 0x68, 0x99, 0x29, 0xe1, 0x76, 0x05, 0xa2, 0xbe, 0x02, + 0xfe, 0xce, 0xff, 0x05, 0x26, 0x22, 0xbc, 0xfb, 0xe5, 0xc7, 0x9f, 0x6f, 0xcd, 0x2e, 0x76, 0x68, + 0x7d, 0xf3, 0xf0, 0x14, 0xd6, 0xdd, 0xcd, 0x70, 0xb7, 0x6e, 0x55, 0x5f, 0x07, 0xff, 0xc1, 0x0a, + 0x95, 0x4d, 0xdd, 0xd5, 0xa9, 0x01, 0x6e, 0xd1, 0xeb, 0xb6, 0x9a, 0x7e, 0x2e, 0xd6, 0xe8, 0x14, + 0x25, 0xb4, 0x2f, 0x66, 0x81, 0x61, 0xdd, 0xf9, 0xea, 0x2a, 0xf8, 0xf7, 0x6f, 0xd4, 0xd8, 0xec, + 0x7b, 0x3a, 0xbb, 0x87, 0xdd, 0x6b, 0xb3, 0xf7, 0x0f, 0xcf, 0x16, 0x81, 0x77, 0xbe, 0x08, 0xbc, + 0xdf, 0x8b, 0xc0, 0xfb, 0xba, 0x0c, 0x1a, 0xe7, 0xcb, 0xa0, 0xf1, 0x73, 0x19, 0x34, 0xde, 0x90, + 0x64, 0xa2, 0xc6, 0xf3, 0x88, 0xc4, 0x62, 0x46, 0x65, 0x9c, 0xab, 0x29, 0x8b, 0x24, 0x1d, 0x69, + 0x8f, 0x57, 0x5c, 0x7d, 0x14, 0xf9, 0x7b, 0xfa, 0xc9, 0x98, 0xa9, 0x93, 0x8c, 0xcb, 0xa8, 0xa5, + 0x7f, 0xce, 0x67, 0xff, 0x02, 0x00, 0x00, 0xff, 0xff, 0xfe, 0x68, 0xcb, 0x84, 0x5a, 0x04, 0x00, + 0x00, +} + +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConn + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion4 + +// QueryClient is the client API for Query service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type QueryClient interface { + // Queries the parameters of the module. + Params(ctx context.Context, in *QueryParamsRequest, opts ...grpc.CallOption) (*QueryParamsResponse, error) + // Queries a Schedule by name. + Schedule(ctx context.Context, in *QueryGetScheduleRequest, opts ...grpc.CallOption) (*QueryGetScheduleResponse, error) + // Queries a list of Schedule items. + Schedules(ctx context.Context, in *QuerySchedulesRequest, opts ...grpc.CallOption) (*QuerySchedulesResponse, error) +} + +type queryClient struct { + cc grpc1.ClientConn +} + +func NewQueryClient(cc grpc1.ClientConn) QueryClient { + return &queryClient{cc} +} + +func (c *queryClient) Params(ctx context.Context, in *QueryParamsRequest, opts ...grpc.CallOption) (*QueryParamsResponse, error) { + out := new(QueryParamsResponse) + err := c.cc.Invoke(ctx, "/secret.cron.Query/Params", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *queryClient) Schedule(ctx context.Context, in *QueryGetScheduleRequest, opts ...grpc.CallOption) (*QueryGetScheduleResponse, error) { + out := new(QueryGetScheduleResponse) + err := c.cc.Invoke(ctx, "/secret.cron.Query/Schedule", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *queryClient) Schedules(ctx context.Context, in *QuerySchedulesRequest, opts ...grpc.CallOption) (*QuerySchedulesResponse, error) { + out := new(QuerySchedulesResponse) + err := c.cc.Invoke(ctx, "/secret.cron.Query/Schedules", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// QueryServer is the server API for Query service. +type QueryServer interface { + // Queries the parameters of the module. + Params(context.Context, *QueryParamsRequest) (*QueryParamsResponse, error) + // Queries a Schedule by name. + Schedule(context.Context, *QueryGetScheduleRequest) (*QueryGetScheduleResponse, error) + // Queries a list of Schedule items. + Schedules(context.Context, *QuerySchedulesRequest) (*QuerySchedulesResponse, error) +} + +// UnimplementedQueryServer can be embedded to have forward compatible implementations. +type UnimplementedQueryServer struct { +} + +func (*UnimplementedQueryServer) Params(ctx context.Context, req *QueryParamsRequest) (*QueryParamsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Params not implemented") +} +func (*UnimplementedQueryServer) Schedule(ctx context.Context, req *QueryGetScheduleRequest) (*QueryGetScheduleResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Schedule not implemented") +} +func (*UnimplementedQueryServer) Schedules(ctx context.Context, req *QuerySchedulesRequest) (*QuerySchedulesResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Schedules not implemented") +} + +func RegisterQueryServer(s grpc1.Server, srv QueryServer) { + s.RegisterService(&_Query_serviceDesc, srv) +} + +func _Query_Params_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryParamsRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).Params(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/secret.cron.Query/Params", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).Params(ctx, req.(*QueryParamsRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Query_Schedule_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryGetScheduleRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).Schedule(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/secret.cron.Query/Schedule", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).Schedule(ctx, req.(*QueryGetScheduleRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Query_Schedules_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QuerySchedulesRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).Schedules(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/secret.cron.Query/Schedules", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).Schedules(ctx, req.(*QuerySchedulesRequest)) + } + return interceptor(ctx, in, info, handler) +} + +var _Query_serviceDesc = grpc.ServiceDesc{ + ServiceName: "secret.cron.Query", + HandlerType: (*QueryServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "Params", + Handler: _Query_Params_Handler, + }, + { + MethodName: "Schedule", + Handler: _Query_Schedule_Handler, + }, + { + MethodName: "Schedules", + Handler: _Query_Schedules_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "secret/cron/query.proto", +} + +func (m *QueryParamsRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryParamsRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryParamsRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func (m *QueryParamsResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryParamsResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryParamsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.Params.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func (m *QueryGetScheduleRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryGetScheduleRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryGetScheduleRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Name) > 0 { + i -= len(m.Name) + copy(dAtA[i:], m.Name) + i = encodeVarintQuery(dAtA, i, uint64(len(m.Name))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *QueryGetScheduleResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryGetScheduleResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryGetScheduleResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.Schedule.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func (m *QuerySchedulesRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QuerySchedulesRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QuerySchedulesRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Pagination != nil { + { + size, err := m.Pagination.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *QuerySchedulesResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QuerySchedulesResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QuerySchedulesResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Pagination != nil { + { + size, err := m.Pagination.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + if len(m.Schedules) > 0 { + for iNdEx := len(m.Schedules) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Schedules[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + } + return len(dAtA) - i, nil +} + +func encodeVarintQuery(dAtA []byte, offset int, v uint64) int { + offset -= sovQuery(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *QueryParamsRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func (m *QueryParamsResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.Params.Size() + n += 1 + l + sovQuery(uint64(l)) + return n +} + +func (m *QueryGetScheduleRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Name) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *QueryGetScheduleResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.Schedule.Size() + n += 1 + l + sovQuery(uint64(l)) + return n +} + +func (m *QuerySchedulesRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Pagination != nil { + l = m.Pagination.Size() + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *QuerySchedulesResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.Schedules) > 0 { + for _, e := range m.Schedules { + l = e.Size() + n += 1 + l + sovQuery(uint64(l)) + } + } + if m.Pagination != nil { + l = m.Pagination.Size() + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func sovQuery(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozQuery(x uint64) (n int) { + return sovQuery(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *QueryParamsRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryParamsRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryParamsRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryParamsResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryParamsResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryParamsResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Params", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Params.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryGetScheduleRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryGetScheduleRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryGetScheduleRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Name", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Name = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryGetScheduleResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryGetScheduleResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryGetScheduleResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Schedule", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Schedule.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QuerySchedulesRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QuerySchedulesRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QuerySchedulesRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Pagination", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Pagination == nil { + m.Pagination = &query.PageRequest{} + } + if err := m.Pagination.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QuerySchedulesResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QuerySchedulesResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QuerySchedulesResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Schedules", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Schedules = append(m.Schedules, Schedule{}) + if err := m.Schedules[len(m.Schedules)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Pagination", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Pagination == nil { + m.Pagination = &query.PageResponse{} + } + if err := m.Pagination.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipQuery(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowQuery + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowQuery + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowQuery + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthQuery + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupQuery + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthQuery + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthQuery = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowQuery = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupQuery = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/cron/types/query.pb.gw.go b/x/cron/types/query.pb.gw.go new file mode 100644 index 000000000..5377127ef --- /dev/null +++ b/x/cron/types/query.pb.gw.go @@ -0,0 +1,337 @@ +// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT. +// source: secret/cron/query.proto + +/* +Package types is a reverse proxy. + +It translates gRPC into RESTful JSON APIs. +*/ +package types + +import ( + "context" + "io" + "net/http" + + "github.com/golang/protobuf/descriptor" + "github.com/golang/protobuf/proto" + "github.com/grpc-ecosystem/grpc-gateway/runtime" + "github.com/grpc-ecosystem/grpc-gateway/utilities" + "google.golang.org/grpc" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/grpclog" + "google.golang.org/grpc/metadata" + "google.golang.org/grpc/status" +) + +// Suppress "imported and not used" errors +var _ codes.Code +var _ io.Reader +var _ status.Status +var _ = runtime.String +var _ = utilities.NewDoubleArray +var _ = descriptor.ForMessage +var _ = metadata.Join + +func request_Query_Params_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryParamsRequest + var metadata runtime.ServerMetadata + + msg, err := client.Params(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_Params_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryParamsRequest + var metadata runtime.ServerMetadata + + msg, err := server.Params(ctx, &protoReq) + return msg, metadata, err + +} + +func request_Query_Schedule_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryGetScheduleRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["name"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "name") + } + + protoReq.Name, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "name", err) + } + + msg, err := client.Schedule(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_Schedule_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryGetScheduleRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["name"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "name") + } + + protoReq.Name, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "name", err) + } + + msg, err := server.Schedule(ctx, &protoReq) + return msg, metadata, err + +} + +var ( + filter_Query_Schedules_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)} +) + +func request_Query_Schedules_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QuerySchedulesRequest + var metadata runtime.ServerMetadata + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_Schedules_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := client.Schedules(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_Schedules_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QuerySchedulesRequest + var metadata runtime.ServerMetadata + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_Schedules_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := server.Schedules(ctx, &protoReq) + return msg, metadata, err + +} + +// RegisterQueryHandlerServer registers the http handlers for service Query to "mux". +// UnaryRPC :call QueryServer directly. +// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. +// Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterQueryHandlerFromEndpoint instead. +func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, server QueryServer) error { + + mux.Handle("GET", pattern_Query_Params_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_Params_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_Params_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_Schedule_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_Schedule_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_Schedule_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_Schedules_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_Schedules_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_Schedules_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + return nil +} + +// RegisterQueryHandlerFromEndpoint is same as RegisterQueryHandler but +// automatically dials to "endpoint" and closes the connection when "ctx" gets done. +func RegisterQueryHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) { + conn, err := grpc.Dial(endpoint, opts...) + if err != nil { + return err + } + defer func() { + if err != nil { + if cerr := conn.Close(); cerr != nil { + grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) + } + return + } + go func() { + <-ctx.Done() + if cerr := conn.Close(); cerr != nil { + grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) + } + }() + }() + + return RegisterQueryHandler(ctx, mux, conn) +} + +// RegisterQueryHandler registers the http handlers for service Query to "mux". +// The handlers forward requests to the grpc endpoint over "conn". +func RegisterQueryHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error { + return RegisterQueryHandlerClient(ctx, mux, NewQueryClient(conn)) +} + +// RegisterQueryHandlerClient registers the http handlers for service Query +// to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "QueryClient". +// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "QueryClient" +// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in +// "QueryClient" to call the correct interceptors. +func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, client QueryClient) error { + + mux.Handle("GET", pattern_Query_Params_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_Params_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_Params_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_Schedule_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_Schedule_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_Schedule_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_Schedules_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_Schedules_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_Schedules_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + return nil +} + +var ( + pattern_Query_Params_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"secret", "cron", "params"}, "", runtime.AssumeColonVerbOpt(false))) + + pattern_Query_Schedule_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3}, []string{"secret", "cron", "schedule", "name"}, "", runtime.AssumeColonVerbOpt(false))) + + pattern_Query_Schedules_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"secret", "cron", "schedule"}, "", runtime.AssumeColonVerbOpt(false))) +) + +var ( + forward_Query_Params_0 = runtime.ForwardResponseMessage + + forward_Query_Schedule_0 = runtime.ForwardResponseMessage + + forward_Query_Schedules_0 = runtime.ForwardResponseMessage +) diff --git a/x/cron/types/schedule.pb.go b/x/cron/types/schedule.pb.go new file mode 100644 index 000000000..7f6f5fc7f --- /dev/null +++ b/x/cron/types/schedule.pb.go @@ -0,0 +1,912 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: secret/cron/schedule.proto + +package types + +import ( + fmt "fmt" + _ "github.com/cosmos/gogoproto/gogoproto" + proto "github.com/cosmos/gogoproto/proto" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// Defines when messages will be executed in the block +type ExecutionStage int32 + +const ( + // Execution at the end of the block + ExecutionStage_EXECUTION_STAGE_END_BLOCKER ExecutionStage = 0 + // Execution at the beginning of the block + ExecutionStage_EXECUTION_STAGE_BEGIN_BLOCKER ExecutionStage = 1 +) + +var ExecutionStage_name = map[int32]string{ + 0: "EXECUTION_STAGE_END_BLOCKER", + 1: "EXECUTION_STAGE_BEGIN_BLOCKER", +} + +var ExecutionStage_value = map[string]int32{ + "EXECUTION_STAGE_END_BLOCKER": 0, + "EXECUTION_STAGE_BEGIN_BLOCKER": 1, +} + +func (x ExecutionStage) String() string { + return proto.EnumName(ExecutionStage_name, int32(x)) +} + +func (ExecutionStage) EnumDescriptor() ([]byte, []int) { + return fileDescriptor_3d6729589d2158da, []int{0} +} + +// Defines the schedule for execution +type Schedule struct { + // Name of schedule + Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` + // Period in blocks + Period uint64 `protobuf:"varint,2,opt,name=period,proto3" json:"period,omitempty"` + // Msgs that will be executed every certain number of blocks, specified in the `period` field + Msgs []MsgExecuteContract `protobuf:"bytes,3,rep,name=msgs,proto3" json:"msgs"` + // Last execution's block height + LastExecuteHeight uint64 `protobuf:"varint,4,opt,name=last_execute_height,json=lastExecuteHeight,proto3" json:"last_execute_height,omitempty"` + // Stage when messages will be executed + ExecutionStage ExecutionStage `protobuf:"varint,5,opt,name=execution_stage,json=executionStage,proto3,enum=secret.cron.ExecutionStage" json:"execution_stage,omitempty"` +} + +func (m *Schedule) Reset() { *m = Schedule{} } +func (m *Schedule) String() string { return proto.CompactTextString(m) } +func (*Schedule) ProtoMessage() {} +func (*Schedule) Descriptor() ([]byte, []int) { + return fileDescriptor_3d6729589d2158da, []int{0} +} +func (m *Schedule) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Schedule) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Schedule.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *Schedule) XXX_Merge(src proto.Message) { + xxx_messageInfo_Schedule.Merge(m, src) +} +func (m *Schedule) XXX_Size() int { + return m.Size() +} +func (m *Schedule) XXX_DiscardUnknown() { + xxx_messageInfo_Schedule.DiscardUnknown(m) +} + +var xxx_messageInfo_Schedule proto.InternalMessageInfo + +func (m *Schedule) GetName() string { + if m != nil { + return m.Name + } + return "" +} + +func (m *Schedule) GetPeriod() uint64 { + if m != nil { + return m.Period + } + return 0 +} + +func (m *Schedule) GetMsgs() []MsgExecuteContract { + if m != nil { + return m.Msgs + } + return nil +} + +func (m *Schedule) GetLastExecuteHeight() uint64 { + if m != nil { + return m.LastExecuteHeight + } + return 0 +} + +func (m *Schedule) GetExecutionStage() ExecutionStage { + if m != nil { + return m.ExecutionStage + } + return ExecutionStage_EXECUTION_STAGE_END_BLOCKER +} + +// Defines the contract and the message to pass +type MsgExecuteContract struct { + // The address of the smart contract + Contract string `protobuf:"bytes,1,opt,name=contract,proto3" json:"contract,omitempty"` + // JSON encoded message to be passed to the contract + Msg string `protobuf:"bytes,2,opt,name=msg,proto3" json:"msg,omitempty"` +} + +func (m *MsgExecuteContract) Reset() { *m = MsgExecuteContract{} } +func (m *MsgExecuteContract) String() string { return proto.CompactTextString(m) } +func (*MsgExecuteContract) ProtoMessage() {} +func (*MsgExecuteContract) Descriptor() ([]byte, []int) { + return fileDescriptor_3d6729589d2158da, []int{1} +} +func (m *MsgExecuteContract) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgExecuteContract) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgExecuteContract.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgExecuteContract) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgExecuteContract.Merge(m, src) +} +func (m *MsgExecuteContract) XXX_Size() int { + return m.Size() +} +func (m *MsgExecuteContract) XXX_DiscardUnknown() { + xxx_messageInfo_MsgExecuteContract.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgExecuteContract proto.InternalMessageInfo + +func (m *MsgExecuteContract) GetContract() string { + if m != nil { + return m.Contract + } + return "" +} + +func (m *MsgExecuteContract) GetMsg() string { + if m != nil { + return m.Msg + } + return "" +} + +// Defines the number of current schedules +type ScheduleCount struct { + // The number of current schedules + Count int32 `protobuf:"varint,1,opt,name=count,proto3" json:"count,omitempty"` +} + +func (m *ScheduleCount) Reset() { *m = ScheduleCount{} } +func (m *ScheduleCount) String() string { return proto.CompactTextString(m) } +func (*ScheduleCount) ProtoMessage() {} +func (*ScheduleCount) Descriptor() ([]byte, []int) { + return fileDescriptor_3d6729589d2158da, []int{2} +} +func (m *ScheduleCount) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *ScheduleCount) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_ScheduleCount.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *ScheduleCount) XXX_Merge(src proto.Message) { + xxx_messageInfo_ScheduleCount.Merge(m, src) +} +func (m *ScheduleCount) XXX_Size() int { + return m.Size() +} +func (m *ScheduleCount) XXX_DiscardUnknown() { + xxx_messageInfo_ScheduleCount.DiscardUnknown(m) +} + +var xxx_messageInfo_ScheduleCount proto.InternalMessageInfo + +func (m *ScheduleCount) GetCount() int32 { + if m != nil { + return m.Count + } + return 0 +} + +func init() { + proto.RegisterEnum("secret.cron.ExecutionStage", ExecutionStage_name, ExecutionStage_value) + proto.RegisterType((*Schedule)(nil), "secret.cron.Schedule") + proto.RegisterType((*MsgExecuteContract)(nil), "secret.cron.MsgExecuteContract") + proto.RegisterType((*ScheduleCount)(nil), "secret.cron.ScheduleCount") +} + +func init() { proto.RegisterFile("secret/cron/schedule.proto", fileDescriptor_3d6729589d2158da) } + +var fileDescriptor_3d6729589d2158da = []byte{ + // 398 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x64, 0x52, 0x4f, 0x8b, 0xd3, 0x40, + 0x1c, 0xcd, 0xd8, 0x74, 0xd9, 0x9d, 0xc5, 0xba, 0x8e, 0x8b, 0x84, 0x2e, 0xa6, 0xb1, 0x20, 0x04, + 0x0f, 0x09, 0xac, 0x27, 0x8f, 0x26, 0x1d, 0xda, 0xa2, 0xa6, 0x90, 0x54, 0x10, 0x2f, 0x21, 0x9d, + 0x0e, 0x93, 0x60, 0x93, 0x29, 0x99, 0x09, 0xd6, 0x6f, 0xe1, 0xc7, 0xea, 0xb1, 0x47, 0x4f, 0x22, + 0xed, 0xc1, 0xaf, 0x21, 0x99, 0xa4, 0xc5, 0xba, 0xb7, 0xf7, 0xe6, 0xbd, 0x37, 0xbf, 0x3f, 0x33, + 0xb0, 0x2f, 0x28, 0x29, 0xa9, 0x74, 0x49, 0xc9, 0x0b, 0x57, 0x90, 0x94, 0x2e, 0xab, 0x15, 0x75, + 0xd6, 0x25, 0x97, 0x1c, 0x5d, 0x37, 0x9a, 0x53, 0x6b, 0xfd, 0x5b, 0xc6, 0x19, 0x57, 0xe7, 0x6e, + 0x8d, 0x1a, 0xcb, 0xf0, 0x0f, 0x80, 0x97, 0x51, 0x9b, 0x42, 0x08, 0xea, 0x45, 0x92, 0x53, 0x03, + 0x58, 0xc0, 0xbe, 0x0a, 0x15, 0x46, 0xcf, 0xe1, 0xc5, 0x9a, 0x96, 0x19, 0x5f, 0x1a, 0x8f, 0x2c, + 0x60, 0xeb, 0x61, 0xcb, 0xd0, 0x5b, 0xa8, 0xe7, 0x82, 0x09, 0xa3, 0x63, 0x75, 0xec, 0xeb, 0xfb, + 0x81, 0xf3, 0x4f, 0x29, 0xe7, 0xa3, 0x60, 0x78, 0x43, 0x49, 0x25, 0xa9, 0xcf, 0x0b, 0x59, 0x26, + 0x44, 0x7a, 0xfa, 0xf6, 0xd7, 0x40, 0x0b, 0x55, 0x04, 0x39, 0xf0, 0xd9, 0x2a, 0x11, 0x32, 0xa6, + 0x8d, 0x27, 0x4e, 0x69, 0xc6, 0x52, 0x69, 0xe8, 0xea, 0xfe, 0xa7, 0xb5, 0xd4, 0xa6, 0x27, 0x4a, + 0x40, 0x23, 0xf8, 0xa4, 0xb1, 0x66, 0xbc, 0x88, 0x85, 0x4c, 0x18, 0x35, 0xba, 0x16, 0xb0, 0x7b, + 0xf7, 0x77, 0x67, 0x55, 0xf1, 0xd1, 0x13, 0xd5, 0x96, 0xb0, 0x47, 0xcf, 0xf8, 0xd0, 0x83, 0xe8, + 0x61, 0x5f, 0xa8, 0x0f, 0x2f, 0x49, 0x8b, 0xdb, 0xb1, 0x4f, 0x1c, 0xdd, 0xc0, 0x4e, 0x2e, 0x98, + 0x9a, 0xfb, 0x2a, 0xac, 0xe1, 0xf0, 0x15, 0x7c, 0x7c, 0x5c, 0x96, 0xcf, 0xab, 0x42, 0xa2, 0x5b, + 0xd8, 0x25, 0x35, 0x50, 0xd9, 0x6e, 0xd8, 0x90, 0xd7, 0x73, 0xd8, 0x3b, 0x6f, 0x06, 0x0d, 0xe0, + 0x1d, 0xfe, 0x8c, 0xfd, 0x4f, 0xf3, 0xe9, 0x2c, 0x88, 0xa3, 0xf9, 0xbb, 0x31, 0x8e, 0x71, 0x30, + 0x8a, 0xbd, 0x0f, 0x33, 0xff, 0x3d, 0x0e, 0x6f, 0x34, 0xf4, 0x12, 0xbe, 0xf8, 0xdf, 0xe0, 0xe1, + 0xf1, 0x34, 0x38, 0x59, 0x80, 0x37, 0xd9, 0xee, 0x4d, 0xb0, 0xdb, 0x9b, 0xe0, 0xf7, 0xde, 0x04, + 0x3f, 0x0e, 0xa6, 0xb6, 0x3b, 0x98, 0xda, 0xcf, 0x83, 0xa9, 0x7d, 0x71, 0x58, 0x26, 0xd3, 0x6a, + 0xe1, 0x10, 0x9e, 0xbb, 0x82, 0x94, 0x72, 0x95, 0x2c, 0x84, 0x1b, 0xa9, 0xd5, 0x04, 0x54, 0x7e, + 0xe3, 0xe5, 0x57, 0x77, 0xd3, 0x7c, 0x10, 0xf9, 0x7d, 0x4d, 0xc5, 0xe2, 0x42, 0xbd, 0xfd, 0x9b, + 0xbf, 0x01, 0x00, 0x00, 0xff, 0xff, 0x69, 0xe1, 0x6f, 0x81, 0x3c, 0x02, 0x00, 0x00, +} + +func (m *Schedule) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *Schedule) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Schedule) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.ExecutionStage != 0 { + i = encodeVarintSchedule(dAtA, i, uint64(m.ExecutionStage)) + i-- + dAtA[i] = 0x28 + } + if m.LastExecuteHeight != 0 { + i = encodeVarintSchedule(dAtA, i, uint64(m.LastExecuteHeight)) + i-- + dAtA[i] = 0x20 + } + if len(m.Msgs) > 0 { + for iNdEx := len(m.Msgs) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Msgs[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintSchedule(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + } + } + if m.Period != 0 { + i = encodeVarintSchedule(dAtA, i, uint64(m.Period)) + i-- + dAtA[i] = 0x10 + } + if len(m.Name) > 0 { + i -= len(m.Name) + copy(dAtA[i:], m.Name) + i = encodeVarintSchedule(dAtA, i, uint64(len(m.Name))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgExecuteContract) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgExecuteContract) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgExecuteContract) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Msg) > 0 { + i -= len(m.Msg) + copy(dAtA[i:], m.Msg) + i = encodeVarintSchedule(dAtA, i, uint64(len(m.Msg))) + i-- + dAtA[i] = 0x12 + } + if len(m.Contract) > 0 { + i -= len(m.Contract) + copy(dAtA[i:], m.Contract) + i = encodeVarintSchedule(dAtA, i, uint64(len(m.Contract))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *ScheduleCount) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *ScheduleCount) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *ScheduleCount) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Count != 0 { + i = encodeVarintSchedule(dAtA, i, uint64(m.Count)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func encodeVarintSchedule(dAtA []byte, offset int, v uint64) int { + offset -= sovSchedule(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *Schedule) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Name) + if l > 0 { + n += 1 + l + sovSchedule(uint64(l)) + } + if m.Period != 0 { + n += 1 + sovSchedule(uint64(m.Period)) + } + if len(m.Msgs) > 0 { + for _, e := range m.Msgs { + l = e.Size() + n += 1 + l + sovSchedule(uint64(l)) + } + } + if m.LastExecuteHeight != 0 { + n += 1 + sovSchedule(uint64(m.LastExecuteHeight)) + } + if m.ExecutionStage != 0 { + n += 1 + sovSchedule(uint64(m.ExecutionStage)) + } + return n +} + +func (m *MsgExecuteContract) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Contract) + if l > 0 { + n += 1 + l + sovSchedule(uint64(l)) + } + l = len(m.Msg) + if l > 0 { + n += 1 + l + sovSchedule(uint64(l)) + } + return n +} + +func (m *ScheduleCount) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Count != 0 { + n += 1 + sovSchedule(uint64(m.Count)) + } + return n +} + +func sovSchedule(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozSchedule(x uint64) (n int) { + return sovSchedule(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *Schedule) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowSchedule + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: Schedule: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Schedule: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Name", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowSchedule + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthSchedule + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthSchedule + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Name = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Period", wireType) + } + m.Period = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowSchedule + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Period |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Msgs", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowSchedule + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthSchedule + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthSchedule + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Msgs = append(m.Msgs, MsgExecuteContract{}) + if err := m.Msgs[len(m.Msgs)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 4: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field LastExecuteHeight", wireType) + } + m.LastExecuteHeight = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowSchedule + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.LastExecuteHeight |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 5: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field ExecutionStage", wireType) + } + m.ExecutionStage = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowSchedule + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.ExecutionStage |= ExecutionStage(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipSchedule(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthSchedule + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgExecuteContract) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowSchedule + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgExecuteContract: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgExecuteContract: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Contract", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowSchedule + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthSchedule + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthSchedule + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Contract = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Msg", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowSchedule + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthSchedule + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthSchedule + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Msg = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipSchedule(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthSchedule + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *ScheduleCount) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowSchedule + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: ScheduleCount: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: ScheduleCount: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Count", wireType) + } + m.Count = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowSchedule + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Count |= int32(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipSchedule(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthSchedule + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipSchedule(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowSchedule + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowSchedule + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowSchedule + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthSchedule + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupSchedule + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthSchedule + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthSchedule = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowSchedule = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupSchedule = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/cron/types/tx.go b/x/cron/types/tx.go new file mode 100644 index 000000000..27b4ceec4 --- /dev/null +++ b/x/cron/types/tx.go @@ -0,0 +1,125 @@ +package types + +import ( + "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" +) + +var _ sdk.Msg = &MsgAddSchedule{} + +func (msg *MsgAddSchedule) Route() string { + return RouterKey +} + +func (msg *MsgAddSchedule) Type() string { + return "add-schedule" +} + +func (msg *MsgAddSchedule) GetSigners() []sdk.AccAddress { + authority, err := sdk.AccAddressFromBech32(msg.Authority) + if err != nil { // should never happen as valid basic rejects invalid addresses + panic(err.Error()) + } + return []sdk.AccAddress{authority} +} + +func (msg *MsgAddSchedule) GetSignBytes() []byte { + return ModuleCdc.MustMarshalJSON(msg) +} + +func (msg *MsgAddSchedule) Validate() error { + if _, err := sdk.AccAddressFromBech32(msg.Authority); err != nil { + return errors.Wrap(err, "authority is invalid") + } + + if msg.Name == "" { + return errors.Wrap(sdkerrors.ErrInvalidRequest, "name is invalid") + } + + if msg.Period == 0 { + return errors.Wrap(sdkerrors.ErrInvalidRequest, "period is invalid") + } + + if len(msg.Msgs) == 0 { + return errors.Wrap(sdkerrors.ErrInvalidRequest, "msgs should not be empty") + } + + if _, ok := ExecutionStage_name[int32(msg.ExecutionStage)]; !ok { + return errors.Wrap(sdkerrors.ErrInvalidRequest, "execution stage is invalid") + } + + return nil +} + +//---------------------------------------------------------------- + +var _ sdk.Msg = &MsgRemoveSchedule{} + +func (msg *MsgRemoveSchedule) Route() string { + return RouterKey +} + +func (msg *MsgRemoveSchedule) Type() string { + return "remove-schedule" +} + +func (msg *MsgRemoveSchedule) GetSigners() []sdk.AccAddress { + authority, err := sdk.AccAddressFromBech32(msg.Authority) + if err != nil { // should never happen as valid basic rejects invalid addresses + panic(err.Error()) + } + return []sdk.AccAddress{authority} +} + +func (msg *MsgRemoveSchedule) GetSignBytes() []byte { + return ModuleCdc.MustMarshalJSON(msg) +} + +func (msg *MsgRemoveSchedule) Validate() error { + if _, err := sdk.AccAddressFromBech32(msg.Authority); err != nil { + return errors.Wrap(err, "authority is invalid") + } + + if msg.Name == "" { + return errors.Wrap(sdkerrors.ErrInvalidRequest, "name is invalid") + } + + return nil +} + +//---------------------------------------------------------------- + +var _ sdk.Msg = &MsgUpdateParams{} + +func (msg *MsgUpdateParams) Route() string { + return RouterKey +} + +func (msg *MsgUpdateParams) Type() string { + return "update-params" +} + +func (msg *MsgUpdateParams) GetSigners() []sdk.AccAddress { + authority, err := sdk.AccAddressFromBech32(msg.Authority) + if err != nil { // should never happen as valid basic rejects invalid addresses + panic(err.Error()) + } + return []sdk.AccAddress{authority} +} + +func (msg *MsgUpdateParams) GetSignBytes() []byte { + return ModuleCdc.MustMarshalJSON(msg) +} + +func (msg *MsgUpdateParams) Validate() error { + if _, err := sdk.AccAddressFromBech32(msg.Authority); err != nil { + return errors.Wrap(err, "authority is invalid") + } + + if _, err := sdk.AccAddressFromBech32(msg.Params.SecurityAddress); err != nil { + return errors.Wrap(err, "security_address is invalid") + } + + return nil +} diff --git a/x/cron/types/tx.pb.go b/x/cron/types/tx.pb.go new file mode 100644 index 000000000..1b502c253 --- /dev/null +++ b/x/cron/types/tx.pb.go @@ -0,0 +1,1512 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: secret/cron/tx.proto + +package types + +import ( + context "context" + fmt "fmt" + _ "github.com/cosmos/cosmos-proto" + _ "github.com/cosmos/cosmos-sdk/types/msgservice" + _ "github.com/cosmos/cosmos-sdk/types/tx/amino" + _ "github.com/cosmos/gogoproto/gogoproto" + grpc1 "github.com/cosmos/gogoproto/grpc" + proto "github.com/cosmos/gogoproto/proto" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// The MsgAddSchedule request type. +type MsgAddSchedule struct { + // The address of the governance account. + Authority string `protobuf:"bytes,1,opt,name=authority,proto3" json:"authority,omitempty"` + // Name of the schedule + Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"` + // Period in blocks + Period uint64 `protobuf:"varint,3,opt,name=period,proto3" json:"period,omitempty"` + // Msgs that will be executed every certain number of blocks, specified in the `period` field + Msgs []MsgExecuteContract `protobuf:"bytes,4,rep,name=msgs,proto3" json:"msgs"` + // Stage when messages will be executed + ExecutionStage ExecutionStage `protobuf:"varint,5,opt,name=execution_stage,json=executionStage,proto3,enum=secret.cron.ExecutionStage" json:"execution_stage,omitempty"` +} + +func (m *MsgAddSchedule) Reset() { *m = MsgAddSchedule{} } +func (m *MsgAddSchedule) String() string { return proto.CompactTextString(m) } +func (*MsgAddSchedule) ProtoMessage() {} +func (*MsgAddSchedule) Descriptor() ([]byte, []int) { + return fileDescriptor_dc5dfbc481f4f7b1, []int{0} +} +func (m *MsgAddSchedule) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgAddSchedule) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgAddSchedule.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgAddSchedule) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgAddSchedule.Merge(m, src) +} +func (m *MsgAddSchedule) XXX_Size() int { + return m.Size() +} +func (m *MsgAddSchedule) XXX_DiscardUnknown() { + xxx_messageInfo_MsgAddSchedule.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgAddSchedule proto.InternalMessageInfo + +func (m *MsgAddSchedule) GetAuthority() string { + if m != nil { + return m.Authority + } + return "" +} + +func (m *MsgAddSchedule) GetName() string { + if m != nil { + return m.Name + } + return "" +} + +func (m *MsgAddSchedule) GetPeriod() uint64 { + if m != nil { + return m.Period + } + return 0 +} + +func (m *MsgAddSchedule) GetMsgs() []MsgExecuteContract { + if m != nil { + return m.Msgs + } + return nil +} + +func (m *MsgAddSchedule) GetExecutionStage() ExecutionStage { + if m != nil { + return m.ExecutionStage + } + return ExecutionStage_EXECUTION_STAGE_END_BLOCKER +} + +// Defines the response structure for executing a MsgAddSchedule message. +type MsgAddScheduleResponse struct { +} + +func (m *MsgAddScheduleResponse) Reset() { *m = MsgAddScheduleResponse{} } +func (m *MsgAddScheduleResponse) String() string { return proto.CompactTextString(m) } +func (*MsgAddScheduleResponse) ProtoMessage() {} +func (*MsgAddScheduleResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_dc5dfbc481f4f7b1, []int{1} +} +func (m *MsgAddScheduleResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgAddScheduleResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgAddScheduleResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgAddScheduleResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgAddScheduleResponse.Merge(m, src) +} +func (m *MsgAddScheduleResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgAddScheduleResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgAddScheduleResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgAddScheduleResponse proto.InternalMessageInfo + +// The MsgRemoveSchedule request type. +type MsgRemoveSchedule struct { + // The address of the governance account. + Authority string `protobuf:"bytes,1,opt,name=authority,proto3" json:"authority,omitempty"` + // Name of the schedule + Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"` +} + +func (m *MsgRemoveSchedule) Reset() { *m = MsgRemoveSchedule{} } +func (m *MsgRemoveSchedule) String() string { return proto.CompactTextString(m) } +func (*MsgRemoveSchedule) ProtoMessage() {} +func (*MsgRemoveSchedule) Descriptor() ([]byte, []int) { + return fileDescriptor_dc5dfbc481f4f7b1, []int{2} +} +func (m *MsgRemoveSchedule) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgRemoveSchedule) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgRemoveSchedule.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgRemoveSchedule) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgRemoveSchedule.Merge(m, src) +} +func (m *MsgRemoveSchedule) XXX_Size() int { + return m.Size() +} +func (m *MsgRemoveSchedule) XXX_DiscardUnknown() { + xxx_messageInfo_MsgRemoveSchedule.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgRemoveSchedule proto.InternalMessageInfo + +func (m *MsgRemoveSchedule) GetAuthority() string { + if m != nil { + return m.Authority + } + return "" +} + +func (m *MsgRemoveSchedule) GetName() string { + if m != nil { + return m.Name + } + return "" +} + +// Defines the response structure for executing a MsgRemoveSchedule message. +type MsgRemoveScheduleResponse struct { +} + +func (m *MsgRemoveScheduleResponse) Reset() { *m = MsgRemoveScheduleResponse{} } +func (m *MsgRemoveScheduleResponse) String() string { return proto.CompactTextString(m) } +func (*MsgRemoveScheduleResponse) ProtoMessage() {} +func (*MsgRemoveScheduleResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_dc5dfbc481f4f7b1, []int{3} +} +func (m *MsgRemoveScheduleResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgRemoveScheduleResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgRemoveScheduleResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgRemoveScheduleResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgRemoveScheduleResponse.Merge(m, src) +} +func (m *MsgRemoveScheduleResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgRemoveScheduleResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgRemoveScheduleResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgRemoveScheduleResponse proto.InternalMessageInfo + +// The MsgUpdateParams request type. +// +// Since: 0.47 +type MsgUpdateParams struct { + // The address of the governance account. + Authority string `protobuf:"bytes,1,opt,name=authority,proto3" json:"authority,omitempty"` + // Defines the x/cron parameters to update. + // + // NOTE: All parameters must be supplied. + Params Params `protobuf:"bytes,2,opt,name=params,proto3" json:"params"` +} + +func (m *MsgUpdateParams) Reset() { *m = MsgUpdateParams{} } +func (m *MsgUpdateParams) String() string { return proto.CompactTextString(m) } +func (*MsgUpdateParams) ProtoMessage() {} +func (*MsgUpdateParams) Descriptor() ([]byte, []int) { + return fileDescriptor_dc5dfbc481f4f7b1, []int{4} +} +func (m *MsgUpdateParams) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgUpdateParams) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgUpdateParams.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgUpdateParams) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgUpdateParams.Merge(m, src) +} +func (m *MsgUpdateParams) XXX_Size() int { + return m.Size() +} +func (m *MsgUpdateParams) XXX_DiscardUnknown() { + xxx_messageInfo_MsgUpdateParams.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgUpdateParams proto.InternalMessageInfo + +func (m *MsgUpdateParams) GetAuthority() string { + if m != nil { + return m.Authority + } + return "" +} + +func (m *MsgUpdateParams) GetParams() Params { + if m != nil { + return m.Params + } + return Params{} +} + +// Defines the response structure for executing a MsgUpdateParams message. +// +// Since: 0.47 +type MsgUpdateParamsResponse struct { +} + +func (m *MsgUpdateParamsResponse) Reset() { *m = MsgUpdateParamsResponse{} } +func (m *MsgUpdateParamsResponse) String() string { return proto.CompactTextString(m) } +func (*MsgUpdateParamsResponse) ProtoMessage() {} +func (*MsgUpdateParamsResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_dc5dfbc481f4f7b1, []int{5} +} +func (m *MsgUpdateParamsResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgUpdateParamsResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgUpdateParamsResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgUpdateParamsResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgUpdateParamsResponse.Merge(m, src) +} +func (m *MsgUpdateParamsResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgUpdateParamsResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgUpdateParamsResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgUpdateParamsResponse proto.InternalMessageInfo + +func init() { + proto.RegisterType((*MsgAddSchedule)(nil), "secret.cron.MsgAddSchedule") + proto.RegisterType((*MsgAddScheduleResponse)(nil), "secret.cron.MsgAddScheduleResponse") + proto.RegisterType((*MsgRemoveSchedule)(nil), "secret.cron.MsgRemoveSchedule") + proto.RegisterType((*MsgRemoveScheduleResponse)(nil), "secret.cron.MsgRemoveScheduleResponse") + proto.RegisterType((*MsgUpdateParams)(nil), "secret.cron.MsgUpdateParams") + proto.RegisterType((*MsgUpdateParamsResponse)(nil), "secret.cron.MsgUpdateParamsResponse") +} + +func init() { proto.RegisterFile("secret/cron/tx.proto", fileDescriptor_dc5dfbc481f4f7b1) } + +var fileDescriptor_dc5dfbc481f4f7b1 = []byte{ + // 561 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x94, 0x41, 0x8b, 0xd3, 0x40, + 0x14, 0xc7, 0x9b, 0x6d, 0xb7, 0xd0, 0xa9, 0x74, 0xd9, 0x6c, 0xe9, 0xa6, 0xa9, 0x64, 0x4b, 0x95, + 0xb5, 0x16, 0x4c, 0xb0, 0xc2, 0x82, 0xbd, 0x6d, 0x75, 0xc1, 0x4b, 0x55, 0x52, 0x04, 0xf1, 0xb2, + 0xa4, 0xc9, 0x30, 0x0d, 0x6e, 0x32, 0x61, 0xde, 0x74, 0xed, 0xde, 0xc4, 0xe3, 0x7a, 0xf1, 0x0b, + 0x78, 0x17, 0x4f, 0x3d, 0xf8, 0x21, 0xf6, 0xb8, 0x78, 0xf2, 0x24, 0xd2, 0x1e, 0xfa, 0x35, 0x24, + 0x93, 0x64, 0x37, 0x69, 0xa1, 0x07, 0xc1, 0x4b, 0x32, 0xef, 0xfd, 0xde, 0x7b, 0xf3, 0x9f, 0x37, + 0x8f, 0x41, 0x55, 0xc0, 0x36, 0xc3, 0xdc, 0xb0, 0x19, 0xf5, 0x0d, 0x3e, 0xd5, 0x03, 0x46, 0x39, + 0x95, 0xcb, 0x91, 0x57, 0x0f, 0xbd, 0xea, 0xae, 0xe5, 0xb9, 0x3e, 0x35, 0xc4, 0x37, 0xe2, 0xea, + 0xbe, 0x4d, 0xc1, 0xa3, 0x60, 0x78, 0x40, 0x8c, 0xf3, 0xc7, 0xe1, 0x2f, 0x06, 0xf5, 0x08, 0x9c, + 0x0a, 0xcb, 0x88, 0x8c, 0x18, 0x55, 0x09, 0x25, 0x34, 0xf2, 0x87, 0xab, 0xd8, 0xab, 0xa4, 0xf7, + 0x0f, 0x2c, 0x66, 0x79, 0x49, 0xbc, 0x9a, 0x26, 0x60, 0x8f, 0xb1, 0x33, 0x39, 0xc3, 0x11, 0x6b, + 0x7d, 0xdd, 0x42, 0x95, 0x01, 0x90, 0x63, 0xc7, 0x19, 0xc6, 0x40, 0x3e, 0x42, 0x25, 0x6b, 0xc2, + 0xc7, 0x94, 0xb9, 0xfc, 0x42, 0x91, 0x9a, 0x52, 0xbb, 0xd4, 0x57, 0x7e, 0xfe, 0x78, 0x54, 0x8d, + 0x35, 0x1c, 0x3b, 0x0e, 0xc3, 0x00, 0x43, 0xce, 0x5c, 0x9f, 0x98, 0xb7, 0xa1, 0xb2, 0x8c, 0x0a, + 0xbe, 0xe5, 0x61, 0x65, 0x2b, 0x4c, 0x31, 0xc5, 0x5a, 0xae, 0xa1, 0x62, 0x80, 0x99, 0x4b, 0x1d, + 0x25, 0xdf, 0x94, 0xda, 0x05, 0x33, 0xb6, 0xe4, 0xa7, 0xa8, 0xe0, 0x01, 0x01, 0xa5, 0xd0, 0xcc, + 0xb7, 0xcb, 0xdd, 0x03, 0x3d, 0xd5, 0x25, 0x7d, 0x00, 0xe4, 0x64, 0x8a, 0xed, 0x09, 0xc7, 0xcf, + 0xa8, 0xcf, 0x99, 0x65, 0xf3, 0x7e, 0xe1, 0xea, 0xf7, 0x41, 0xce, 0x14, 0x29, 0xf2, 0x73, 0xb4, + 0x83, 0x05, 0x76, 0xa9, 0x7f, 0x0a, 0xdc, 0x22, 0x58, 0xd9, 0x6e, 0x4a, 0xed, 0x4a, 0xb7, 0x91, + 0xa9, 0x72, 0x92, 0xc4, 0x0c, 0xc3, 0x10, 0xb3, 0x82, 0x33, 0x76, 0xef, 0xf0, 0xd3, 0x72, 0xd6, + 0xb9, 0x15, 0x7f, 0xb9, 0x9c, 0x75, 0xf6, 0x44, 0x7f, 0xb2, 0xcd, 0x68, 0x29, 0xa8, 0x96, 0xf5, + 0x98, 0x18, 0x02, 0xea, 0x03, 0x6e, 0x5d, 0x4a, 0x68, 0x77, 0x00, 0xc4, 0xc4, 0x1e, 0x3d, 0xc7, + 0xff, 0xa3, 0x79, 0xbd, 0x87, 0xeb, 0x1a, 0x6b, 0x89, 0xc6, 0xec, 0xb6, 0xad, 0x06, 0xaa, 0xaf, + 0x39, 0x6f, 0x94, 0x7e, 0x97, 0xd0, 0xce, 0x00, 0xc8, 0x9b, 0xc0, 0xb1, 0x38, 0x7e, 0x2d, 0x26, + 0xe3, 0x9f, 0x75, 0x1e, 0xa1, 0x62, 0x34, 0x5b, 0x42, 0x69, 0xb9, 0xbb, 0x97, 0x69, 0x7a, 0x54, + 0xbc, 0x5f, 0x0a, 0xaf, 0xeb, 0xdb, 0x72, 0xd6, 0x91, 0xcc, 0x38, 0xba, 0xf7, 0x60, 0xfd, 0x2c, + 0xd5, 0xe4, 0x2c, 0x69, 0x61, 0xad, 0x3a, 0xda, 0x5f, 0x71, 0x25, 0xe7, 0xe8, 0x7e, 0xde, 0x42, + 0xf9, 0x01, 0x10, 0xf9, 0x15, 0x2a, 0xa7, 0xe7, 0xb5, 0xb1, 0x3a, 0x3d, 0x29, 0xa8, 0xde, 0xdb, + 0x00, 0x93, 0xc2, 0xf2, 0x5b, 0x54, 0x59, 0xb9, 0x46, 0x6d, 0x35, 0x2d, 0xcb, 0xd5, 0xc3, 0xcd, + 0xfc, 0xa6, 0xb2, 0x89, 0xee, 0x64, 0xda, 0x7e, 0x77, 0x35, 0x2f, 0x4d, 0xd5, 0xfb, 0x9b, 0x68, + 0x52, 0x53, 0xdd, 0xfe, 0x18, 0x76, 0xb6, 0xff, 0xe2, 0x6a, 0xae, 0x49, 0xd7, 0x73, 0x4d, 0xfa, + 0x33, 0xd7, 0xa4, 0x2f, 0x0b, 0x2d, 0x77, 0xbd, 0xd0, 0x72, 0xbf, 0x16, 0x5a, 0xee, 0x9d, 0x4e, + 0x5c, 0x3e, 0x9e, 0x8c, 0x74, 0x9b, 0x7a, 0x06, 0xd8, 0x8c, 0x9f, 0x59, 0x23, 0x30, 0x86, 0xa2, + 0xf2, 0x4b, 0xcc, 0x3f, 0x50, 0xf6, 0xde, 0x98, 0xc6, 0xcf, 0xd4, 0x45, 0x80, 0x61, 0x54, 0x14, + 0x4f, 0xc1, 0x93, 0xbf, 0x01, 0x00, 0x00, 0xff, 0xff, 0x28, 0x09, 0xad, 0x41, 0xc2, 0x04, 0x00, + 0x00, +} + +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConn + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion4 + +// MsgClient is the client API for Msg service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type MsgClient interface { + // Adds new schedule. + AddSchedule(ctx context.Context, in *MsgAddSchedule, opts ...grpc.CallOption) (*MsgAddScheduleResponse, error) + // Removes schedule. + RemoveSchedule(ctx context.Context, in *MsgRemoveSchedule, opts ...grpc.CallOption) (*MsgRemoveScheduleResponse, error) + // Updates the module parameters. + UpdateParams(ctx context.Context, in *MsgUpdateParams, opts ...grpc.CallOption) (*MsgUpdateParamsResponse, error) +} + +type msgClient struct { + cc grpc1.ClientConn +} + +func NewMsgClient(cc grpc1.ClientConn) MsgClient { + return &msgClient{cc} +} + +func (c *msgClient) AddSchedule(ctx context.Context, in *MsgAddSchedule, opts ...grpc.CallOption) (*MsgAddScheduleResponse, error) { + out := new(MsgAddScheduleResponse) + err := c.cc.Invoke(ctx, "/secret.cron.Msg/AddSchedule", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *msgClient) RemoveSchedule(ctx context.Context, in *MsgRemoveSchedule, opts ...grpc.CallOption) (*MsgRemoveScheduleResponse, error) { + out := new(MsgRemoveScheduleResponse) + err := c.cc.Invoke(ctx, "/secret.cron.Msg/RemoveSchedule", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *msgClient) UpdateParams(ctx context.Context, in *MsgUpdateParams, opts ...grpc.CallOption) (*MsgUpdateParamsResponse, error) { + out := new(MsgUpdateParamsResponse) + err := c.cc.Invoke(ctx, "/secret.cron.Msg/UpdateParams", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// MsgServer is the server API for Msg service. +type MsgServer interface { + // Adds new schedule. + AddSchedule(context.Context, *MsgAddSchedule) (*MsgAddScheduleResponse, error) + // Removes schedule. + RemoveSchedule(context.Context, *MsgRemoveSchedule) (*MsgRemoveScheduleResponse, error) + // Updates the module parameters. + UpdateParams(context.Context, *MsgUpdateParams) (*MsgUpdateParamsResponse, error) +} + +// UnimplementedMsgServer can be embedded to have forward compatible implementations. +type UnimplementedMsgServer struct { +} + +func (*UnimplementedMsgServer) AddSchedule(ctx context.Context, req *MsgAddSchedule) (*MsgAddScheduleResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method AddSchedule not implemented") +} +func (*UnimplementedMsgServer) RemoveSchedule(ctx context.Context, req *MsgRemoveSchedule) (*MsgRemoveScheduleResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method RemoveSchedule not implemented") +} +func (*UnimplementedMsgServer) UpdateParams(ctx context.Context, req *MsgUpdateParams) (*MsgUpdateParamsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method UpdateParams not implemented") +} + +func RegisterMsgServer(s grpc1.Server, srv MsgServer) { + s.RegisterService(&_Msg_serviceDesc, srv) +} + +func _Msg_AddSchedule_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgAddSchedule) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).AddSchedule(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/secret.cron.Msg/AddSchedule", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).AddSchedule(ctx, req.(*MsgAddSchedule)) + } + return interceptor(ctx, in, info, handler) +} + +func _Msg_RemoveSchedule_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgRemoveSchedule) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).RemoveSchedule(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/secret.cron.Msg/RemoveSchedule", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).RemoveSchedule(ctx, req.(*MsgRemoveSchedule)) + } + return interceptor(ctx, in, info, handler) +} + +func _Msg_UpdateParams_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgUpdateParams) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).UpdateParams(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/secret.cron.Msg/UpdateParams", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).UpdateParams(ctx, req.(*MsgUpdateParams)) + } + return interceptor(ctx, in, info, handler) +} + +var _Msg_serviceDesc = grpc.ServiceDesc{ + ServiceName: "secret.cron.Msg", + HandlerType: (*MsgServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "AddSchedule", + Handler: _Msg_AddSchedule_Handler, + }, + { + MethodName: "RemoveSchedule", + Handler: _Msg_RemoveSchedule_Handler, + }, + { + MethodName: "UpdateParams", + Handler: _Msg_UpdateParams_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "secret/cron/tx.proto", +} + +func (m *MsgAddSchedule) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgAddSchedule) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgAddSchedule) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.ExecutionStage != 0 { + i = encodeVarintTx(dAtA, i, uint64(m.ExecutionStage)) + i-- + dAtA[i] = 0x28 + } + if len(m.Msgs) > 0 { + for iNdEx := len(m.Msgs) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Msgs[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x22 + } + } + if m.Period != 0 { + i = encodeVarintTx(dAtA, i, uint64(m.Period)) + i-- + dAtA[i] = 0x18 + } + if len(m.Name) > 0 { + i -= len(m.Name) + copy(dAtA[i:], m.Name) + i = encodeVarintTx(dAtA, i, uint64(len(m.Name))) + i-- + dAtA[i] = 0x12 + } + if len(m.Authority) > 0 { + i -= len(m.Authority) + copy(dAtA[i:], m.Authority) + i = encodeVarintTx(dAtA, i, uint64(len(m.Authority))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgAddScheduleResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgAddScheduleResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgAddScheduleResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func (m *MsgRemoveSchedule) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgRemoveSchedule) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgRemoveSchedule) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Name) > 0 { + i -= len(m.Name) + copy(dAtA[i:], m.Name) + i = encodeVarintTx(dAtA, i, uint64(len(m.Name))) + i-- + dAtA[i] = 0x12 + } + if len(m.Authority) > 0 { + i -= len(m.Authority) + copy(dAtA[i:], m.Authority) + i = encodeVarintTx(dAtA, i, uint64(len(m.Authority))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgRemoveScheduleResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgRemoveScheduleResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgRemoveScheduleResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func (m *MsgUpdateParams) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgUpdateParams) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgUpdateParams) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.Params.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + if len(m.Authority) > 0 { + i -= len(m.Authority) + copy(dAtA[i:], m.Authority) + i = encodeVarintTx(dAtA, i, uint64(len(m.Authority))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgUpdateParamsResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgUpdateParamsResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgUpdateParamsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func encodeVarintTx(dAtA []byte, offset int, v uint64) int { + offset -= sovTx(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *MsgAddSchedule) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Authority) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.Name) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + if m.Period != 0 { + n += 1 + sovTx(uint64(m.Period)) + } + if len(m.Msgs) > 0 { + for _, e := range m.Msgs { + l = e.Size() + n += 1 + l + sovTx(uint64(l)) + } + } + if m.ExecutionStage != 0 { + n += 1 + sovTx(uint64(m.ExecutionStage)) + } + return n +} + +func (m *MsgAddScheduleResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func (m *MsgRemoveSchedule) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Authority) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.Name) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + return n +} + +func (m *MsgRemoveScheduleResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func (m *MsgUpdateParams) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Authority) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = m.Params.Size() + n += 1 + l + sovTx(uint64(l)) + return n +} + +func (m *MsgUpdateParamsResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func sovTx(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozTx(x uint64) (n int) { + return sovTx(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *MsgAddSchedule) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgAddSchedule: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgAddSchedule: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Authority", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Authority = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Name", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Name = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Period", wireType) + } + m.Period = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Period |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Msgs", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Msgs = append(m.Msgs, MsgExecuteContract{}) + if err := m.Msgs[len(m.Msgs)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 5: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field ExecutionStage", wireType) + } + m.ExecutionStage = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.ExecutionStage |= ExecutionStage(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgAddScheduleResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgAddScheduleResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgAddScheduleResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgRemoveSchedule) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgRemoveSchedule: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgRemoveSchedule: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Authority", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Authority = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Name", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Name = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgRemoveScheduleResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgRemoveScheduleResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgRemoveScheduleResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgUpdateParams) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgUpdateParams: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgUpdateParams: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Authority", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Authority = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Params", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Params.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgUpdateParamsResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgUpdateParamsResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgUpdateParamsResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipTx(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowTx + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowTx + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowTx + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthTx + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupTx + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthTx + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthTx = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowTx = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupTx = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/cron/types/types.go b/x/cron/types/types.go new file mode 100644 index 000000000..ab1254f4c --- /dev/null +++ b/x/cron/types/types.go @@ -0,0 +1 @@ +package types diff --git a/x/cron/types/v1/schedule.pb.go b/x/cron/types/v1/schedule.pb.go new file mode 100644 index 000000000..db2717010 --- /dev/null +++ b/x/cron/types/v1/schedule.pb.go @@ -0,0 +1,843 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: secret/cron/v1/schedule.proto + +package v1 + +import ( + fmt "fmt" + _ "github.com/cosmos/gogoproto/gogoproto" + proto "github.com/cosmos/gogoproto/proto" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// Defines the schedule for execution +type Schedule struct { + // Name of schedule + Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` + // Period in blocks + Period uint64 `protobuf:"varint,2,opt,name=period,proto3" json:"period,omitempty"` + // Msgs that will be executed every certain number of blocks, specified in the `period` field + Msgs []MsgExecuteContract `protobuf:"bytes,3,rep,name=msgs,proto3" json:"msgs"` + // Last execution's block height + LastExecuteHeight uint64 `protobuf:"varint,4,opt,name=last_execute_height,json=lastExecuteHeight,proto3" json:"last_execute_height,omitempty"` +} + +func (m *Schedule) Reset() { *m = Schedule{} } +func (m *Schedule) String() string { return proto.CompactTextString(m) } +func (*Schedule) ProtoMessage() {} +func (*Schedule) Descriptor() ([]byte, []int) { + return fileDescriptor_e9ea3196663ffe81, []int{0} +} +func (m *Schedule) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Schedule) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Schedule.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *Schedule) XXX_Merge(src proto.Message) { + xxx_messageInfo_Schedule.Merge(m, src) +} +func (m *Schedule) XXX_Size() int { + return m.Size() +} +func (m *Schedule) XXX_DiscardUnknown() { + xxx_messageInfo_Schedule.DiscardUnknown(m) +} + +var xxx_messageInfo_Schedule proto.InternalMessageInfo + +func (m *Schedule) GetName() string { + if m != nil { + return m.Name + } + return "" +} + +func (m *Schedule) GetPeriod() uint64 { + if m != nil { + return m.Period + } + return 0 +} + +func (m *Schedule) GetMsgs() []MsgExecuteContract { + if m != nil { + return m.Msgs + } + return nil +} + +func (m *Schedule) GetLastExecuteHeight() uint64 { + if m != nil { + return m.LastExecuteHeight + } + return 0 +} + +// Defines the contract and the message to pass +type MsgExecuteContract struct { + // The address of the smart contract + Contract string `protobuf:"bytes,1,opt,name=contract,proto3" json:"contract,omitempty"` + // JSON encoded message to be passed to the contract + Msg string `protobuf:"bytes,2,opt,name=msg,proto3" json:"msg,omitempty"` +} + +func (m *MsgExecuteContract) Reset() { *m = MsgExecuteContract{} } +func (m *MsgExecuteContract) String() string { return proto.CompactTextString(m) } +func (*MsgExecuteContract) ProtoMessage() {} +func (*MsgExecuteContract) Descriptor() ([]byte, []int) { + return fileDescriptor_e9ea3196663ffe81, []int{1} +} +func (m *MsgExecuteContract) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgExecuteContract) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgExecuteContract.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgExecuteContract) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgExecuteContract.Merge(m, src) +} +func (m *MsgExecuteContract) XXX_Size() int { + return m.Size() +} +func (m *MsgExecuteContract) XXX_DiscardUnknown() { + xxx_messageInfo_MsgExecuteContract.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgExecuteContract proto.InternalMessageInfo + +func (m *MsgExecuteContract) GetContract() string { + if m != nil { + return m.Contract + } + return "" +} + +func (m *MsgExecuteContract) GetMsg() string { + if m != nil { + return m.Msg + } + return "" +} + +// Defines the number of current schedules +type ScheduleCount struct { + // The number of current schedules + Count int32 `protobuf:"varint,1,opt,name=count,proto3" json:"count,omitempty"` +} + +func (m *ScheduleCount) Reset() { *m = ScheduleCount{} } +func (m *ScheduleCount) String() string { return proto.CompactTextString(m) } +func (*ScheduleCount) ProtoMessage() {} +func (*ScheduleCount) Descriptor() ([]byte, []int) { + return fileDescriptor_e9ea3196663ffe81, []int{2} +} +func (m *ScheduleCount) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *ScheduleCount) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_ScheduleCount.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *ScheduleCount) XXX_Merge(src proto.Message) { + xxx_messageInfo_ScheduleCount.Merge(m, src) +} +func (m *ScheduleCount) XXX_Size() int { + return m.Size() +} +func (m *ScheduleCount) XXX_DiscardUnknown() { + xxx_messageInfo_ScheduleCount.DiscardUnknown(m) +} + +var xxx_messageInfo_ScheduleCount proto.InternalMessageInfo + +func (m *ScheduleCount) GetCount() int32 { + if m != nil { + return m.Count + } + return 0 +} + +func init() { + proto.RegisterType((*Schedule)(nil), "secret.cron.v1.Schedule") + proto.RegisterType((*MsgExecuteContract)(nil), "secret.cron.v1.MsgExecuteContract") + proto.RegisterType((*ScheduleCount)(nil), "secret.cron.v1.ScheduleCount") +} + +func init() { proto.RegisterFile("secret/cron/v1/schedule.proto", fileDescriptor_e9ea3196663ffe81) } + +var fileDescriptor_e9ea3196663ffe81 = []byte{ + // 323 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x64, 0x91, 0xc1, 0x4a, 0x3b, 0x31, + 0x10, 0xc6, 0x37, 0xff, 0x6e, 0x4b, 0x9b, 0x3f, 0x8a, 0xc6, 0x22, 0x4b, 0xc1, 0x58, 0x16, 0x84, + 0x9e, 0x12, 0x56, 0xaf, 0x9e, 0x5a, 0x04, 0x41, 0xf4, 0xb0, 0xbd, 0x79, 0x29, 0xdb, 0x34, 0x64, + 0x8b, 0xdd, 0x4d, 0x49, 0x66, 0x6b, 0x7d, 0x0b, 0x1f, 0xc2, 0x87, 0xe9, 0xb1, 0x47, 0x4f, 0x22, + 0xed, 0x8b, 0xc8, 0x66, 0x57, 0x41, 0xbc, 0x7d, 0x1f, 0xbf, 0xf9, 0x32, 0x33, 0x19, 0x7c, 0x66, + 0xa5, 0x30, 0x12, 0xb8, 0x30, 0x3a, 0xe7, 0xab, 0x88, 0x5b, 0x91, 0xca, 0x59, 0xb1, 0x90, 0x6c, + 0x69, 0x34, 0x68, 0x72, 0x58, 0x61, 0x56, 0x62, 0xb6, 0x8a, 0x7a, 0x5d, 0xa5, 0x95, 0x76, 0x88, + 0x97, 0xaa, 0xaa, 0x0a, 0xdf, 0x10, 0x6e, 0x8f, 0xeb, 0x20, 0x21, 0xd8, 0xcf, 0x93, 0x4c, 0x06, + 0xa8, 0x8f, 0x06, 0x9d, 0xd8, 0x69, 0x72, 0x8a, 0x5b, 0x4b, 0x69, 0xe6, 0x7a, 0x16, 0xfc, 0xeb, + 0xa3, 0x81, 0x1f, 0xd7, 0x8e, 0x5c, 0x63, 0x3f, 0xb3, 0xca, 0x06, 0x8d, 0x7e, 0x63, 0xf0, 0xff, + 0x32, 0x64, 0xbf, 0xbb, 0xb1, 0x7b, 0xab, 0x6e, 0xd6, 0x52, 0x14, 0x20, 0x47, 0x3a, 0x07, 0x93, + 0x08, 0x18, 0xfa, 0x9b, 0x8f, 0x73, 0x2f, 0x76, 0x29, 0xc2, 0xf0, 0xc9, 0x22, 0xb1, 0x30, 0x91, + 0x55, 0xcd, 0x24, 0x95, 0x73, 0x95, 0x42, 0xe0, 0xbb, 0x16, 0xc7, 0x25, 0xaa, 0xd3, 0xb7, 0x0e, + 0x84, 0x43, 0x4c, 0xfe, 0xbe, 0x48, 0x7a, 0xb8, 0x2d, 0x6a, 0x5d, 0xcf, 0xfc, 0xe3, 0xc9, 0x11, + 0x6e, 0x64, 0x56, 0xb9, 0xa1, 0x3b, 0x71, 0x29, 0xc3, 0x0b, 0x7c, 0xf0, 0xbd, 0xe9, 0x48, 0x17, + 0x39, 0x90, 0x2e, 0x6e, 0x8a, 0x52, 0xb8, 0x6c, 0x33, 0xae, 0xcc, 0xf0, 0x6e, 0xb3, 0xa3, 0x68, + 0xbb, 0xa3, 0xe8, 0x73, 0x47, 0xd1, 0xeb, 0x9e, 0x7a, 0xdb, 0x3d, 0xf5, 0xde, 0xf7, 0xd4, 0x7b, + 0x8c, 0xd4, 0x1c, 0xd2, 0x62, 0xca, 0x84, 0xce, 0xb8, 0x15, 0x06, 0x16, 0xc9, 0xd4, 0xf2, 0xb1, + 0xdb, 0xfb, 0x41, 0xc2, 0xb3, 0x36, 0x4f, 0x7c, 0x5d, 0x5d, 0x03, 0x5e, 0x96, 0xd2, 0xf2, 0x55, + 0x34, 0x6d, 0xb9, 0x5f, 0xbe, 0xfa, 0x0a, 0x00, 0x00, 0xff, 0xff, 0xa7, 0x7e, 0x3b, 0xfa, 0xac, + 0x01, 0x00, 0x00, +} + +func (m *Schedule) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *Schedule) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Schedule) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.LastExecuteHeight != 0 { + i = encodeVarintSchedule(dAtA, i, uint64(m.LastExecuteHeight)) + i-- + dAtA[i] = 0x20 + } + if len(m.Msgs) > 0 { + for iNdEx := len(m.Msgs) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Msgs[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintSchedule(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + } + } + if m.Period != 0 { + i = encodeVarintSchedule(dAtA, i, uint64(m.Period)) + i-- + dAtA[i] = 0x10 + } + if len(m.Name) > 0 { + i -= len(m.Name) + copy(dAtA[i:], m.Name) + i = encodeVarintSchedule(dAtA, i, uint64(len(m.Name))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgExecuteContract) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgExecuteContract) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgExecuteContract) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Msg) > 0 { + i -= len(m.Msg) + copy(dAtA[i:], m.Msg) + i = encodeVarintSchedule(dAtA, i, uint64(len(m.Msg))) + i-- + dAtA[i] = 0x12 + } + if len(m.Contract) > 0 { + i -= len(m.Contract) + copy(dAtA[i:], m.Contract) + i = encodeVarintSchedule(dAtA, i, uint64(len(m.Contract))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *ScheduleCount) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *ScheduleCount) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *ScheduleCount) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Count != 0 { + i = encodeVarintSchedule(dAtA, i, uint64(m.Count)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func encodeVarintSchedule(dAtA []byte, offset int, v uint64) int { + offset -= sovSchedule(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *Schedule) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Name) + if l > 0 { + n += 1 + l + sovSchedule(uint64(l)) + } + if m.Period != 0 { + n += 1 + sovSchedule(uint64(m.Period)) + } + if len(m.Msgs) > 0 { + for _, e := range m.Msgs { + l = e.Size() + n += 1 + l + sovSchedule(uint64(l)) + } + } + if m.LastExecuteHeight != 0 { + n += 1 + sovSchedule(uint64(m.LastExecuteHeight)) + } + return n +} + +func (m *MsgExecuteContract) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Contract) + if l > 0 { + n += 1 + l + sovSchedule(uint64(l)) + } + l = len(m.Msg) + if l > 0 { + n += 1 + l + sovSchedule(uint64(l)) + } + return n +} + +func (m *ScheduleCount) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Count != 0 { + n += 1 + sovSchedule(uint64(m.Count)) + } + return n +} + +func sovSchedule(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozSchedule(x uint64) (n int) { + return sovSchedule(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *Schedule) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowSchedule + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: Schedule: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Schedule: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Name", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowSchedule + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthSchedule + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthSchedule + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Name = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Period", wireType) + } + m.Period = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowSchedule + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Period |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Msgs", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowSchedule + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthSchedule + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthSchedule + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Msgs = append(m.Msgs, MsgExecuteContract{}) + if err := m.Msgs[len(m.Msgs)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 4: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field LastExecuteHeight", wireType) + } + m.LastExecuteHeight = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowSchedule + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.LastExecuteHeight |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipSchedule(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthSchedule + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgExecuteContract) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowSchedule + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgExecuteContract: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgExecuteContract: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Contract", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowSchedule + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthSchedule + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthSchedule + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Contract = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Msg", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowSchedule + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthSchedule + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthSchedule + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Msg = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipSchedule(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthSchedule + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *ScheduleCount) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowSchedule + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: ScheduleCount: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: ScheduleCount: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Count", wireType) + } + m.Count = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowSchedule + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Count |= int32(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipSchedule(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthSchedule + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipSchedule(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowSchedule + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowSchedule + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowSchedule + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthSchedule + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupSchedule + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthSchedule + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthSchedule = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowSchedule = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupSchedule = fmt.Errorf("proto: unexpected end of group") +)