Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

neutron testnet version #221

Closed
wants to merge 10 commits into from
2 changes: 1 addition & 1 deletion apps/mtcs/enclave/quartz.manifest.template
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ loader.env.MYAPP_DATA = { passthrough = true }
loader.env.QUARTZ_PORT = { passthrough = true }

loader.argv = ["enclave",
"--chain-id", "testing",
"--chain-id", "pion-1",
"--fmspc", "{{ fmspc }}",
"--tcbinfo-contract", "{{ tcbinfo_contract }}",
"--dcap-verifier-contract", "{{ dcap_verifier_contract }}",
Expand Down
2 changes: 1 addition & 1 deletion apps/mtcs/enclave/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,6 @@ pub struct Cli {
#[clap(long, default_value = "127.0.0.1:11090")]
pub node_url: String,

#[clap(long, default_value = "admin")]
#[clap(long, default_value = "val1")]
pub tx_sender: String,
}
4 changes: 2 additions & 2 deletions apps/mtcs/enclave/src/mtcs_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@
where
A: Attestor,
{
pub fn new(config: Config, sk: Arc<Mutex<Option<SigningKey>>>, attestor: A) -> Self {
pub fn new(_config: Config, sk: Arc<Mutex<Option<SigningKey>>>, attestor: A) -> Self {
Self {

Check failure on line 55 in apps/mtcs/enclave/src/mtcs_server.rs

View workflow job for this annotation

GitHub Actions / clippy

missing field `config` in initializer of `mtcs_server::MtcsService<A>`

error[E0063]: missing field `config` in initializer of `mtcs_server::MtcsService<A>` --> apps/mtcs/enclave/src/mtcs_server.rs:55:9 | 55 | Self { | ^^^^ missing `config`
config,
// config,
sk,
attestor,
}
Expand Down
16 changes: 11 additions & 5 deletions apps/mtcs/enclave/src/wslistener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ impl<A: Attestor> WebSocketHandler for MtcsService<A> {
"message.sender" => {
sender = values.first().cloned();
}
"wasm._contract_address" => {
"neutron._contract_address" => {
contract_address = values.first().cloned();
}
_ => {}
Expand Down Expand Up @@ -99,8 +99,8 @@ async fn handler<A: Attestor>(
sender: String,
node_url: &str,
) -> Result<()> {
let chain_id = &ChainId::from_str("testing")?;
let httpurl = Url::parse(&format!("http://{}", node_url))?;
let chain_id = &ChainId::from_str("pion-1")?;
let httpurl = Url::parse(&format!("https://{}", node_url))?; // TODO Improve
let wasmd_client = CliWasmdClient::new(httpurl);

// Query obligations and liquidity sources from chain
Expand Down Expand Up @@ -130,8 +130,14 @@ async fn handler<A: Attestor>(
});

// Send setoffs to mtcs contract on chain
let output =
wasmd_client.tx_execute(contract, chain_id, 2000000, &sender, json!(setoffs_msg))?;
let output = wasmd_client.tx_execute(
contract,
chain_id,
2000000,
&sender,
json!(setoffs_msg),
"1000untrn",
)?;

println!("Setoffs TX: {}", output);
Ok(())
Expand Down
6 changes: 3 additions & 3 deletions apps/mtcs/quartz.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
mock_sgx = false
tx_sender = "admin"
chain_id = "testing"
node_url = "127.0.0.1:26657"
tx_sender = "val1"
chain_id = "pion-1"
node_url = "rpc-falcron.pion-1.ntrn.tech"
enclave_rpc_addr = "http://127.0.0.1"
enclave_rpc_port = 11090
trusted_hash = ""
Expand Down
2 changes: 1 addition & 1 deletion apps/transfers/enclave/quartz.manifest.template
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ loader.env.MYAPP_DATA = { passthrough = true }
loader.env.QUARTZ_PORT = { passthrough = true }

loader.argv = ["quartz-app-transfers-enclave",
"--chain-id", "testing",
"--chain-id", "pion-1",
"--fmspc", "{{ fmspc }}",
"--tcbinfo-contract", "{{ tcbinfo_contract }}",
"--dcap-verifier-contract", "{{ dcap_verifier_contract }}",
Expand Down
2 changes: 1 addition & 1 deletion apps/transfers/enclave/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ pub struct Cli {
#[clap(long, default_value = "127.0.0.1:11090")]
pub node_url: String,

#[clap(long, default_value = "admin")]
#[clap(long, default_value = "val1")]
pub tx_sender: String,
}

Expand Down
8 changes: 5 additions & 3 deletions apps/transfers/enclave/src/wslistener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ async fn transfer_handler<A: Attestor>(
ws_config: &WsListenerConfig,
) -> Result<()> {
let chain_id = &ChainId::from_str(&ws_config.chain_id)?;
let httpurl = Url::parse(&format!("http://{}", ws_config.node_url))?;
let httpurl = Url::parse(&format!("https://{}", ws_config.node_url))?;
let wasmd_client = CliWasmdClient::new(httpurl.clone());

// Query contract state
Expand All @@ -186,7 +186,7 @@ async fn transfer_handler<A: Attestor>(

// Wait 2 blocks
info!("Waiting 2 blocks for light client proof");
let wsurl = format!("ws://{}/websocket", ws_config.node_url);
let wsurl = format!("wss://{}/websocket", ws_config.node_url);
two_block_waitoor(&wsurl).await?;

// Call tm prover with trusted hash and height
Expand Down Expand Up @@ -255,6 +255,7 @@ async fn transfer_handler<A: Attestor>(
2000000,
&ws_config.tx_sender,
json!(transfer_msg),
"11000untrn",
)?;

println!("Output TX: {}", output);
Expand All @@ -269,7 +270,7 @@ async fn query_handler<A: Attestor>(
ws_config: &WsListenerConfig,
) -> Result<()> {
let chain_id = &ChainId::from_str(&ws_config.chain_id)?;
let httpurl = Url::parse(&format!("http://{}", ws_config.node_url))?;
let httpurl = Url::parse(&format!("https://{}", ws_config.node_url))?;
let wasmd_client = CliWasmdClient::new(httpurl);

// Query contract state
Expand Down Expand Up @@ -322,6 +323,7 @@ async fn query_handler<A: Attestor>(
2000000,
&ws_config.tx_sender,
json!(query_msg),
"11000untrn",
)?;

println!("Output TX: {}", output);
Expand Down
3 changes: 3 additions & 0 deletions apps/transfers/frontend/src/config/chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import { localWasm } from './chains/localWasm'
import { localNeutron } from './chains/localNeutron'
import { testnetNeutron } from './chains/testnetNeutron'


Check failure on line 7 in apps/transfers/frontend/src/config/chain.ts

View workflow job for this annotation

GitHub Actions / linting

Delete `⏎`
const supportedChains: Record<string, ChainInfo> = {
doWasm: {
...localWasm,
Expand All @@ -12,6 +14,7 @@
},
localNeutron,
localWasm,
testnetNeutron,
}

const chain = supportedChains[process.env.NEXT_PUBLIC_TARGET_CHAIN!]
Expand Down
2 changes: 1 addition & 1 deletion apps/transfers/frontend/src/config/chains/localNeutron.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ChainInfo } from '@keplr-wallet/types'

// Neutron local chain definition
export const localNeutron: ChainInfo = {
chainId: 'testing',
chainId: 'test-1',
chainName: 'Local Neutron Testchain',
rpc: 'http://localhost:26657',
rest: 'http://localhost:1317',
Expand Down
43 changes: 43 additions & 0 deletions apps/transfers/frontend/src/config/chains/testnetNeutron.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { ChainInfo } from '@keplr-wallet/types'

// Neutron testnet chain definition
export const testnetNeutron: ChainInfo = {
chainId: 'pion-1',
chainName: 'Neutron Testnet',
rpc: 'https://rpc-falcron.pion-1.ntrn.tech',
rest: 'https://rest-falcron.pion-1.ntrn.tech',
stakeCurrency: {
coinDenom: 'NEUTRON',
coinMinimalDenom: 'untrn',
coinDecimals: 6,
coinGeckoId: 'neutron',
},
bip44: {
coinType: 118,
},
bech32Config: {
bech32PrefixAccAddr: 'neutron',
bech32PrefixAccPub: 'neutron' + 'pub',
bech32PrefixValAddr: 'neutron' + 'valoper',
bech32PrefixValPub: 'neutron' + 'valoperpub',
bech32PrefixConsAddr: 'neutron' + 'valcons',
bech32PrefixConsPub: 'neutron' + 'valconspub',
},
currencies: [
{
coinDenom: 'NTRN',
coinMinimalDenom: 'untrn',
coinDecimals: 6,
coinGeckoId: 'neutron',
},
],
feeCurrencies: [
{
coinDenom: 'NTRN',
coinMinimalDenom: 'untrn',
coinDecimals: 6,
coinGeckoId: 'neutron',
gasPriceStep: { low: 0.001, average: 0.0025, high: 0.004 },
},
],
}
6 changes: 3 additions & 3 deletions apps/transfers/quartz.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
mock_sgx = false
tx_sender = "admin"
chain_id = "testing"
node_url = "127.0.0.1:26657"
tx_sender = "val1"
chain_id = "pion-1"
node_url = "rpc-falcron.pion-1.ntrn.tech"
enclave_rpc_addr = "http://127.0.0.1"
enclave_rpc_port = 11090
trusted_hash = ""
Expand Down
6 changes: 3 additions & 3 deletions cli/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,15 @@ fn default_rpc_addr() -> String {
}

fn default_node_url() -> String {
"127.0.0.1:26657".to_string()
"rpc-falcron.pion-1.ntrn.tech".to_string()
}

fn default_tx_sender() -> String {
String::from("admin")
String::from("val1")
}

fn default_chain_id() -> ChainId {
"testing".parse().expect("default chain_id failed")
"pion-1".parse().expect("default chain_id failed")
}

fn default_port() -> u16 {
Expand Down
55 changes: 45 additions & 10 deletions cli/src/handler/contract_deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ use tendermint_rpc::HttpClient;
use tracing::{debug, info};
use wasmd_client::{CliWasmdClient, WasmdClient};

use super::utils::{
helpers::block_tx_commit,
types::{Log, WasmdTxResponse},
};
use super::utils::{helpers::block_tx_commit, types::WasmdTxResponse};
use crate::{
config::Config,
error::Error,
Expand Down Expand Up @@ -68,7 +65,7 @@ async fn deploy(
args: ContractDeployRequest,
config: &Config,
) -> Result<(u64, String), anyhow::Error> {
let httpurl = Url::parse(&format!("http://{}", config.node_url))?;
let httpurl = Url::parse(&format!("https://{}", config.node_url))?;
let tmrpc_client = HttpClient::new(httpurl.as_str())?;
let wasmd_client = CliWasmdClient::new(Url::parse(httpurl.as_str())?);

Expand All @@ -79,10 +76,32 @@ async fn deploy(
&config.tx_sender,
wasm_bin_path.display().to_string(),
)?)?;
let res = block_tx_commit(&tmrpc_client, deploy_output.txhash).await?;
info!("Deploy output: {:?}", deploy_output);

let log: Vec<Log> = serde_json::from_str(&res.tx_result.log)?;
let code_id: u64 = log[0].events[1].attributes[1].value.parse()?;
let res = block_tx_commit(&tmrpc_client, deploy_output.txhash).await?;
// info!("Deploy response {:?}", res);
info!("TX result log: {}", res.tx_result.log);

// let log: Vec<Log> = serde_json::from_str(&res.tx_result.log)?;
// let code_id: u64 = log[0].events[1].attributes[1].value.parse()?;
// config.save_codeid_to_cache(wasm_bin_path, code_id).await?;

// Find the 'code_id' attribute
let code_id = res
.tx_result
.events
.iter()
.find(|event| event.kind == "store_code")
.and_then(|event| {
event
.attributes
.iter()
.find(|attr| attr.key_str().unwrap_or("") == "code_id")
})
.and_then(|attr| attr.value_str().ok().and_then(|v| v.parse().ok()))
.ok_or_else(|| anyhow::anyhow!("Failed to find code_id in the transaction result"))?;

info!("Code ID: {}", code_id);
config.save_codeid_to_cache(wasm_bin_path, code_id).await?;

code_id
Expand All @@ -108,8 +127,24 @@ async fn deploy(
)?)?;
let res = block_tx_commit(&tmrpc_client, init_output.txhash).await?;

let log: Vec<Log> = serde_json::from_str(&res.tx_result.log)?;
let contract_addr: &String = &log[0].events[1].attributes[0].value;
// info!("Init response: {:?}", res);

// Find the '_contract_address' attribute
let contract_addr: String = res
.tx_result
.events
.iter()
.find(|event| event.kind == "instantiate")
.and_then(|event| {
event
.attributes
.iter()
.find(|attr| attr.key_str().unwrap_or("") == "_contract_address")
})
.and_then(|attr| attr.value_str().ok().and_then(|v| v.parse().ok()))
.ok_or_else(|| {
anyhow::anyhow!("Failed to find contract_address in the transaction result")
})?;

info!("🚀 Successfully deployed and instantiated contract!");
info!("🆔 Code ID: {}", code_id);
Expand Down
13 changes: 9 additions & 4 deletions cli/src/handler/handshake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ impl Handler for HandshakeRequest {
}

async fn handshake(args: HandshakeRequest, config: Config) -> Result<String, anyhow::Error> {
let httpurl = Url::parse(&format!("http://{}", config.node_url))?;
let wsurl = format!("ws://{}/websocket", config.node_url);
let httpurl = Url::parse(&format!("https://{}", config.node_url))?;
let wsurl = format!("wss://{}/websocket", config.node_url);

let tmrpc_client = HttpClient::new(httpurl.as_str())?;
let wasmd_client = CliWasmdClient::new(Url::parse(httpurl.as_str())?);
Expand All @@ -60,6 +60,7 @@ async fn handshake(args: HandshakeRequest, config: Config) -> Result<String, any
let res: serde_json::Value = RelayMessage::SessionCreate
.run_relay(config.enclave_rpc())
.await?;
info!("\n\n Enclave run realy response: {:?}", res);

let output: WasmdTxResponse = serde_json::from_str(
wasmd_client
Expand All @@ -69,10 +70,11 @@ async fn handshake(args: HandshakeRequest, config: Config) -> Result<String, any
2000000,
&config.tx_sender,
json!(res),
"11000untrn", // Add the fee here
)?
.as_str(),
)?;
debug!("\n\n SessionCreate tx output: {:?}", output);
info!("\n\n SessionCreate tx output: {:?}", output);

// Wait for tx to commit
block_tx_commit(&tmrpc_client, output.txhash).await?;
Expand Down Expand Up @@ -101,6 +103,7 @@ async fn handshake(args: HandshakeRequest, config: Config) -> Result<String, any

// Execute SessionSetPubKey on enclave
info!("Running SessionSetPubKey");

let res: serde_json::Value = RelayMessage::SessionSetPubKey {
proof: proof_output,
}
Expand All @@ -112,13 +115,15 @@ async fn handshake(args: HandshakeRequest, config: Config) -> Result<String, any
wasmd_client
.tx_execute(
&args.contract.clone(),
&ChainId::from_str("testing")?,
&ChainId::from_str("pion-1")?,
2000000,
&config.tx_sender,
json!(res),
"11000untrn", // Add the fee here
)?
.as_str(),
)?;
info!("\n\n SessionCreate tx output: {:?}", output);

// Wait for tx to commit
block_tx_commit(&tmrpc_client, output.txhash).await?;
Expand Down
4 changes: 2 additions & 2 deletions cli/src/handler/utils/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use crate::{config::Config, error::Error};

pub fn wasmaddr_to_id(address_str: &str) -> Result<AccountId, anyhow::Error> {
let (hr, _) = bech32_decode(address_str).map_err(|e| anyhow!(e))?;
if hr != "wasm" {
if hr != "neutron" {
return Err(anyhow!(hr));
}

Expand Down Expand Up @@ -60,7 +60,7 @@ pub async fn block_tx_commit(client: &HttpClient, tx: Hash) -> Result<TmTxRespon

// Queries the chain for the latested height and hash
pub fn query_latest_height_hash(node_url: &String) -> Result<(Height, Hash), Error> {
let httpurl = Url::parse(&format!("http://{}", node_url))
let httpurl = Url::parse(&format!("https://{}", node_url))
.map_err(|e| Error::GenericErr(e.to_string()))?;
let wasmd_client = CliWasmdClient::new(httpurl);

Expand Down
Loading
Loading