use crate::msg::to_any;
use crate::proto::qorechain::rdk::v1 as pb;
use cosmrs::Any;
pub const CREATE_ROLLUP: &str = "/qorechain.rdk.v1.MsgCreateRollup";
pub const SUBMIT_BATCH: &str = "/qorechain.rdk.v1.MsgSubmitBatch";
pub const CHALLENGE_BATCH: &str = "/qorechain.rdk.v1.MsgChallengeBatch";
pub const RESOLVE_CHALLENGE: &str = "/qorechain.rdk.v1.MsgResolveChallenge";
pub const PAUSE_ROLLUP: &str = "/qorechain.rdk.v1.MsgPauseRollup";
pub const RESUME_ROLLUP: &str = "/qorechain.rdk.v1.MsgResumeRollup";
pub const STOP_ROLLUP: &str = "/qorechain.rdk.v1.MsgStopRollup";
pub fn create_rollup(
creator: impl Into<String>,
rollup_id: impl Into<String>,
profile: impl Into<String>,
vm_type: impl Into<String>,
stake_amount: i64,
) -> pb::MsgCreateRollup {
pb::MsgCreateRollup {
creator: creator.into(),
rollup_id: rollup_id.into(),
profile: profile.into(),
vm_type: vm_type.into(),
stake_amount,
}
}
pub fn create_rollup_any(
creator: impl Into<String>,
rollup_id: impl Into<String>,
profile: impl Into<String>,
vm_type: impl Into<String>,
stake_amount: i64,
) -> Any {
to_any(
&create_rollup(creator, rollup_id, profile, vm_type, stake_amount),
CREATE_ROLLUP,
)
}
#[allow(clippy::too_many_arguments)]
pub fn submit_batch(
sequencer: impl Into<String>,
rollup_id: impl Into<String>,
batch_index: u64,
state_root: Vec<u8>,
prev_state_root: Vec<u8>,
tx_count: u64,
data_hash: Vec<u8>,
proof: Vec<u8>,
) -> pb::MsgSubmitBatch {
pb::MsgSubmitBatch {
sequencer: sequencer.into(),
rollup_id: rollup_id.into(),
batch_index,
state_root,
prev_state_root,
tx_count,
data_hash,
proof,
}
}
#[allow(clippy::too_many_arguments)]
pub fn submit_batch_any(
sequencer: impl Into<String>,
rollup_id: impl Into<String>,
batch_index: u64,
state_root: Vec<u8>,
prev_state_root: Vec<u8>,
tx_count: u64,
data_hash: Vec<u8>,
proof: Vec<u8>,
) -> Any {
to_any(
&submit_batch(
sequencer,
rollup_id,
batch_index,
state_root,
prev_state_root,
tx_count,
data_hash,
proof,
),
SUBMIT_BATCH,
)
}
pub fn challenge_batch(
challenger: impl Into<String>,
rollup_id: impl Into<String>,
batch_index: u64,
proof: Vec<u8>,
) -> pb::MsgChallengeBatch {
pb::MsgChallengeBatch {
challenger: challenger.into(),
rollup_id: rollup_id.into(),
batch_index,
proof,
}
}
pub fn challenge_batch_any(
challenger: impl Into<String>,
rollup_id: impl Into<String>,
batch_index: u64,
proof: Vec<u8>,
) -> Any {
to_any(
&challenge_batch(challenger, rollup_id, batch_index, proof),
CHALLENGE_BATCH,
)
}
pub fn resolve_challenge(
resolver: impl Into<String>,
rollup_id: impl Into<String>,
batch_index: u64,
fraud_upheld: bool,
) -> pb::MsgResolveChallenge {
pb::MsgResolveChallenge {
resolver: resolver.into(),
rollup_id: rollup_id.into(),
batch_index,
fraud_upheld,
}
}
pub fn resolve_challenge_any(
resolver: impl Into<String>,
rollup_id: impl Into<String>,
batch_index: u64,
fraud_upheld: bool,
) -> Any {
to_any(
&resolve_challenge(resolver, rollup_id, batch_index, fraud_upheld),
RESOLVE_CHALLENGE,
)
}
pub fn pause_rollup(
creator: impl Into<String>,
rollup_id: impl Into<String>,
reason: impl Into<String>,
) -> pb::MsgPauseRollup {
pb::MsgPauseRollup {
creator: creator.into(),
rollup_id: rollup_id.into(),
reason: reason.into(),
}
}
pub fn pause_rollup_any(
creator: impl Into<String>,
rollup_id: impl Into<String>,
reason: impl Into<String>,
) -> Any {
to_any(&pause_rollup(creator, rollup_id, reason), PAUSE_ROLLUP)
}
pub fn resume_rollup(
creator: impl Into<String>,
rollup_id: impl Into<String>,
) -> pb::MsgResumeRollup {
pb::MsgResumeRollup {
creator: creator.into(),
rollup_id: rollup_id.into(),
}
}
pub fn resume_rollup_any(creator: impl Into<String>, rollup_id: impl Into<String>) -> Any {
to_any(&resume_rollup(creator, rollup_id), RESUME_ROLLUP)
}
pub fn stop_rollup(creator: impl Into<String>, rollup_id: impl Into<String>) -> pb::MsgStopRollup {
pb::MsgStopRollup {
creator: creator.into(),
rollup_id: rollup_id.into(),
}
}
pub fn stop_rollup_any(creator: impl Into<String>, rollup_id: impl Into<String>) -> Any {
to_any(&stop_rollup(creator, rollup_id), STOP_ROLLUP)
}