Skip to content

Commit

Permalink
Merge remote-tracking branch 'namada/ibc-integration' (#390) into main
Browse files Browse the repository at this point in the history
* namada/ibc-integration:
  [ci] wasm checksums update
  use ibc-transfer cmd
  rename local variables
  fix for v0.8.1
  fix a way to call ibc_proof_specs
  fix for ibc integration branch
  add a test for non-IBC transfer on the same chain
  fix for denom decoding
  get receipt absence proof for TimeoutOnClose
  add a failure test
  add timeout and close tests
  add transfer back
  check balances
  add sub_prefix
  with height
  query with the height
  wait the next block
  add update_client
  fix requests
  add sleep
  add transfer test
  [ci] wasm checksums update
  remove clone
  fix header hash
  fix sub-prefix
  replace now func
  fix timeout timestamp
  fix timeout height
  [ci] wasm checksums update
  fix timeout
  add ibc-transfer command
  fix VP reads
  add denom.rs
  fix relay transfer
  fix IBC token VP for ack error
  fix coding for ack and ftt
  • Loading branch information
juped committed Nov 14, 2022
2 parents e84eaca + fe7d5ad commit c84a299
Show file tree
Hide file tree
Showing 39 changed files with 6,782 additions and 455 deletions.
670 changes: 657 additions & 13 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,13 @@ tendermint-config = {git = "https://github.com/heliaxdev/tendermint-rs.git", rev
tendermint-proto = {git = "https://github.com/heliaxdev/tendermint-rs.git", rev = "e6c684731f21bffd89886d3e91074b96aee074ba"}
tendermint-rpc = {git = "https://github.com/heliaxdev/tendermint-rs.git", rev = "e6c684731f21bffd89886d3e91074b96aee074ba"}
tendermint-testgen = {git = "https://github.com/heliaxdev/tendermint-rs.git", rev = "e6c684731f21bffd89886d3e91074b96aee074ba"}
tendermint-light-client = {git = "https://github.com/heliaxdev/tendermint-rs.git", rev = "e6c684731f21bffd89886d3e91074b96aee074ba"}
tendermint-light-client-verifier = {git = "https://github.com/heliaxdev/tendermint-rs.git", rev = "e6c684731f21bffd89886d3e91074b96aee074ba"}

# patched to a commit on the `eth-bridge-integration` branch of our fork
ibc = {git = "https://github.com/heliaxdev/ibc-rs.git", rev = "f4703dfe2c1f25cc431279ab74f10f3e0f6827e2"}
ibc-proto = {git = "https://github.com/heliaxdev/ibc-rs.git", rev = "f4703dfe2c1f25cc431279ab74f10f3e0f6827e2"}
ibc-relayer = {git = "https://github.com/heliaxdev/ibc-rs.git", rev = "f4703dfe2c1f25cc431279ab74f10f3e0f6827e2"}

# patched to a commit on the `eth-bridge-integration` branch of our fork
tower-abci = {git = "https://github.com/heliaxdev/tower-abci.git", rev = "fcc0014d0bda707109901abfa1b2f782d242f082"}
Expand Down
3 changes: 3 additions & 0 deletions apps/src/bin/anoma-client/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ pub async fn main() -> Result<()> {
Sub::TxTransfer(TxTransfer(args)) => {
tx::submit_transfer(ctx, args).await;
}
Sub::TxIbcTransfer(TxIbcTransfer(args)) => {
tx::submit_ibc_transfer(ctx, args).await;
}
Sub::TxUpdateVp(TxUpdateVp(args)) => {
tx::submit_update_vp(ctx, args).await;
}
Expand Down
1 change: 1 addition & 0 deletions apps/src/bin/anoma/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ fn handle_command(cmd: cli::cmds::Anoma, raw_sub_cmd: String) -> Result<()> {
cli::cmds::Anoma::Client(_)
| cli::cmds::Anoma::TxCustom(_)
| cli::cmds::Anoma::TxTransfer(_)
| cli::cmds::Anoma::TxIbcTransfer(_)
| cli::cmds::Anoma::TxUpdateVp(_)
| cli::cmds::Anoma::TxInitProposal(_)
| cli::cmds::Anoma::TxVoteProposal(_) => {
Expand Down
111 changes: 111 additions & 0 deletions apps/src/lib/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ pub mod cmds {
// Inlined commands from the client.
TxCustom(TxCustom),
TxTransfer(TxTransfer),
TxIbcTransfer(TxIbcTransfer),
TxUpdateVp(TxUpdateVp),
TxInitProposal(TxInitProposal),
TxVoteProposal(TxVoteProposal),
Expand All @@ -59,6 +60,7 @@ pub mod cmds {
.subcommand(Ledger::def())
.subcommand(TxCustom::def())
.subcommand(TxTransfer::def())
.subcommand(TxIbcTransfer::def())
.subcommand(TxUpdateVp::def())
.subcommand(TxInitProposal::def())
.subcommand(TxVoteProposal::def())
Expand All @@ -71,6 +73,8 @@ pub mod cmds {
let ledger = SubCmd::parse(matches).map(Self::Ledger);
let tx_custom = SubCmd::parse(matches).map(Self::TxCustom);
let tx_transfer = SubCmd::parse(matches).map(Self::TxTransfer);
let tx_ibc_transfer =
SubCmd::parse(matches).map(Self::TxIbcTransfer);
let tx_update_vp = SubCmd::parse(matches).map(Self::TxUpdateVp);
let tx_init_proposal =
SubCmd::parse(matches).map(Self::TxInitProposal);
Expand All @@ -81,6 +85,7 @@ pub mod cmds {
.or(ledger)
.or(tx_custom)
.or(tx_transfer)
.or(tx_ibc_transfer)
.or(tx_update_vp)
.or(tx_init_proposal)
.or(tx_vote_proposal)
Expand Down Expand Up @@ -144,6 +149,7 @@ pub mod cmds {
// Simple transactions
.subcommand(TxCustom::def().display_order(1))
.subcommand(TxTransfer::def().display_order(1))
.subcommand(TxIbcTransfer::def().display_order(1))
.subcommand(TxUpdateVp::def().display_order(1))
.subcommand(TxInitAccount::def().display_order(1))
.subcommand(TxInitValidator::def().display_order(1))
Expand Down Expand Up @@ -174,6 +180,7 @@ pub mod cmds {
use AnomaClientWithContext::*;
let tx_custom = Self::parse_with_ctx(matches, TxCustom);
let tx_transfer = Self::parse_with_ctx(matches, TxTransfer);
let tx_ibc_transfer = Self::parse_with_ctx(matches, TxIbcTransfer);
let tx_update_vp = Self::parse_with_ctx(matches, TxUpdateVp);
let tx_init_account = Self::parse_with_ctx(matches, TxInitAccount);
let tx_init_validator =
Expand Down Expand Up @@ -202,6 +209,7 @@ pub mod cmds {
let utils = SubCmd::parse(matches).map(Self::WithoutContext);
tx_custom
.or(tx_transfer)
.or(tx_ibc_transfer)
.or(tx_update_vp)
.or(tx_init_account)
.or(tx_init_validator)
Expand Down Expand Up @@ -259,6 +267,7 @@ pub mod cmds {
// Ledger cmds
TxCustom(TxCustom),
TxTransfer(TxTransfer),
TxIbcTransfer(TxIbcTransfer),
QueryResult(QueryResult),
TxUpdateVp(TxUpdateVp),
TxInitAccount(TxInitAccount),
Expand Down Expand Up @@ -781,6 +790,25 @@ pub mod cmds {
}
}

#[derive(Clone, Debug)]
pub struct TxIbcTransfer(pub args::TxIbcTransfer);

impl SubCmd for TxIbcTransfer {
const CMD: &'static str = "ibc-transfer";

fn parse(matches: &ArgMatches) -> Option<Self> {
matches.subcommand_matches(Self::CMD).map(|matches| {
TxIbcTransfer(args::TxIbcTransfer::parse(matches))
})
}

fn def() -> App {
App::new(Self::CMD)
.about("Send a signed IBC transfer transaction.")
.add_args::<args::TxIbcTransfer>()
}
}

#[derive(Clone, Debug)]
pub struct TxUpdateVp(pub args::TxUpdateVp);

Expand Down Expand Up @@ -1210,6 +1238,7 @@ pub mod args {
use std::path::PathBuf;
use std::str::FromStr;

use namada::ibc::core::ics24_host::identifier::{ChannelId, PortId};
use namada::types::address::Address;
use namada::types::chain::{ChainId, ChainIdPrefix};
use namada::types::governance::ProposalVote;
Expand Down Expand Up @@ -1243,6 +1272,7 @@ pub mod args {
const CHAIN_ID: Arg<ChainId> = arg("chain-id");
const CHAIN_ID_OPT: ArgOpt<ChainId> = CHAIN_ID.opt();
const CHAIN_ID_PREFIX: Arg<ChainIdPrefix> = arg("chain-prefix");
const CHANNEL_ID: Arg<ChannelId> = arg("channel-id");
const CODE_PATH: Arg<PathBuf> = arg("code-path");
const CODE_PATH_OPT: ArgOpt<PathBuf> = CODE_PATH.opt();
const CONSENSUS_TIMEOUT_COMMIT: ArgDefault<Timeout> = arg_default(
Expand Down Expand Up @@ -1279,6 +1309,10 @@ pub mod args {
const MODE: ArgOpt<String> = arg_opt("mode");
const NET_ADDRESS: Arg<SocketAddr> = arg("net-address");
const OWNER: ArgOpt<WalletAddress> = arg_opt("owner");
const PORT_ID: ArgDefault<PortId> = arg_default(
"port-id",
DefaultFn(|| PortId::from_str("transfer").unwrap()),
);
const PROPOSAL_OFFLINE: ArgFlag = flag("offline");
const PROTOCOL_KEY: ArgOpt<WalletPublicKey> = arg_opt("protocol-key");
const PRE_GENESIS_PATH: ArgOpt<PathBuf> = arg_opt("pre-genesis-path");
Expand All @@ -1289,6 +1323,7 @@ pub mod args {
const RAW_ADDRESS: Arg<Address> = arg("address");
const RAW_ADDRESS_OPT: ArgOpt<Address> = RAW_ADDRESS.opt();
const RAW_PUBLIC_KEY_OPT: ArgOpt<common::PublicKey> = arg_opt("public-key");
const RECEIVER: Arg<String> = arg("receiver");
const REWARDS_CODE_PATH: ArgOpt<PathBuf> = arg_opt("rewards-code-path");
const REWARDS_KEY: ArgOpt<WalletPublicKey> = arg_opt("rewards-key");
const SCHEME: ArgDefault<SchemeType> =
Expand All @@ -1301,6 +1336,8 @@ pub mod args {
const STORAGE_KEY: Arg<storage::Key> = arg("storage-key");
const SUB_PREFIX: ArgOpt<String> = arg_opt("sub-prefix");
const TARGET: Arg<WalletAddress> = arg("target");
const TIMEOUT_HEIGHT: ArgOpt<u64> = arg_opt("timeout-height");
const TIMEOUT_SEC_OFFSET: ArgOpt<u64> = arg_opt("timeout-sec-offset");
const TOKEN_OPT: ArgOpt<WalletAddress> = TOKEN.opt();
const TOKEN: Arg<WalletAddress> = arg("token");
const TX_HASH: Arg<String> = arg("tx-hash");
Expand Down Expand Up @@ -1476,6 +1513,80 @@ pub mod args {
}
}

/// IBC transfer transaction arguments
#[derive(Clone, Debug)]
pub struct TxIbcTransfer {
/// Common tx arguments
pub tx: Tx,
/// Transfer source address
pub source: WalletAddress,
/// Transfer target address
pub receiver: String,
/// Transferred token address
pub token: WalletAddress,
/// Transferred token address
pub sub_prefix: Option<String>,
/// Transferred token amount
pub amount: token::Amount,
/// Port ID
pub port_id: PortId,
/// Channel ID
pub channel_id: ChannelId,
/// Timeout height of the destination chain
pub timeout_height: Option<u64>,
/// Timeout timestamp offset
pub timeout_sec_offset: Option<u64>,
}

impl Args for TxIbcTransfer {
fn parse(matches: &ArgMatches) -> Self {
let tx = Tx::parse(matches);
let source = SOURCE.parse(matches);
let receiver = RECEIVER.parse(matches);
let token = TOKEN.parse(matches);
let sub_prefix = SUB_PREFIX.parse(matches);
let amount = AMOUNT.parse(matches);
let port_id = PORT_ID.parse(matches);
let channel_id = CHANNEL_ID.parse(matches);
let timeout_height = TIMEOUT_HEIGHT.parse(matches);
let timeout_sec_offset = TIMEOUT_SEC_OFFSET.parse(matches);
Self {
tx,
source,
receiver,
token,
sub_prefix,
amount,
port_id,
channel_id,
timeout_height,
timeout_sec_offset,
}
}

fn def(app: App) -> App {
app.add_args::<Tx>()
.arg(SOURCE.def().about(
"The source account address. The source's key is used to \
produce the signature.",
))
.arg(RECEIVER.def().about(
"The receiver address on the destination chain as string.",
))
.arg(TOKEN.def().about("The transfer token."))
.arg(SUB_PREFIX.def().about("The token's sub prefix."))
.arg(AMOUNT.def().about("The amount to transfer in decimal."))
.arg(PORT_ID.def().about("The port ID."))
.arg(CHANNEL_ID.def().about("The channel ID."))
.arg(
TIMEOUT_HEIGHT
.def()
.about("The timeout height of the destination chain."),
)
.arg(TIMEOUT_SEC_OFFSET.def().about("The timeout as seconds."))
}
}

/// Transaction to initialize a new account
#[derive(Clone, Debug)]
pub struct TxInitAccount {
Expand Down
23 changes: 22 additions & 1 deletion apps/src/lib/client/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,13 @@ use namada::types::governance::{
VotePower,
};
use namada::types::key::*;
use namada::types::storage::{Epoch, Key, KeySeg, PrefixValue};
use namada::types::storage::{BlockHeight, Epoch, Key, KeySeg, PrefixValue};
use namada::types::token::{balance_key, Amount};
use namada::types::{address, storage, token};

use crate::cli::{self, args, Context};
use crate::client::tendermint_rpc_types::TxResponse;
use crate::facade::tendermint::merkle::proof::Proof;
use crate::facade::tendermint_config::net::Address as TendermintAddress;
use crate::facade::tendermint_rpc::error::Error as TError;
use crate::facade::tendermint_rpc::query::Query;
Expand Down Expand Up @@ -1295,6 +1296,26 @@ where
})
}

/// Query a storage value and the proof without decoding.
pub async fn query_storage_value_bytes(
client: &HttpClient,
key: &storage::Key,
height: Option<BlockHeight>,
prove: bool,
) -> (Option<Vec<u8>>, Option<Proof>) {
let data = None;
let response = unwrap_client_response(
RPC.shell()
.storage_value(client, data, height, prove, key)
.await,
);
if response.data.is_empty() {
(None, response.proof)
} else {
(Some(response.data), response.proof)
}
}

/// Query a range of storage values with a matching prefix and decode them with
/// [`BorshDeserialize`]. Returns an iterator of the storage keys paired with
/// their associated values.
Expand Down
Loading

0 comments on commit c84a299

Please sign in to comment.