Add deploy script template

This commit is contained in:
Armani Ferrante 2021-01-27 19:58:26 -08:00
parent 80e23f8719
commit 989b1ea3bd
No known key found for this signature in database
GPG Key ID: D597A80BCF8E12B7
5 changed files with 65 additions and 26 deletions

51
Cargo.lock generated
View File

@ -617,6 +617,12 @@ version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ea221b5284a47e40033bf9b66f35f984ec0ea2931eb03505246cd27a963f981b"
[[package]]
name = "cpuid-bool"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8aebca1129a03dc6dc2b127edd729435bbc4a37e1d5f4d7513165089ceb02634"
[[package]]
name = "crc32fast"
version = "1.2.1"
@ -896,7 +902,7 @@ dependencies = [
"ed25519",
"rand",
"serde",
"sha2",
"sha2 0.8.2",
"zeroize",
]
@ -1538,7 +1544,7 @@ dependencies = [
"digest 0.8.1",
"hmac-drbg",
"rand",
"sha2",
"sha2 0.8.2",
"subtle 2.4.0",
"typenum",
]
@ -2626,6 +2632,19 @@ dependencies = [
"opaque-debug 0.2.3",
]
[[package]]
name = "sha2"
version = "0.9.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6e7aab86fe2149bad8c507606bdb3f4ef5e7b2380eb92350f56122cca72a42a8"
dependencies = [
"block-buffer 0.9.0",
"cfg-if 1.0.0",
"cpuid-bool",
"digest 0.9.0",
"opaque-debug 0.3.0",
]
[[package]]
name = "sha3"
version = "0.9.1"
@ -2797,9 +2816,9 @@ dependencies = [
[[package]]
name = "solana-frozen-abi"
version = "1.5.0"
version = "1.5.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2511b9e46d30daa7bde24eb6330eb3808885573ceca99c550f4fc8d3e428785a"
checksum = "0d0c1cf7dafbcf4e1e0a56b7b28848bdf41a5e3065e9763d3aae892027109956"
dependencies = [
"bs58",
"bv",
@ -2809,7 +2828,7 @@ dependencies = [
"rustc_version",
"serde",
"serde_derive",
"sha2",
"sha2 0.9.2",
"solana-frozen-abi-macro",
"solana-logger",
"thiserror",
@ -2817,9 +2836,9 @@ dependencies = [
[[package]]
name = "solana-frozen-abi-macro"
version = "1.5.0"
version = "1.5.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5f616e1d66cfb1d5f35d4677af1e5592dc4da2141e718ddf42c926ad47d4727f"
checksum = "cb44325468e78e9e4535c90c656c36c953b42cd34ed4999d39f1d33b8780a545"
dependencies = [
"lazy_static",
"proc-macro2 1.0.24",
@ -2830,9 +2849,9 @@ dependencies = [
[[package]]
name = "solana-logger"
version = "1.5.0"
version = "1.5.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4c2be7d6ec2bd98cabae975b9eea0a418ae550f60188892d2190b8b0c9e8ae20"
checksum = "b7a46715d2f6fda4697f640038fbd2a16645b10af81dbf2e5a19048c99b8a546"
dependencies = [
"env_logger",
"lazy_static",
@ -2890,9 +2909,9 @@ dependencies = [
[[package]]
name = "solana-program"
version = "1.5.0"
version = "1.5.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7a7df63d84d4ba7f67365d179b9994f2690554f313e219f29810b4583077e066"
checksum = "fb200f05cb93b01f6e9b2e0d94d240e7e5dfa0b14c4308713b236c01a525a0ef"
dependencies = [
"bincode",
"bs58",
@ -2910,7 +2929,7 @@ dependencies = [
"serde",
"serde_bytes",
"serde_derive",
"sha2",
"sha2 0.9.2",
"solana-frozen-abi",
"solana-frozen-abi-macro",
"solana-logger",
@ -3032,7 +3051,7 @@ dependencies = [
"serde_bytes",
"serde_derive",
"serde_json",
"sha2",
"sha2 0.8.2",
"sha3",
"solana-crate-features",
"solana-frozen-abi",
@ -3045,9 +3064,9 @@ dependencies = [
[[package]]
name = "solana-sdk-macro"
version = "1.5.0"
version = "1.5.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "012a3f407ae5a2571c810592d72f86c87b4652aeeb8ed7e3082970af172d5ac6"
checksum = "d463f2a24e75ca02f065ac2a9ac855f661c8d0f8917090514d65e4f82cdf05ab"
dependencies = [
"bs58",
"proc-macro2 1.0.24",
@ -3392,7 +3411,7 @@ dependencies = [
"pbkdf2",
"rand",
"rustc-hash",
"sha2",
"sha2 0.8.2",
"unicode-normalization",
]

View File

@ -19,7 +19,7 @@ anchor-attribute-program = { path = "./attribute/program", version = "0.0.0-alph
anchor-attribute-state = { path = "./attribute/state", version = "0.0.0-alpha.0" }
anchor-derive-accounts = { path = "./derive/accounts", version = "0.0.0-alpha.0" }
serum-borsh = { version = "0.8.0-serum.1", features = ["serum-program"] }
solana-program = "1.4.3"
solana-program = "=1.5.0"
thiserror = "1.0.20"
[workspace]

View File

@ -100,6 +100,11 @@ fn init(name: String) -> Result<()> {
let mut mocha = File::create(&format!("tests/{}.js", name))?;
mocha.write_all(template::mocha(&name).as_bytes())?;
// Build the migrations directory.
fs::create_dir("migrations")?;
let mut deploy = File::create("migrations/deploy.js")?;
deploy.write_all(&template::deploy_script().as_bytes())?;
println!("{} initialized", name);
Ok(())
@ -138,7 +143,6 @@ fn new_program(name: &str) -> Result<()> {
xargo_toml.write_all(template::xargo_toml().as_bytes())?;
let mut lib_rs = File::create(&format!("programs/{}/src/lib.rs", name))?;
lib_rs.write_all(template::lib_rs(&name).as_bytes())?;
Ok(())
}
@ -400,10 +404,10 @@ fn run_hosted_deploy(url: &str, keypair: &str) -> Result<()> {
let cur_dir = std::env::current_dir()?;
let module_path = format!("{}/migrations/deploy.js", cur_dir.display());
let deploy_script_str = template::deploy_script(url, &module_path);
let deploy_script_host_str = template::deploy_script_host(url, &module_path);
std::env::set_current_dir(".anchor")?;
std::fs::write("deploy.js", deploy_script_str)?;
std::fs::write("deploy.js", deploy_script_host_str)?;
if let Err(e) = std::process::Command::new("node")
.arg("deploy.js")
.stdout(Stdio::inherit())

View File

@ -34,10 +34,9 @@ anchor-lang = {{ git = "https://github.com/project-serum/anchor", features = ["d
)
}
pub fn deploy_script(cluster_url: &str, script_path: &str) -> String {
pub fn deploy_script_host(cluster_url: &str, script_path: &str) -> String {
format!(
r#"
const serumCmn = require("@project-serum/common");
const anchor = require('@project-serum/anchor');
// Deploy script defined by the user.
@ -47,9 +46,9 @@ async function main() {{
const url = "{1}";
const preflightCommitment = 'recent';
const connection = new anchor.web3.Connection(url, preflightCommitment);
const wallet = serumCmn.NodeWallet.local();
const wallet = anchor.Wallet.local();
const provider = new serumCmn.Provider(connection, wallet, {{
const provider = new anchor.Provider(connection, wallet, {{
preflightCommitment,
commitment: 'recent',
}});
@ -63,6 +62,23 @@ main();
)
}
pub fn deploy_script() -> String {
return r#"
// Migrations are an early feature. Currently, they're nothing more than this
// single deploy script that's invoked from the CLI, injecting a provider
// configured from the workspace's Anchor.toml.
const anchor = require("@project-serum/anchor");
module.exports = async function (provider) {
// Configure client to use the provider.
anchor.setProvider(provider);
// Add your deploy script here.
}
"#
.to_string();
}
pub fn xargo_toml() -> String {
r#"[target.bpfel-unknown-unknown.dependencies.std]
features = []"#

View File

@ -1,6 +1,6 @@
use crate::{
AccountDeserialize, AccountSerialize, Accounts, AccountsExit, Context, CpiAccount,
ToAccountInfo, ToAccountInfos, ToAccountMetas,
AccountDeserialize, AccountSerialize, Accounts, AccountsExit, CpiAccount, ToAccountInfo,
ToAccountInfos, ToAccountMetas,
};
use solana_program::account_info::AccountInfo;
use solana_program::entrypoint::ProgramResult;