Add deposit button
This commit is contained in:
Generated
+3
@@ -76,8 +76,11 @@ checksum = "94a45b455c14666b85fc40a019e8ab9eb75e3a124e05494f5397122bc9eb06e0"
|
||||
name = "app"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"bandwidth-claim-contract",
|
||||
"bip39",
|
||||
"coconut-interface",
|
||||
"credentials",
|
||||
"network-defaults",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"tauri",
|
||||
|
||||
@@ -15,6 +15,7 @@ build = "src/build.rs"
|
||||
tauri-build = { version = "1.0.0-beta.2" }
|
||||
|
||||
[dependencies]
|
||||
bip39 = "1.0.1"
|
||||
serde_json = "1.0"
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
tauri = { version = "1.0.0-beta.4", features = [] }
|
||||
@@ -23,7 +24,9 @@ url = "2.2"
|
||||
|
||||
coconut-interface = { path = "../../../common/coconut-interface" }
|
||||
credentials = { path = "../../../common/credentials" }
|
||||
validator-client = {path = "../../../common/client-libs/validator-client"}
|
||||
validator-client = {path = "../../../common/client-libs/validator-client", features = ["nymd-client"] }
|
||||
bandwidth-claim-contract = { path = "../../../common/bandwidth-claim-contract" }
|
||||
network-defaults = { path = "../../../common/network-defaults" }
|
||||
|
||||
[features]
|
||||
default = ["custom-protocol"]
|
||||
|
||||
@@ -3,8 +3,11 @@
|
||||
windows_subsystem = "windows"
|
||||
)]
|
||||
|
||||
use bip39::Mnemonic;
|
||||
use std::str::FromStr;
|
||||
use std::sync::Arc;
|
||||
|
||||
use bandwidth_claim_contract::msg::ExecuteMsg;
|
||||
use tokio::sync::RwLock;
|
||||
use url::Url;
|
||||
|
||||
@@ -14,6 +17,7 @@ use coconut_interface::{
|
||||
};
|
||||
use credentials::coconut::bandwidth::{obtain_signature, BandwidthVoucherAttributes};
|
||||
use credentials::obtain_aggregate_verification_key;
|
||||
use validator_client::nymd::{AccountId, CosmosCoin, Decimal, Denom, NymdClient};
|
||||
|
||||
struct State {
|
||||
signatures: Vec<Signature>,
|
||||
@@ -55,15 +59,37 @@ fn parse_url_validators(raw: &[String]) -> Result<Vec<Url>, String> {
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
async fn randomise_credential(
|
||||
idx: usize,
|
||||
state: tauri::State<'_, Arc<RwLock<State>>>,
|
||||
) -> Result<Vec<Signature>, String> {
|
||||
let mut state = state.write().await;
|
||||
let signature = state.signatures.remove(idx);
|
||||
let (new_signature, _) = signature.randomise(&state.params);
|
||||
state.signatures.insert(idx, new_signature);
|
||||
Ok(state.signatures.clone())
|
||||
async fn deposit_funds(_state: tauri::State<'_, Arc<RwLock<State>>>) -> Result<String, String> {
|
||||
let nymd_url = Url::from_str("http://127.0.0.1:26657").unwrap();
|
||||
let mnemonic = Mnemonic::from_str(&"sun surge soon stomach flavor country gorilla dress oblige stamp attract hip soldier agree steel prize nuclear know enjoy arm bargain always theme matter").unwrap();
|
||||
let nymd_client = NymdClient::connect_with_mnemonic(
|
||||
network_defaults::all::Network::SANDBOX,
|
||||
nymd_url.as_ref(),
|
||||
None,
|
||||
None,
|
||||
AccountId::from_str("nymt14hj2tavq8fpesdwxxcu44rty3hh90vhuysqrsr").ok(),
|
||||
mnemonic,
|
||||
None,
|
||||
)
|
||||
.expect("Could not create nymd client");
|
||||
let req = ExecuteMsg::BuyBandwidth {};
|
||||
let funds = vec![CosmosCoin {
|
||||
denom: Denom::from_str(network_defaults::sandbox::DENOM).unwrap(),
|
||||
amount: Decimal::from(1000000u64),
|
||||
}];
|
||||
let tx = nymd_client
|
||||
.execute(
|
||||
nymd_client.erc20_bridge_contract_address().unwrap(),
|
||||
&req,
|
||||
Default::default(),
|
||||
"",
|
||||
funds,
|
||||
)
|
||||
.await
|
||||
.unwrap()
|
||||
.transaction_hash;
|
||||
println!("Tx hash: {}", tx);
|
||||
Ok(tx.to_string())
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
@@ -206,7 +232,7 @@ fn main() {
|
||||
))))
|
||||
.invoke_handler(tauri::generate_handler![
|
||||
get_credential,
|
||||
randomise_credential,
|
||||
deposit_funds,
|
||||
delete_credential,
|
||||
list_credentials,
|
||||
verify_credential
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
const validator_urls = ["http://localhost:8080", "http://localhost:8081", "http://localhost:8082"];
|
||||
let signatures = [];
|
||||
let qrVisible = false;
|
||||
let tx_hash = "";
|
||||
|
||||
async function getCredential() {
|
||||
signatures = await invoke("get_credential", {
|
||||
@@ -13,10 +14,8 @@
|
||||
});
|
||||
}
|
||||
|
||||
async function randomiseCredential(idx) {
|
||||
signatures = await invoke("randomise_credential", {
|
||||
idx: idx,
|
||||
});
|
||||
async function depositFunds() {
|
||||
tx_hash = await invoke("deposit_funds");
|
||||
}
|
||||
|
||||
async function verifyCredential(idx) {
|
||||
@@ -58,6 +57,7 @@
|
||||
<title>Coconut</title>
|
||||
</svelte:head>
|
||||
|
||||
<button class="btn btn-success" on:click={depositFunds}>Deposit</button>
|
||||
<button class="btn btn-success" on:click={getCredential}>Get Credential</button>
|
||||
<hr />
|
||||
<table class="table table-dark">
|
||||
@@ -67,11 +67,6 @@
|
||||
<td>
|
||||
<div class="btn-group" role="group" aria-label="Basic example">
|
||||
<button
|
||||
class="btn btn-primary"
|
||||
on:click={() => {
|
||||
randomiseCredential(idx);
|
||||
}}>Randomize</button
|
||||
><button
|
||||
class="btn btn-danger"
|
||||
on:click={() => {
|
||||
deleteCredential(idx);
|
||||
|
||||
@@ -82,7 +82,7 @@ pub async fn post_blind_sign(
|
||||
nymd_url.as_ref(),
|
||||
None,
|
||||
None,
|
||||
AccountId::from_str("").ok(),
|
||||
AccountId::from_str("nymt14hj2tavq8fpesdwxxcu44rty3hh90vhuysqrsr").ok(),
|
||||
mnemonic,
|
||||
None,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user