Skip to content

Commit

Permalink
rusk-wallet: Adjust rusk-wallet so that rusk can use it
Browse files Browse the repository at this point in the history
This change includes:
- add moonlight support
- add functions that return a key for a given index
- add code that can generate a test-wallet with a seed of [0u8;
  RNG_SEED]
  • Loading branch information
moCello committed Sep 6, 2024
1 parent 5b4f33f commit 1c36e92
Show file tree
Hide file tree
Showing 4 changed files with 234 additions and 83 deletions.
6 changes: 6 additions & 0 deletions rusk-wallet/src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,12 @@ impl Ord for NoteData {
}
}

impl AsRef<Note> for NoteData {
fn as_ref(&self) -> &Note {
&self.note
}
}

impl Serializable<{ u64::SIZE + Note::SIZE }> for NoteData {
type Error = dusk_bytes::Error;
/// Converts a Note into a byte representation
Expand Down
38 changes: 30 additions & 8 deletions rusk-wallet/src/clients.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ mod sync;

use dusk_bytes::Serializable;
use execution_core::{
transfer::{phoenix::Prove, Transaction},
signatures::bls::PublicKey as AccountPublicKey,
transfer::{moonlight::AccountData, phoenix::Prove, Transaction},
Error as ExecutionCoreError,
};
use flume::Receiver;
Expand Down Expand Up @@ -139,15 +140,15 @@ impl State {
/// Skips writing the proof for non phoenix transactions
pub fn prove_and_propagate(
&self,
utx: Transaction,
tx: Transaction,
) -> Result<Transaction, Error> {
let status = self.status;
let prover = &self.prover;
let mut utx = utx;
let mut tx = tx;

if let Transaction::Phoenix(tx) = &mut utx {
if let Transaction::Phoenix(utx) = &mut tx {
let status = self.status;
let proof = tx.proof();
let proof = utx.proof();

status("Attempt to prove tx...");

Expand All @@ -158,12 +159,12 @@ impl State {
ExecutionCoreError::PhoenixCircuit(e.to_string())
})?;

tx.set_proof(proof);
utx.set_proof(proof);

status("Proving sucesss!");
}

let tx_bytes = utx.to_var_bytes();
let tx_bytes = tx.to_var_bytes();

status("Attempt to preverify tx...");
let preverify_req = RuskRequest::new("preverify", tx_bytes.clone());
Expand All @@ -175,7 +176,7 @@ impl State {
let _ = self.client.call(2, "Chain", &propagate_req).wait()?;
status("Transaction propagated!");

Ok(utx)
Ok(tx)
}

/// Find notes for a view key, starting from the given block height.
Expand Down Expand Up @@ -215,6 +216,27 @@ impl State {
inputs
}

pub(crate) fn fetch_account(
&self,
pk: &AccountPublicKey,
) -> Result<AccountData, Error> {
let status = self.status;
status("Fetching account-data...");

let account = self
.client
.contract_query::<_, 1024>(TRANSFER_CONTRACT, "account", pk)
.wait()?;
let account = rkyv::from_bytes(&account).map_err(|_| Error::Rkyv)?;
status("account-data received!");

let account_address = pk.to_bytes().to_vec();
let account_address = bs58::encode(account_address).into_string();
println!("Account address: {}", account_address);

Ok(account)
}

pub(crate) fn fetch_notes(
&self,
pk: &PhoenixPublicKey,
Expand Down
Loading

0 comments on commit 1c36e92

Please sign in to comment.