pub async fn send_to_eth(
    private_key: PrivateKey,
    destination: EthAddress,
    amount: Coin,
    fee: Coin,
    contact: &Contact,
) -> Result<TxResponse, CosmosGrpcError> {
    let our_address = private_key
        .to_public_key()
        .expect("Invalid private key!")
        .to_address();
    if amount.denom != fee.denom {
        return Err(CosmosGrpcError::BadInput(format!(
            "{} {} is an invalid denom set for SendToEth you must pay fees in the same token your sending",
            amount.denom, fee.denom,
        )));
    }
    let balances = contact.get_balances(our_address).await.unwrap();
    let mut found = false;
    for balance in balances {
        if balance.denom == amount.denom {
            let total_amount = amount.amount.clone() + (fee.amount.clone() * 2u8.into());
            if balance.amount < total_amount {
                return Err(CosmosGrpcError::BadInput(format!(
                    "Insufficient balance of {} to send {}",
                    amount.denom, total_amount,
                )));
            }
            found = true;
        }
    }
    if !found {
        return Err(CosmosGrpcError::BadInput(format!(
            "No balance of {} to send",
            amount.denom,
        )));
    }

    let msg_send_to_eth = MsgSendToEth {
        sender: our_address.to_string(),
        eth_dest: destination.to_string(),
        amount: Some(amount.into()),
        bridge_fee: Some(fee.clone().into()),
    };

    let fee = Fee {
        amount: vec![fee],
        gas_limit: 500_000u64,
        granter: None,
        payer: None,
    };

    let msg = Msg::new("/gravity.v1.MsgSendToEth", msg_send_to_eth);

    let args = contact.get_message_args(our_address, fee).await?;
    trace!("got optional tx info");

    let msg_bytes = private_key.sign_std_msg(&[msg], args, MEMO)?;

    let mut txrpc = TxServiceClient::connect(contact.get_url()).await?;
    let response = txrpc
        .broadcast_tx(BroadcastTxRequest {
            tx_bytes: msg_bytes,
            mode: BroadcastMode::Sync.into(),
        })
        .await?;
    let response = response.into_inner();

    contact
        .wait_for_tx(response.tx_response.unwrap(), TIMEOUT)
        .await
}
/// Sends tokens from Cosmos to Ethereum. These tokens will not be sent immediately instead
/// they will require some time to be included in a batch
Sends tokens from Cosmos to Ethereum. These tokens will not be sent immediately instead
they will require some time to be included in a batch
Sends tokens from Cosmos to Ethereum . These tokens will not be sent immediately instead they will require some time to be included in a batch
pub async fn send_to_eth(
    private_key: PrivateKey,
    destination: EthAddress,
    amount: Coin,
    fee: Coin,
    contact: &Contact,
) -> Result<TxResponse, CosmosGrpcError> {
    let our_address = private_key
        .to_public_key()
        .expect("Invalid private key!")
        .to_address();
    if amount.denom != fee.denom {
        return Err(CosmosGrpcError::BadInput(format!(
            "{} {} is an invalid denom set for SendToEth you must pay fees in the same token your sending",
            amount.denom, fee.denom,
        )));
    }
    let balances = contact.get_balances(our_address).await.unwrap();
    let mut found = false;
    for balance in balances {
        if balance.denom == amount.denom {
            let total_amount = amount.amount.clone() + (fee.amount.clone() * 2u8.into());
            if balance.amount < total_amount {
                return Err(CosmosGrpcError::BadInput(format!(
                    "Insufficient balance of {} to send {}",
                    amount.denom, total_amount,
                )));
            }
            found = true;
        }
    }
    if !found {
        return Err(CosmosGrpcError::BadInput(format!(
            "No balance of {} to send",
            amount.denom,
        )));
    }
    let msg_send_to_eth = MsgSendToEth {
        sender: our_address.to_string(),
        eth_dest: destination.to_string(),
        amount: Some(amount.into()),
        bridge_fee: Some(fee.clone().into()),
    };
    let fee = Fee {
        amount: vec![fee],
        gas_limit: 500_000u64,
        granter: None,
        payer: None,
    };
    let msg = Msg::new("/gravity.v1.MsgSendToEth", msg_send_to_eth);
    let args = contact.get_message_args(our_address, fee).await?;
    trace!("got optional tx info");
    let msg_bytes = private_key.sign_std_msg(&[msg], args, MEMO)?;
    let mut txrpc = TxServiceClient::connect(contact.get_url()).await?;
    let response = txrpc
        .broadcast_tx(BroadcastTxRequest {
            tx_bytes: msg_bytes,
            mode: BroadcastMode::Sync.into(),
        })
        .await?;
    let response = response.into_inner();
    contact
        .wait_for_tx(response.tx_response.unwrap(), TIMEOUT)
        .await
}
pub async fn send_to_eth ( private_key : PrivateKey , destination : EthAddress , amount : Coin , fee : Coin , contact : & Contact , ) -> Result < TxResponse , CosmosGrpcError > { let our_address = private_key . to_public_key ( ) . expect ( " " ) . to_address ( ) ; if amount . denom != fee . denom { return Err ( CosmosGrpcError :: BadInput ( format ! ( " " amount denom fee denom ) ) ) ; } let balances = contact . get_balances ( our_address ) . await . unwrap ( ) ; let mut found = false ; for balance in balances { if balance . denom == amount . denom { let total_amount = amount . amount . clone ( ) + ( fee . amount . clone ( ) * 2u8 . into ( ) ) ; if balance . amount < total_amount { return Err ( CosmosGrpcError :: BadInput ( format ! ( " " amount denom total_amount ) ) ) ; } found = true ; } } if ! found { return Err ( CosmosGrpcError :: BadInput ( format ! ( " " amount denom ) ) ) ; } let msg_send_to_eth = MsgSendToEth { sender : our_address . to_string ( ) , eth_dest : destination . to_string ( ) , amount : Some ( amount . into ( ) ) , bridge_fee : Some ( fee . clone ( ) . into ( ) ) , } ; let fee = Fee { amount : vec ! [ fee ] , gas_limit : 500_000u64 , granter : None , payer : None , } ; let msg = Msg :: new ( " " , msg_send_to_eth ) ; let args = contact . get_message_args ( our_address , fee ) . await ? ; trace ! ( " " ) ; let msg_bytes = private_key . sign_std_msg ( & [ msg ] , args , MEMO ) ? ; let mut txrpc = TxServiceClient :: connect ( contact . get_url ( ) ) . await ? ; let response = txrpc . broadcast_tx ( BroadcastTxRequest { tx_bytes : msg_bytes , mode : BroadcastMode :: Sync . into ( ) , } ) . await ? ; let response = response . into_inner ( ) ; contact . wait_for_tx ( response . tx_response . unwrap ( ) , TIMEOUT ) . await }
Sends tokens from Cosmos to Ethereum.
Sends tokens from Cosmos to Ethereum .
private_key
PrivateKey
destination
EthAddress
amount
Coin
fee
Coin
contact
&Contact