Skip to content

Commit

Permalink
clean
Browse files Browse the repository at this point in the history
  • Loading branch information
kent-3 committed May 6, 2024
1 parent 0939a49 commit e3fc5d7
Show file tree
Hide file tree
Showing 12 changed files with 80 additions and 291 deletions.
34 changes: 23 additions & 11 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion secretrs/examples/contract_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use regex::Regex;
use serde::{Deserialize, Serialize};

use secretrs::{
clients::{ComputeQueryClient, RegistrationQueryClient},
grpc_clients::{ComputeQueryClient, RegistrationQueryClient},
proto::secret::compute::v1beta1::{QueryByContractAddressRequest, QuerySecretContractRequest},
utils::encryption::EncryptionUtils,
};
Expand Down
16 changes: 8 additions & 8 deletions secretrs/examples/encrypt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,28 @@ use serde::{Deserialize, Serialize};

use secretrs::utils::EncryptionUtils;

#[derive(Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum QueryMsg {
TokenInfo {},
}

#[tokio::main(flavor = "current_thread")]
async fn main() -> Result<()> {
color_eyre::install()?;

let code_hash = "9a00ca4ad505e9be7e6e6dddf8d939b7ec7e9ac8e109c8681f10db9cacb36d42";
let query = QueryMsg::TokenInfo {};

let encryption_utils = EncryptionUtils::new(None, "pulsar-3")?;
let encrypted = encryption_utils.encrypt(code_hash, &query)?;
let nonce = encrypted.nonce();
let query = encrypted.into_inner();

println!("Encrypted query: {}", hex::encode(&query));

// Use this to decrypt responses from the enclave:

let decrypted_bytes = encryption_utils.decrypt(&nonce, &query)?;
println!("Decrypted query: {}", String::from_utf8(decrypted_bytes)?);

Ok(())
}

#[derive(Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum QueryMsg {
TokenInfo {},
}
26 changes: 8 additions & 18 deletions secretrs/examples/query.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
use color_eyre::{eyre::OptionExt, owo_colors::OwoColorize, Result};

use secretrs::{
clients::{AuthQueryClient, BankQueryClient, ComputeQueryClient, GrpcClient, TxServiceClient},
grpc_clients::{
AuthQueryClient, BankQueryClient, ComputeQueryClient, GrpcClient, TxServiceClient,
},
proto,
};

// const GRPC_URL: &str = "http://localhost:9090";
const GRPC_URL: &str = "http://grpc.testnet.secretsaturn.net:9090";
const TEST_ADDRESS: &str = "secret1ap26qrlp8mcq2pg6r47w43l0y8zkqm8a450s03";

#[tokio::main(flavor = "current_thread")]
async fn async_main() -> Result<()> {
color_eyre::install()?;

// A single item page used throughout for brevity
use proto::cosmos::base::query::v1beta1::PageRequest;
let _one_page = Some(PageRequest {
Expand Down Expand Up @@ -44,7 +48,7 @@ async fn async_main() -> Result<()> {
// Method #1
if let Some(any) = response.account {
let base_account = any.to_msg::<proto::cosmos::auth::v1beta1::BaseAccount>()?;
let base_account = secretrs::auth::BaseAccount::try_from(base_account)?;
let base_account = cosmrs::auth::BaseAccount::try_from(base_account)?;
println!(
"Example: \"{}'s account number is {} and sequence is {} at block {}\"",
base_account.address.bright_green(),
Expand All @@ -58,7 +62,7 @@ async fn async_main() -> Result<()> {
// let base_account = response
// .account
// .and_then(|any| any.to_msg::<proto::cosmos::auth::v1beta1::BaseAccount>().ok() )
// .and_then(|base_account| secretrs::auth::BaseAccount::try_from(base_account).ok())
// .and_then(|base_account| cosmrs::auth::BaseAccount::try_from(base_account).ok())
// .ok_or_eyre("No Account")?;
// println!("Account: {:?}", base_account.green());

Expand Down Expand Up @@ -121,17 +125,3 @@ async fn async_main() -> Result<()> {

Ok(())
}

fn main() -> Result<()> {
color_eyre::install()?;

// Create a new Tokio runtime using the current thread scheduler
let rt = tokio::runtime::Builder::new_current_thread()
.enable_io()
.enable_time()
.build()
.unwrap();

// Use the runtime to run the async code
rt.block_on(async_main())
}
33 changes: 5 additions & 28 deletions secretrs/examples/tx.rs
Original file line number Diff line number Diff line change
@@ -1,30 +1,21 @@
// #![allow(unused)]

use color_eyre::{owo_colors::OwoColorize, Result};
use tokio::time::{sleep, Duration};

use secretrs::proto::cosmos::tx::v1beta1::BroadcastTxRequest;
use secretrs::{
bank::MsgSend,
clients::{GrpcClient, TxServiceClient},
grpc_clients::{GrpcClient, TxServiceClient},
proto::cosmos::tx::v1beta1::BroadcastTxRequest,
query::PageRequest,
tendermint::Hash,
tx::{self, Fee, Msg, SignDoc, SignerInfo, Tx},
AccountId, Coin,
};

// const GRPC_URL: &str = "http://grpc.testnet.secretsaturn.net:9090";
const GRPC_URL: &str = "http://localhost:9090";

async fn async_main() -> Result<()> {
// A single item page used throughout for brevity
let _one_page = Some(PageRequest {
key: vec![],
offset: 0,
limit: 1,
count_total: true,
reverse: false,
});
#[tokio::main(flavor = "current_thread")]
async fn main() -> Result<()> {
color_eyre::install()?;

// Tx Broadcast
println!("\n{}", "Tx Service".underline().blue());
Expand Down Expand Up @@ -87,17 +78,3 @@ async fn async_main() -> Result<()> {

Ok(())
}

fn main() -> Result<()> {
color_eyre::install()?;

// Create a new Tokio runtime using the current thread scheduler
let rt = tokio::runtime::Builder::new_current_thread()
.enable_io()
.enable_time()
.build()
.unwrap();

// Use the runtime to run the async code
rt.block_on(async_main())
}
120 changes: 0 additions & 120 deletions secretrs/src/dev.rs

This file was deleted.

Loading

0 comments on commit e3fc5d7

Please sign in to comment.