solana proram deploy
This commit is contained in:
parent
c6212d18fd
commit
27a05a37ec
|
@ -1 +1,3 @@
|
||||||
/target
|
/target
|
||||||
|
/test-ledger
|
||||||
|
/dev-tools
|
|
@ -2669,6 +2669,7 @@ dependencies = [
|
||||||
"dirs",
|
"dirs",
|
||||||
"reqwest",
|
"reqwest",
|
||||||
"serde",
|
"serde",
|
||||||
|
"solana-sdk",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|
|
@ -15,4 +15,5 @@ anyhow = "1.0.56"
|
||||||
anchor-client = "0.23.0"
|
anchor-client = "0.23.0"
|
||||||
dirs = "4.0.0"
|
dirs = "4.0.0"
|
||||||
serde = { version = "1.0.136", features = ["derive"] }
|
serde = { version = "1.0.136", features = ["derive"] }
|
||||||
reqwest = { version = "0.11.10", features = ["blocking", "json"] }
|
reqwest = { version = "0.11.10", features = ["blocking", "json"] }
|
||||||
|
solana-sdk = "1.8.14"
|
|
@ -1,10 +1,15 @@
|
||||||
use std::io::Error;
|
use std::{
|
||||||
|
fs,
|
||||||
|
io::Error,
|
||||||
|
path::Path,
|
||||||
|
process::{Command, Stdio},
|
||||||
|
};
|
||||||
|
|
||||||
use anchor_client::Cluster;
|
use anchor_client::Cluster;
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use reqwest::blocking::Client;
|
use reqwest::blocking::Client;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use std::fs;
|
use solana_sdk::signature::{write_keypair_file, Keypair};
|
||||||
|
|
||||||
use crate::config::{Config, ConfigOverride};
|
use crate::config::{Config, ConfigOverride};
|
||||||
|
|
||||||
|
@ -22,36 +27,75 @@ const REGISTRY_URL: &str = "https://anchor.projectserum.com/api/v0";
|
||||||
const SERUM_DEX_ID: &str = "9xQeWvG816bUx9EPjHmaT23yvVM2ZWbrrpZb9PusVFin";
|
const SERUM_DEX_ID: &str = "9xQeWvG816bUx9EPjHmaT23yvVM2ZWbrrpZb9PusVFin";
|
||||||
|
|
||||||
pub fn deploy(cfg_override: &ConfigOverride, cluster: Option<Cluster>) -> Result<()> {
|
pub fn deploy(cfg_override: &ConfigOverride, cluster: Option<Cluster>) -> Result<()> {
|
||||||
with_config(cfg_override, |_cfg| {
|
with_config(cfg_override, |cfg| {
|
||||||
println!("Deploying to: {}", cluster.unwrap().url());
|
let cluster = cluster.unwrap();
|
||||||
|
let cluster_url = cluster.url();
|
||||||
|
|
||||||
|
let provider_keypair = cfg.provider.wallet.to_string();
|
||||||
|
|
||||||
let client = Client::new();
|
let client = Client::new();
|
||||||
|
|
||||||
println!("Fetching Artifact...");
|
let program_keypair_path = Path::new("./dev-tools/serum-dex-dev.json");
|
||||||
let latest_resp = client
|
let program_artifact_path = Path::new("./dev-tools/serum-dex.so");
|
||||||
.get(format!("{REGISTRY_URL}/program/{SERUM_DEX_ID}/latest"))
|
|
||||||
.send()?
|
|
||||||
.json::<Vec<LatestResponse>>()?;
|
|
||||||
|
|
||||||
let latest_build_id = latest_resp
|
// If ./dev-tools does NOT exist
|
||||||
.get(0)
|
if !Path::exists(Path::new("./dev-tools")) {
|
||||||
.ok_or(Error::new(
|
println!("Fetching Artifact...");
|
||||||
std::io::ErrorKind::NotFound,
|
let latest_resp = client
|
||||||
"No latest build found",
|
.get(format!("{REGISTRY_URL}/program/{SERUM_DEX_ID}/latest"))
|
||||||
))?
|
.send()?
|
||||||
.id;
|
.json::<Vec<LatestResponse>>()?;
|
||||||
|
|
||||||
let artifact_path = client
|
let latest_build_id = latest_resp
|
||||||
.get(format!("{REGISTRY_URL}/build/{latest_build_id}/artifacts"))
|
.get(0)
|
||||||
.send()?
|
.ok_or(Error::new(
|
||||||
.json::<ArtifactResponse>()?
|
std::io::ErrorKind::NotFound,
|
||||||
.binary;
|
"No latest build found",
|
||||||
|
))?
|
||||||
|
.id;
|
||||||
|
|
||||||
let artifact_bytes = client.get(&artifact_path).send()?.bytes()?;
|
let artifact_path = client
|
||||||
|
.get(format!("{REGISTRY_URL}/build/{latest_build_id}/artifacts"))
|
||||||
|
.send()?
|
||||||
|
.json::<ArtifactResponse>()?
|
||||||
|
.binary;
|
||||||
|
|
||||||
fs::write("test.so", artifact_bytes)?;
|
let artifact_bytes = client.get(&artifact_path).send()?.bytes()?;
|
||||||
|
|
||||||
|
fs::create_dir("./dev-tools")?;
|
||||||
|
let program_keypair = Keypair::new();
|
||||||
|
|
||||||
|
fs::write(program_artifact_path, artifact_bytes)?;
|
||||||
|
write_keypair_file(&program_keypair, program_keypair_path).map_err(|e| {
|
||||||
|
Error::new(
|
||||||
|
std::io::ErrorKind::Other,
|
||||||
|
format!("Failed to write keypair file: {}", e),
|
||||||
|
)
|
||||||
|
})?;
|
||||||
|
}
|
||||||
|
|
||||||
|
let exit = Command::new("solana")
|
||||||
|
.arg("program")
|
||||||
|
.arg("deploy")
|
||||||
|
.arg("--url")
|
||||||
|
.arg(cluster_url)
|
||||||
|
.arg("--keypair")
|
||||||
|
.arg(provider_keypair)
|
||||||
|
.arg("--program-id")
|
||||||
|
.arg(program_keypair_path.to_str().unwrap())
|
||||||
|
.arg(program_artifact_path.to_str().unwrap())
|
||||||
|
.stdout(Stdio::inherit())
|
||||||
|
.stderr(Stdio::inherit())
|
||||||
|
.output()
|
||||||
|
.expect("Must deploy");
|
||||||
|
|
||||||
|
if !exit.status.success() {
|
||||||
|
println!("There was a problem deploying: {:?}.", exit);
|
||||||
|
std::process::exit(exit.status.code().unwrap_or(1));
|
||||||
|
}
|
||||||
|
|
||||||
println!("Deploy Successful");
|
println!("Deploy Successful");
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue