sway/forc-plugins/forc-debug/examples/client_usage.rs
César D. Rodas a8d76e3379
Add support recover key (#5419)
## Description

Add recover-public-key to forc-crypto

This function is ported from
https://github.com/FuelLabs/forc-wallet/pull/152

This PR depends on #5388

## Checklist

- [x] I have linked to any relevant issues.
- [x] I have commented my code, particularly in hard-to-understand
areas.
- [x] I have updated the documentation where relevant (API docs, the
reference, and the Sway book).
- [x] I have added tests that prove my fix is effective or that my
feature works.
- [x] I have added (or requested a maintainer to add) the necessary
`Breaking*` or `New Feature` labels where relevant.
- [x] I have done my best to ensure that my PR adheres to [the Fuel Labs
Code Review
Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md).
- [x] I have requested a review from the relevant team or maintainers.
2024-01-23 13:14:29 +11:00

41 lines
1.2 KiB
Rust

use forc_debug::{ContractId, FuelClient, Transaction};
#[tokio::main]
async fn main() {
run_example().await.expect("Running example failed");
}
async fn run_example() -> Result<(), anyhow::Error> {
let client = FuelClient::new("http://localhost:4000/graphql")?;
let session_id = client.start_session().await?;
client
.set_breakpoint(&session_id, ContractId::zeroed(), 0)
.await?;
let tx: Transaction =
serde_json::from_str(include_str!("example_tx.json")).expect("Invalid transaction JSON");
let status = client.start_tx(&session_id, &tx).await?;
assert!(status.breakpoint.is_some());
let value = client.register(&session_id, 12).await?;
println!("reg[12] = {}", value);
let mem = client.memory(&session_id, 0x10, 0x20).await?;
println!("mem[0x10..0x30] = {:?}", mem);
client.set_single_stepping(&session_id, true).await?;
let status = client.continue_tx(&session_id).await?;
assert!(status.breakpoint.is_some());
client.set_single_stepping(&session_id, false).await?;
let status = client.continue_tx(&session_id).await?;
assert!(status.breakpoint.is_none());
client.end_session(&session_id).await?;
Ok(())
}