This repository has been archived by the owner on Oct 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
enhancement: pull remote ABI subcommand (#775)
* initial structure and ops logic * cleanup * cargo fix * cargo fix * Revert "cleanup" This reverts commit 069519e. * cargo fmt * undo cargo fix * use optional contract_name arg, cleanup * undo cargo fix change * undo cargo fic * swap fuels in indexers * fix defaults * update docs * integrate ra0x3 feedback * update doc * deekerno feedback
- Loading branch information
Showing
8 changed files
with
125 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# `forc index pull-abi` | ||
|
||
Pull an abi file from a raw GitHub URL. | ||
|
||
```bash | ||
forc index pull-abi --raw-url https://raw.githubusercontent.com/rvmelkonian/sway-escrow/main/out/debug/escrow-contract-abi.json | ||
``` | ||
|
||
```text | ||
USAGE: | ||
forc-index pull-abi [OPTIONS] --raw-url <RAW_URL> | ||
OPTIONS: | ||
--contract-name <CONTRACT_NAME> Name of contract. | ||
-h, --help Print help information | ||
-p, --path <PATH> Path at which to write the ABI. | ||
--url <URL> URL of the ABI file. | ||
-v, --verbose Enable verbose output. | ||
--with-abi <WITH_ABI> Only pull the ABI for the given contract. | ||
--with-contract <WITH_CONTRACT> Pull the full contract code including the abi. | ||
``` |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
use crate::ops::forc_index_pull_abi; | ||
use anyhow::Result; | ||
use clap::Parser; | ||
use std::path::PathBuf; | ||
|
||
#[derive(Debug, Parser)] | ||
pub struct Command { | ||
/// URL of the ABI file. | ||
#[clap(long, help = "URL of the ABI file.")] | ||
pub url: String, | ||
|
||
/// Only pull the ABI for the given contract. | ||
#[clap(long, help = "Only pull the ABI for the given contract.")] | ||
pub with_abi: Option<bool>, | ||
|
||
/// Pull the full contract code including the abi. | ||
#[clap(long, help = "Pull the full contract code including the abi.")] | ||
pub with_contract: Option<bool>, | ||
|
||
/// Name of contract. | ||
#[clap(long, help = "Name of contract.")] | ||
pub contract_name: Option<String>, | ||
|
||
/// Path at which to write the ABI. | ||
#[clap( | ||
short, | ||
long, | ||
parse(from_os_str), | ||
help = "Path at which to write the ABI." | ||
)] | ||
pub path: Option<PathBuf>, | ||
|
||
/// Enable verbose output. | ||
#[clap(short, long, help = "Enable verbose output.")] | ||
pub verbose: bool, | ||
} | ||
|
||
pub async fn exec(command: Command) -> Result<(), anyhow::Error> { | ||
forc_index_pull_abi::init(command).await?; | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
use crate::cli::PullAbiCommand; | ||
use anyhow::anyhow; | ||
use reqwest::Url; | ||
use std::{fs::File, io::prelude::*}; | ||
use tracing::{error, info}; | ||
|
||
pub async fn init(command: PullAbiCommand) -> anyhow::Result<()> { | ||
let PullAbiCommand { | ||
url, | ||
with_abi, | ||
with_contract, | ||
contract_name, | ||
path, | ||
verbose, | ||
.. | ||
} = command; | ||
|
||
let url = Url::parse(&url)?; | ||
let client = reqwest::Client::new(); | ||
let response = client.get(url.clone()).send().await?; | ||
let content = response.text().await?; | ||
|
||
let file_name = match contract_name { | ||
Some(name) => format!("{}-abi.json", name), | ||
None => url | ||
.path_segments() | ||
.ok_or(anyhow!("Invalid URL path"))? | ||
.last() | ||
.ok_or(anyhow!("Invalid URL path"))? | ||
.to_owned(), | ||
}; | ||
|
||
if with_contract.unwrap_or(false) && with_abi.unwrap_or(false) { | ||
error!("Cannot use both --with-contract and --with-abi, please choose one"); | ||
} | ||
|
||
if with_contract.unwrap_or(false) { | ||
unimplemented!(); | ||
} | ||
|
||
if with_abi.unwrap_or(true) { | ||
let output_dir = path.unwrap_or(std::env::current_dir()?); | ||
let file_path = output_dir.join(file_name); | ||
let mut file = File::create(&file_path)?; | ||
file.write_all(content.as_bytes())?; | ||
|
||
if verbose { | ||
info!("ABI file saved to: {:?}", file_path); | ||
} | ||
|
||
info!("✅ ABI file saved"); | ||
} | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters