Skip to content

Commit

Permalink
rusk-wallet: Change http contract call return value to byte array
Browse files Browse the repository at this point in the history
  • Loading branch information
Daksh14 committed Dec 22, 2024
1 parent 4d98bf8 commit 4d125ed
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 21 deletions.
12 changes: 3 additions & 9 deletions rusk-wallet/src/bin/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -604,12 +604,6 @@ impl Command {
.http_contract_call(contract_id, &fn_name, fn_args)
.await?;

let http_call = if let Some(x) = http_call {
x.to_string()
} else {
"<empty>".to_string()
};

Ok(RunResult::ContractCall(tx.hash(), http_call))
}

Expand Down Expand Up @@ -701,7 +695,7 @@ pub enum RunResult<'a> {
Profile((u8, &'a Profile)),
Profiles(&'a Vec<Profile>),
ContractId([u8; CONTRACT_ID_BYTES]),
ContractCall(BlsScalar, String),
ContractCall(BlsScalar, Vec<u8>),
ExportedKeys(PathBuf, PathBuf),
Create(),
Restore(),
Expand Down Expand Up @@ -779,11 +773,11 @@ impl fmt::Display for RunResult<'_> {
ContractId(bytes) => {
write!(f, "> Contract ID: {}", hex::encode(bytes))
}
ContractCall(scalar, string) => {
ContractCall(scalar, bytes) => {
let hash = hex::encode(scalar.to_bytes());
writeln!(f, "> Contract call transaction hash: {hash}",)?;

writeln!(f, "> Http contract query: {string}",)
writeln!(f, "> Http contract query: {:?}", bytes)
}
ExportedKeys(pk, kp) => {
let pk = pk.display();
Expand Down
14 changes: 2 additions & 12 deletions rusk-wallet/src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -630,25 +630,15 @@ impl<F: SecureWalletFile + Debug> Wallet<F> {
contract_id: String,
fn_name: &str,
fn_args: Vec<u8>,
) -> Result<Option<u32>, Error> {
) -> Result<Vec<u8>, Error> {
let client = self.state()?.client();

// query the rusk vm
let response = client
.call("contracts", Some(contract_id), fn_name, &fn_args)
.await?;

if !response.is_empty() {
// wasm can only return u32 right now
// NOTE: This will fail if the contract returns a u64
// for a 64 bit contract
let value: u32 =
rkyv::from_bytes(&response).map_err(|_| Error::Rkyv)?;

Ok(Some(value))
} else {
Ok(None)
}
Ok(response)
}
}

Expand Down

0 comments on commit 4d125ed

Please sign in to comment.