Skip to content

Commit

Permalink
feat(ucli): add query commands
Browse files Browse the repository at this point in the history
Signed-off-by: aeryz <abdullaheryz@protonmail.com>
  • Loading branch information
aeryz committed Oct 31, 2023
1 parent 52410c9 commit a24e1a2
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 87 deletions.
27 changes: 27 additions & 0 deletions ucli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ pub struct AppArgs {
pub enum Command {
#[command(subcommand)]
Tx(TxCmd),
#[command(subcommand)]
Query(QueryCmd),
}

#[derive(Debug, Subcommand)]
Expand Down Expand Up @@ -68,6 +70,31 @@ pub enum EvmTx {
},
}

#[derive(Debug, Subcommand)]
pub enum QueryCmd {
#[command(subcommand)]
Evm(EvmQuery),
}

#[derive(Debug, Subcommand)]
pub enum EvmQuery {
// TODO(aeryz): Check if native denoms present in the `denomToAddress` mapping.
UcsBalance {
#[arg(long)]
contract_address: Address,
#[arg(long)]
denom: String,
#[arg(long)]
address: Address,
},
ErcBalance {
#[arg(long)]
contract_address: Address,
#[arg(long)]
address: Address,
},
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(bound(serialize = "", deserialize = ""))]
pub struct Config {
Expand Down
40 changes: 40 additions & 0 deletions ucli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,49 @@ async fn main() {
};
}
},
cli::Command::Query(query) => match query {
cli::QueryCmd::Evm(evm_query) => {
let evm: Evm<EvmConfig> = Evm::new(config.evm).await.unwrap();
match evm_query {
cli::EvmQuery::UcsBalance {
contract_address,
denom,
address,
} => {
handle_ucs_balance(evm, contract_address.into(), denom, address.into())
.await
}
cli::EvmQuery::ErcBalance {
contract_address,
address,
} => todo!(),
}
}
},
}
}

async fn handle_ucs_balance(
evm: Evm<EvmConfig>,
contract_address: Address,
denom: String,
address: Address,
) {
let signer_middleware = Arc::new(SignerMiddleware::new(
evm.provider.clone(),
evm.wallet.clone(),
));
let relay = UCS01Relay::new(contract_address, signer_middleware.clone());

let denom = relay.denom_to_address(denom).await.unwrap();
println!("Address is: {}", denom);

let erc_contract = erc20::ERC20::new(denom, signer_middleware.clone());

let balance = erc_contract.balance_of(address).await.unwrap();
println!("Balance is: {}", balance);
}

async fn handle_transfer(
evm: Evm<EvmConfig>,
relay_address: Address,
Expand Down
49 changes: 49 additions & 0 deletions ucli/ucli-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"evm": {
"ibc_handler_address": "0xeda338e4dc46038493b885327842fd3e301cab39",
"signer":
{
"raw": "0x4e9444a6efd6d42725a250b650a781da2737ea308c839eaccb0f7f3dbd2fea77"
},
"eth_rpc_api": "ws://localhost:8546",
"eth_beacon_rpc_api": "http://localhost:9596"
},
"union": {
"signers": [
{
"raw": "0xaa820fa947beb242032a41b6dc9a8b9c37d8f5fbcda0966b1ec80335b10a7d6f"
},
{
"raw": "0xf562d20f0a4ffd8814d262f7023f33971cbcd14a96d60027585777f174b9cdeb"
},
{
"raw": "0xa1f713e0f36404586085a599a45ca8233e23709e23cd54bc8d5452ef8f7bc1e6"
},
{
"raw": "0xedc165ff1ebc27044ddc284c9cf5da656dcbff324f6ecbb9d3203cf5f4738d6d"
},
{
"raw": "0x40c30853b7f3e6d7ec997fc72c78aef65fce2e82d5b71032a98cb8efaa4710ca"
},
{
"raw": "0xaeff1a3cf6e96d1551c95677fff8399b1ee0c3ed2f610928520897202e5ae690"
},
{
"raw": "0x007c467d778a10ca5975f306c23fbb3e904b6d26cb1eefe861a2b21771e56608"
},
{
"raw": "0xd015be9181c7a575c701552fd8c1ba22ae6b8528d0f15db42062e387c77e529f"
},
{
"raw": "0xc85dc3662b72c79d0d484b4599dd8389a08b157b997682455dcb746066eab3b0"
},
{
"raw": "0xc14641f65d26bb81202fdf6c9b36584ccca64a52f47b236117a9ece5b920013c"
}
],
"fee_denom": "stake",
"ws_url": "ws://localhost:26657/websocket",
"prover_endpoint": "https://galois-devnet.cryptware.io:443",
"grpc_url": "http://localhost:9090"
}
}
3 changes: 2 additions & 1 deletion voyager-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@
"hasura": null,
"num_workers": 10,
"queue": {
"type": "in-memory"
"type": "pg-queue",
"database_url": "postgres://postgres:postgrespassword@localhost:5432/default"
}
}
}
87 changes: 1 addition & 86 deletions voyager/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,92 +183,7 @@ async fn do_main(args: cli::AppArgs) -> Result<(), VoyagerError> {
_ => panic!("Not supported."),
}
}
cli::SetupCmd::Transfer {
on,
relay_address,
port_id,
channel_id,
receiver,
amount,
denom,
} => {
let chain = voyager_config.get_chain(&on).await?;

match chain {
AnyChain::EvmMinimal(evm) => {
let signer_middleware = Arc::new(SignerMiddleware::new(
evm.provider.clone(),
evm.wallet.clone(),
));
let relay = UCS01Relay::new(relay_address, signer_middleware.clone());

let denom = relay.denom_to_address(denom).await.unwrap();
let addr = relay.address_to_denom(denom).await.unwrap();
println!(
"Counter: {:?}",
relay
.counterparty_endpoints(port_id.clone(), channel_id.clone())
.await
.unwrap()
);
println!("ADdress is: {}, {}", denom, addr);
println!(
"Foreign: {}, Prefix: {}",
relay
.make_foreign_denom(
port_id.clone(),
channel_id.clone(),
"stake".to_string()
)
.await
.unwrap(),
relay
.make_denom_prefix(port_id.clone(), channel_id.clone())
.await
.unwrap()
);
panic!();

let erc_contract = erc20::ERC20::new(denom, signer_middleware.clone());

let balance = erc_contract.balance_of(evm.wallet.address()).await.unwrap();
println!("Balance is: {}", balance);

erc_contract
.approve(relay_address, U256::max_value() / 2)
.send()
.await
.unwrap()
.await
.unwrap()
.unwrap();
println!("{:?}", evm.wallet.address());

let tx_rcp = relay
.send(
port_id,
channel_id,
hex::decode(receiver).unwrap().into(),
[LocalToken {
denom,
amount: amount.into(),
}]
.into(),
u64::MAX,
u64::MAX,
)
.send()
.await
.unwrap()
.await
.unwrap()
.unwrap();

dbg!(tx_rcp);
}
_ => panic!("Not supported."),
}
}
cli::SetupCmd::Transfer { .. } => {}
_ => panic!("not supported"),
},
Command::Query { on, at, cmd } => {
Expand Down

0 comments on commit a24e1a2

Please sign in to comment.