Skip to content

Commit

Permalink
Merge branch 'main' into willem/remove-sync2
Browse files Browse the repository at this point in the history
  • Loading branch information
ec2 committed Oct 1, 2024
2 parents 443ad17 + ce39263 commit e1d7429
Show file tree
Hide file tree
Showing 11 changed files with 194 additions and 114 deletions.
36 changes: 24 additions & 12 deletions Cargo.lock

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

14 changes: 7 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ tokio_with_wasm = { version = "0.7.1", features = ["rt", "rt-multi-thread", "syn

## Zcash dependencies

zcash_keys = { git = "https://github.com/ChainSafe/librustzcash", rev = "b6d32dd9a57165fb1508e9c1c8ab1a3aba09c7f4", features = ["transparent-inputs", "orchard", "sapling", "unstable"] }
zcash_client_backend = { git = "https://github.com/ChainSafe/librustzcash", rev = "b6d32dd9a57165fb1508e9c1c8ab1a3aba09c7f4", default-features = false, features = ["sync", "lightwalletd-tonic", "wasm-bindgen", "orchard"] }
zcash_client_memory = { git = "https://github.com/ChainSafe/librustzcash", rev = "b6d32dd9a57165fb1508e9c1c8ab1a3aba09c7f4", features = ["orchard"] }
zcash_primitives = { git = "https://github.com/ChainSafe/librustzcash", rev = "b6d32dd9a57165fb1508e9c1c8ab1a3aba09c7f4" }
zcash_address = { git = "https://github.com/ChainSafe/librustzcash", rev = "b6d32dd9a57165fb1508e9c1c8ab1a3aba09c7f4" }
zcash_proofs = { git = "https://github.com/ChainSafe/librustzcash", rev = "b6d32dd9a57165fb1508e9c1c8ab1a3aba09c7f4", default-features = false, features = ["bundled-prover"] }
zcash_keys = { git = "https://github.com/ChainSafe/librustzcash", rev = "9673cc2859e8a2528d1efd3c74795363f87ddf8f", features = ["transparent-inputs", "orchard", "sapling", "unstable"] }
zcash_client_backend = { git = "https://github.com/ChainSafe/librustzcash", rev = "9673cc2859e8a2528d1efd3c74795363f87ddf8f", default-features = false, features = ["sync", "lightwalletd-tonic", "wasm-bindgen", "orchard"] }
zcash_client_memory = { git = "https://github.com/ChainSafe/librustzcash", rev = "9673cc2859e8a2528d1efd3c74795363f87ddf8f", features = ["orchard"] }
zcash_primitives = { git = "https://github.com/ChainSafe/librustzcash", rev = "9673cc2859e8a2528d1efd3c74795363f87ddf8f" }
zcash_address = { git = "https://github.com/ChainSafe/librustzcash", rev = "9673cc2859e8a2528d1efd3c74795363f87ddf8f" }
zcash_proofs = { git = "https://github.com/ChainSafe/librustzcash", rev = "9673cc2859e8a2528d1efd3c74795363f87ddf8f", default-features = false, features = ["bundled-prover"] }

## gRPC Web dependencies
prost = { version = "0.12", default-features = false }
Expand All @@ -76,7 +76,7 @@ tonic = { version = "0.12", default-features = false, features = [

# Used in Native tests
tokio = { version = "1.0" }
zcash_client_sqlite = { git = "https://github.com/ChainSafe/librustzcash", rev = "b6d32dd9a57165fb1508e9c1c8ab1a3aba09c7f4", default-features = false, features = ["unstable", "orchard"], optional = true }
zcash_client_sqlite = { git = "https://github.com/ChainSafe/librustzcash", rev = "9673cc2859e8a2528d1efd3c74795363f87ddf8f", default-features = false, features = ["unstable", "orchard"], optional = true }

getrandom = { version = "0.2", features = ["js"] }
thiserror = "1.0.63"
Expand Down
17 changes: 12 additions & 5 deletions packages/demo-wallet/src/App/Actions.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import initWasm, { initThreadPool, WebWallet } from "@webzjs/webz-core";

import { State, Action } from "./App";
import { MAINNET_LIGHTWALLETD_PROXY } from "./constants";
import { MAINNET_LIGHTWALLETD_PROXY } from "./Constants";

export async function init(dispatch: React.Dispatch<Action>) {
await initWasm();
Expand All @@ -13,8 +13,8 @@ export async function init(dispatch: React.Dispatch<Action>) {
}

export async function addNewAccount(state: State, dispatch: React.Dispatch<Action>, seedPhrase: string, birthdayHeight: number) {
await state.webWallet?.create_account(seedPhrase, 0, birthdayHeight);
dispatch({ type: "append-account-seed", payload: seedPhrase });
let account_id = await state.webWallet?.create_account(seedPhrase, 0, birthdayHeight) || 0;
dispatch({ type: "add-account-seed", payload: [account_id, seedPhrase] });
await syncStateWithWallet(state, dispatch);
}

Expand Down Expand Up @@ -60,6 +60,13 @@ export async function triggerTransfer(
throw new Error("No active account");
}

await state.webWallet?.transfer(state.accountSeeds[state.activeAccount], state.activeAccount, toAddress, amount);
await syncStateWithWallet(state, dispatch);
let activeAccountSeedPhrase = state.accountSeeds.get(state.activeAccount) || "";

let proposal = await state.webWallet?.propose_transfer(state.activeAccount, toAddress, amount);
console.log(JSON.stringify(proposal.describe(), null, 2));

let txids = await state.webWallet.create_proposed_transactions(proposal, activeAccountSeedPhrase);
console.log(JSON.stringify(txids, null, 2));

await state.webWallet.send_authorized_transactions(txids);
}
10 changes: 5 additions & 5 deletions packages/demo-wallet/src/App/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,19 @@ export type State = {
activeAccount?: number;
summary?: WalletSummary;
chainHeight?: bigint;
accountSeeds: string[];
accountSeeds: Map<number, string>;
};

const initialState: State = {
activeAccount: undefined,
summary: undefined,
chainHeight: undefined,
accountSeeds: [],
accountSeeds: new Map<number, string>(),
};

export type Action =
| { type: "set-active-account"; payload: number }
| { type: "append-account-seed"; payload: string }
| { type: "add-account-seed"; payload: [number, string] }
| { type: "set-web-wallet"; payload: WebWallet }
| { type: "set-summary"; payload: WalletSummary }
| { type: "set-chain-height"; payload: bigint };
Expand All @@ -45,8 +45,8 @@ const reducer = (state: State, action: Action): State => {
case "set-active-account": {
return { ...state, activeAccount: action.payload };
}
case "append-account-seed": {
return { ...state, accountSeeds: [...state.accountSeeds, action.payload] };
case "add-account-seed": {
return { ...state, accountSeeds: state.accountSeeds.set(action.payload[0], action.payload[1]) };
}
case "set-web-wallet": {
return { ...state, webWallet: action.payload };
Expand Down
1 change: 1 addition & 0 deletions packages/demo-wallet/src/App/components/ImportAccount.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export function ImportAccount() {
await addNewAccount(state, dispatch, seedPhrase, birthdayHeight);
toast.success("Account imported successfully", {
position: "top-center",
autoClose: 2000,
});
setBirthdayHeight(0);
setSeedPhrase("");
Expand Down
1 change: 1 addition & 0 deletions src/bindgen/mod.rs
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
pub mod proposal;
pub mod wallet;
32 changes: 32 additions & 0 deletions src/bindgen/proposal.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
use wasm_bindgen::prelude::*;

use super::wallet::NoteRef;
use zcash_primitives::transaction::fees::zip317::FeeRule;

/// A handler to an immutable proposal. This can be passed to `create_proposed_transactions` to prove/authorize the transactions
/// before they are sent to the network.
///
/// The proposal can be reviewed by calling `describe` which will return a JSON object with the details of the proposal.
#[wasm_bindgen]
pub struct Proposal {
inner: zcash_client_backend::proposal::Proposal<FeeRule, NoteRef>,
}

impl From<zcash_client_backend::proposal::Proposal<FeeRule, NoteRef>> for Proposal {
fn from(inner: zcash_client_backend::proposal::Proposal<FeeRule, NoteRef>) -> Self {
Self { inner }
}
}

impl From<Proposal> for zcash_client_backend::proposal::Proposal<FeeRule, NoteRef> {
fn from(proposal: Proposal) -> Self {
proposal.inner
}
}

#[wasm_bindgen]
impl Proposal {
pub fn describe(&self) -> JsValue {
serde_wasm_bindgen::to_value(&self.inner).unwrap()
}
}
Loading

0 comments on commit e1d7429

Please sign in to comment.