Skip to content

Commit

Permalink
wip: migration works?
Browse files Browse the repository at this point in the history
  • Loading branch information
benluelo committed Mar 4, 2025
1 parent be9c09d commit f671031
Show file tree
Hide file tree
Showing 7 changed files with 316 additions and 55 deletions.
2 changes: 1 addition & 1 deletion cosmwasm/cosmwasm.nix
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
ucs03_type = "cw20";
bech32_prefix = "union";
apps = {
ucs03 = ucs03-configs.cw20;
# ucs03 = ucs03-configs.cw20;
};
# lightclients = pkgs.lib.lists.remove "cometbls" (builtins.attrNames all-lightclients);
lightclients = [ ];
Expand Down
104 changes: 93 additions & 11 deletions cosmwasm/deployer/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,16 @@ use cosmos_client::{
};
use cosmwasm_std::Addr;
use hex_literal::hex;
use protos::cosmwasm::wasm::v1::{
AccessConfig, AccessType, MsgExecuteContract, MsgExecuteContractResponse,
MsgInstantiateContract2, MsgInstantiateContract2Response, MsgMigrateContract,
MsgMigrateContractResponse, MsgStoreCode, MsgStoreCodeResponse, MsgUpdateInstantiateConfig,
MsgUpdateInstantiateConfigResponse, QuerySmartContractStateRequest,
QuerySmartContractStateResponse,
use protos::{
cosmos::base::query::v1beta1::PageRequest,
cosmwasm::wasm::v1::{
AccessConfig, AccessType, MsgExecuteContract, MsgExecuteContractResponse,
MsgInstantiateContract2, MsgInstantiateContract2Response, MsgMigrateContract,
MsgMigrateContractResponse, MsgStoreCode, MsgStoreCodeResponse, MsgUpdateInstantiateConfig,
MsgUpdateInstantiateConfigResponse, QueryAllContractStateRequest,
QueryAllContractStateResponse, QuerySmartContractStateRequest,
QuerySmartContractStateResponse,
},
};
use serde::{Deserialize, Serialize};
use serde_json::json;
Expand Down Expand Up @@ -85,6 +89,8 @@ enum App {
#[arg(long)]
bech32_prefix: String,
},
#[command(subcommand)]
Query(QueryCmd),
}

#[derive(Debug, Clone, PartialEq, Default, clap::Args)]
Expand All @@ -103,6 +109,18 @@ enum QueryCmd {
#[arg(long)]
code_id: u64,
},
ContractState {
#[arg(long)]
rpc_url: String,
#[arg(long)]
output: Option<PathBuf>,
#[arg(long)]
address: Bech32<H256>,
#[arg(long)]
all: bool,
#[arg(long, default_value_t = 100)]
per_page: u64,
},
}

#[tokio::main]
Expand Down Expand Up @@ -272,10 +290,7 @@ async fn do_main() -> Result<()> {
MsgStoreCode {
sender: ctx.wallet().address().to_string(),
wasm_byte_code: BYTECODE_BASE_BYTECODE.to_vec(),
instantiate_permission: Some(AccessConfig {
permission: AccessType::Everybody.into(),
addresses: vec![],
}), // ..Default::default()
instantiate_permission: None,
},
"",
)
Expand Down Expand Up @@ -320,7 +335,6 @@ async fn do_main() -> Result<()> {
ucs03: None,
},
};

for (client_type, path) in contracts.lightclient {
let address = ctx
.deploy_and_initiate(
Expand Down Expand Up @@ -667,6 +681,74 @@ async fn do_main() -> Result<()> {
"{}",
CosmosSigner::from_raw(*private_key.get(), bech32_prefix).unwrap(),
),
App::Query(query_cmd) => match query_cmd {
QueryCmd::CodeInfo { rpc_url, code_id } => todo!(),
QueryCmd::ContractState {
rpc_url,
output,
address,
all,
per_page,
} => {
let client = cometbft_rpc::Client::new(rpc_url).await?;

if all {
let mut states = BTreeMap::<Bytes, Bytes>::new();

let mut pagination = PageRequest {
key: vec![],
offset: 0,
limit: per_page,
count_total: false,
reverse: false,
};

loop {
let state = client
.grpc_abci_query::<_, QueryAllContractStateResponse>(
"/cosmwasm.wasm.v1.Query/AllContractState",
&QueryAllContractStateRequest {
address: address.to_string(),
pagination: Some(pagination.clone()),
},
None,
false,
)
.await?
.into_result()?
.context("contract state response missing")?;

let p = state.pagination.unwrap();

info!(
"fetched page {} ({} items)",
<Bytes>::from(pagination.key),
state.models.len()
);

pagination = if p.next_key.is_empty() {
break;
} else {
PageRequest {
key: p.next_key,
..pagination
}
};

states.extend(
state
.models
.into_iter()
.map(|model| (model.key.into(), model.value.into())),
);
}

write_output(output, states)?;
} else {
todo!()
}
}
},
}

Ok(())
Expand Down
4 changes: 2 additions & 2 deletions cosmwasm/ibc-union/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ library = []
[dependencies]
alloy = { workspace = true, features = ["sol-types"] }
cosmwasm-schema = { workspace = true }
cosmwasm-std = { workspace = true, features = ["abort"] }
cw-storage-plus = { workspace = true }
cosmwasm-std = { workspace = true, features = ["abort", "iterator"] }
cw-storage-plus = { workspace = true, features = ["iterator"] }
depolama = { workspace = true }
ethabi = { workspace = true }
hex = { workspace = true }
Expand Down
37 changes: 20 additions & 17 deletions cosmwasm/ibc-union/core/light-client-interface/src/state.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
use cosmwasm_std::{Addr, StdError, StdResult};
use depolama::{Prefix, Store, ValueCodec};
use cw_storage_plus::Item;
// use depolama::{Prefix, Store, ValueCodec};
use unionlabs::primitives::Bytes;

pub enum IbcHost {}
impl Store for IbcHost {
const PREFIX: Prefix = Prefix::new(b"ibc_host");
pub const IBC_HOST: Item<Addr> = Item::new("ibc_host");

type Key = ();
type Value = Addr;
}
// pub enum IbcHost {}
// impl Store for IbcHost {
// const PREFIX: Prefix = Prefix::new(b"ibc_host");

impl ValueCodec<Addr> for IbcHost {
fn encode_value(value: &Addr) -> Bytes {
value.as_bytes().into()
}
// type Key = ();
// type Value = Addr;
// }

fn decode_value(raw: &Bytes) -> StdResult<Addr> {
String::from_utf8(raw.to_vec())
.map(Addr::unchecked)
.map_err(|e| StdError::generic_err(format!("invalid value: {e}")))
}
}
// impl ValueCodec<Addr> for IbcHost {
// fn encode_value(value: &Addr) -> Bytes {
// value.as_bytes().into()
// }

// fn decode_value(raw: &Bytes) -> StdResult<Addr> {
// String::from_utf8(raw.to_vec())
// .map(Addr::unchecked)
// .map_err(|e| StdError::generic_err(format!("invalid value: {e}")))
// }
// }
Loading

0 comments on commit f671031

Please sign in to comment.