-
Notifications
You must be signed in to change notification settings - Fork 326
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Initial implementation for the relayer tx command #206 * Adding initial logic to support signing #47 * Adding logic for auth tx * Implementing initial support to conn open init and tx #206 * Changes: - Implemented logic for tx raw connection open init - Logic to build the message only using protobuf types - Got some signing logic but not validated - Still needs lots of refactoring and cleaning * update signing code to use k256 * Ignore .idea * Refactoring the ConnOpenInit logic. Disabling the build and sign tx code #246 * Added logic for the conn init tx on relayer * Finished implementing MsgConnectionOpenInit. No signing implemented #246 Co-authored-by: Andy Nogueira <me@andynogueira.dev>
- Loading branch information
Showing
16 changed files
with
467 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
use crate::prelude::*; | ||
|
||
use crate::error::{Error, Kind}; | ||
use abscissa_core::{Command, Options, Runnable}; | ||
use relayer::config::Config; | ||
use relayer::tx::connection::{conn_init, ConnectionOpenInitOptions}; | ||
|
||
#[derive(Clone, Command, Debug, Options)] | ||
pub struct TxRawConnInitCmd { | ||
#[options(free, help = "identifier of the source chain")] | ||
src_chain_id: Option<String>, | ||
|
||
#[options(free, help = "identifier of the destination chain")] | ||
dest_chain_id: Option<String>, | ||
|
||
#[options(free, help = "identifier of the source client")] | ||
src_client_id: Option<String>, | ||
|
||
#[options(free, help = "identifier of the destination client")] | ||
dest_client_id: Option<String>, | ||
|
||
#[options(free, help = "identifier of the source connection")] | ||
src_connection_id: Option<String>, | ||
|
||
#[options(free, help = "identifier of the destination connection")] | ||
dest_connection_id: Option<String>, | ||
} | ||
|
||
impl TxRawConnInitCmd { | ||
fn validate_options(&self, config: &Config) -> Result<ConnectionOpenInitOptions, String> { | ||
let src_chain_id = self | ||
.src_chain_id | ||
.clone() | ||
.ok_or_else(|| "missing source chain identifier".to_string())?; | ||
|
||
let src_chain_config = config | ||
.chains | ||
.iter() | ||
.find(|c| c.id == src_chain_id.parse().unwrap()) | ||
.ok_or_else(|| "missing src chain configuration".to_string())?; | ||
|
||
let dest_chain_id = self | ||
.dest_chain_id | ||
.clone() | ||
.ok_or_else(|| "missing destination chain identifier".to_string())?; | ||
|
||
let dest_chain_config = config | ||
.chains | ||
.iter() | ||
.find(|c| c.id == dest_chain_id.parse().unwrap()) | ||
.ok_or_else(|| "missing destination chain configuration".to_string())?; | ||
|
||
let src_client_id = self | ||
.src_client_id | ||
.as_ref() | ||
.ok_or_else(|| "missing source client identifier".to_string())? | ||
.parse() | ||
.map_err(|_| "bad source client identifier".to_string())?; | ||
|
||
let src_connection_id = self | ||
.src_connection_id | ||
.as_ref() | ||
.ok_or_else(|| "missing source connection identifier".to_string())? | ||
.parse() | ||
.map_err(|_| "bad source connection identifier".to_string())?; | ||
|
||
let dest_client_id = self | ||
.dest_client_id | ||
.as_ref() | ||
.ok_or_else(|| "missing destination client identifier".to_string())? | ||
.parse() | ||
.map_err(|_| "bad destination client identifier".to_string())?; | ||
|
||
let dest_connection_id = self | ||
.dest_connection_id | ||
.as_ref() | ||
.ok_or_else(|| "missing destination connection identifier".to_string())? | ||
.parse() | ||
.map_err(|_| "bad destination connection identifier".to_string())?; | ||
|
||
let opts = ConnectionOpenInitOptions { | ||
src_client_id, | ||
dest_client_id, | ||
src_connection_id, | ||
dest_connection_id, | ||
src_chain_config: src_chain_config.clone(), | ||
dest_chain_config: dest_chain_config.clone(), | ||
}; | ||
|
||
Ok(opts) | ||
} | ||
} | ||
|
||
impl Runnable for TxRawConnInitCmd { | ||
fn run(&self) { | ||
let config = app_config(); | ||
|
||
let opts = match self.validate_options(&config) { | ||
Err(err) => { | ||
status_err!("invalid options: {}", err); | ||
return; | ||
} | ||
Ok(result) => result, | ||
}; | ||
status_info!("Message", "{:?}", opts); | ||
|
||
let res: Result<(), Error> = conn_init(opts).map_err(|e| Kind::Tx.context(e).into()); | ||
|
||
match res { | ||
Ok(receipt) => status_info!("conn init, result: ", "{:?}", receipt), | ||
Err(e) => status_info!("conn init failed, error: ", "{}", e), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub mod tx; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
// use ibc_proto::tx::v1beta1::{Tx, TxBody, AuthInfo, SignDoc}; | ||
// use ibc::tx_msg::Msg; | ||
//use crate::error::Error; | ||
// use ibc_proto::tx::v1beta1::mode_info::{Single, Sum}; | ||
// use ibc_proto::tx::v1beta1::{AuthInfo, ModeInfo, SignDoc, SignerInfo, Tx, TxBody}; | ||
// use ibc::tx_msg::Msg; | ||
// use ibc_proto::base::crypto::v1beta1::public_key::Sum as PK_Sum; | ||
// use ibc_proto::base::crypto::v1beta1::PublicKey; | ||
// use tendermint::{account::Id, chain::Id as ChainId, net::Address}; | ||
// use hex; | ||
// use std::str::FromStr; | ||
// Signer | ||
// use k256::{ | ||
// ecdsa::{signature::Signer, signature::Verifier, Signature, SigningKey, VerifyKey}, | ||
// EncodedPoint, SecretKey, | ||
// }; | ||
|
||
// pub struct TxWrapper { | ||
// tx: Tx, | ||
// body: Vec<u8>, | ||
// auth_info: Vec<u8>, | ||
// } | ||
|
||
// pub struct TxBuilder { | ||
// | ||
// } | ||
|
||
//impl TxBuilder { | ||
// pub fn build_tx<T: std::error::Error, U: Msg<ValidationError = T>>(msg: Vec<Box<U>>, memo: String) -> Result<TxBody, Error> { | ||
|
||
// Create TxBody | ||
// let body = TxBody { | ||
// messages: proto_msgs, | ||
// memo: "".to_string(), | ||
// timeout_height: 0, | ||
// extension_options: Vec::<prost_types::Any>::new(), | ||
// non_critical_extension_options: Vec::<prost_types::Any>::new(), | ||
// }; | ||
// | ||
// // A protobuf serialization of a TxBody | ||
// let mut body_buf = Vec::new(); | ||
// prost::Message::encode(&body, &mut body_buf).unwrap(); | ||
|
||
// TODO: move this logic to tx builder | ||
// let sum = Some(PK_Sum::Secp256k1(pubkey_bytes)); | ||
// | ||
// let pk = Some(PublicKey { sum }); | ||
// | ||
// let single = Single { mode: 1 }; | ||
// let sum_single = Some(Sum::Single(single)); | ||
// let mode = Some(ModeInfo { sum: sum_single }); | ||
// | ||
// let signer_info = SignerInfo { | ||
// public_key: pk, | ||
// mode_info: mode, | ||
// sequence: 0, | ||
// }; | ||
// | ||
// let auth_info = AuthInfo { | ||
// signer_infos: vec![signer_info], | ||
// fee: None, | ||
// }; | ||
// | ||
// // A protobuf serialization of a AuthInfo | ||
// let mut auth_buf = Vec::new(); | ||
// prost::Message::encode(&auth_info, &mut auth_buf).unwrap(); | ||
// | ||
// let sign_doc = SignDoc { | ||
// body_bytes: body_buf.clone(), | ||
// auth_info_bytes: auth_buf.clone(), | ||
// chain_id: chain_config.clone().id.to_string(), | ||
// account_number: account_number, | ||
// }; | ||
// | ||
// // A protobuf serialization of a AuthInfo | ||
// let mut signdoc_buf = Vec::new(); | ||
// prost::Message::encode(&sign_doc, &mut signdoc_buf).unwrap(); | ||
// | ||
// let signature: Signature = signing_key.sign(&signdoc_buf); | ||
// | ||
// status_info!("Signed Tx", "{:?}", signed_doc); | ||
// | ||
// let tx_raw = TxRaw { | ||
// body_bytes, | ||
// auth_info_bytes: auth_bytes, | ||
// signatures: vec![signature.as_ref().to_vec()], | ||
// }; | ||
// | ||
// let mut txraw_buf = Vec::new(); | ||
// prost::Message::encode(&tx_raw, &mut txraw_buf).unwrap(); | ||
// println!("{:?}", txraw_buf); | ||
// } | ||
|
||
// pub fn get_sign_doc(body: TxBody, auth: AuthInfo) -> Result<SignDoc, Error> { | ||
// // A protobuf serialization of a TxBody | ||
// let mut body_buf = Vec::new(); | ||
// prost::Message::encode(&body, &mut body_buf).unwrap(); | ||
// | ||
// // A protobuf serialization of a AuthInfo | ||
// let mut auth_buf = Vec::new(); | ||
// prost::Message::encode(&auth_info, &mut auth_buf).unwrap(); | ||
// | ||
// let sign_doc = SignDoc { | ||
// body_bytes: body_buf.clone(), | ||
// auth_info_bytes: auth_buf.clone(), | ||
// chain_id: chain_config.clone().id.to_string(), | ||
// account_number: account_number, | ||
// }; | ||
// | ||
// Ok(signdoc) | ||
// } | ||
|
||
// convenience function to get address from private key | ||
|
||
// fn get_account(pk: Vec<u8>) -> Vec<u8> { | ||
// use crypto::digest::Digest; | ||
// use crypto::ripemd160::Ripemd160; | ||
// use crypto::sha2::Sha256; | ||
// let mut seed = Sha256::new(); | ||
// seed.input(pk.as_slice()); | ||
// let mut bytes = vec![0; seed.output_bytes()]; | ||
// seed.result(&mut bytes); | ||
// | ||
// let mut hash = Ripemd160::new(); | ||
// hash.input(bytes.as_slice()); | ||
// let mut acct = vec![0; hash.output_bytes()]; | ||
// hash.result(&mut acct); | ||
// acct.to_vec() | ||
// } | ||
//} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.