Skip to content

Commit

Permalink
Split deploy section into sewup.toml (#200)
Browse files Browse the repository at this point in the history
Split deploy section into `sewup.toml`
  • Loading branch information
yanganto committed Sep 18, 2021
1 parent a556311 commit e21c7eb
Show file tree
Hide file tree
Showing 20 changed files with 64 additions and 61 deletions.
14 changes: 9 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,15 @@ opt-level = "z"
incremental = false
opt-level = "z"

# Following features helps are used when building or testing a contract
[features]
constructor = [] # required
constructor-test = [] # required
```

```toml
# sewup.toml

# Following section including the parameters to deploy the contract
[deploy]
url = "http://localhost:8545" # url for rpc node
Expand All @@ -68,11 +77,6 @@ address = "0xXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" # account address
# gas = 5000000 # optional
# gas_price = 1 # optional


# Following features helps are used when building or testing a contract
[features]
constructor = [] # required
constructor-test = [] # required
```
Place [.cargo/config](./examples/hello-contract/.cargo/config) file in your project to specify the flags for build.

Expand Down
2 changes: 1 addition & 1 deletion SewUp.wiki
Submodule SewUp.wiki updated from 9046f0 to 06eeee
4 changes: 2 additions & 2 deletions cargo-sewup/src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ use tokio::{
use wasmprinter::print_file;
use wat;

use cargo_sewup::config::Toml;
use cargo_sewup::config::CargoToml;
use cargo_sewup::deploy_wasm;

async fn check_cargo_toml() -> Result<String> {
let config_contents = read_to_string("Cargo.toml")
.await
.context("can not read Cargo.toml")?;
let config: Toml = toml::from_str(config_contents.as_str())?;
let config: CargoToml = toml::from_str(config_contents.as_str())?;

// TODO: more toml config checking here

Expand Down
21 changes: 10 additions & 11 deletions cargo-sewup/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use serde_derive::Deserialize;
use tokio::fs::read_to_string;

use crate::constants::{DEFAULT_GAS, DEFAULT_GAS_PRICE};
use crate::errors::DeployError;

#[derive(Deserialize)]
pub struct Deploy {
Expand Down Expand Up @@ -37,20 +36,20 @@ pub struct Package {
}

#[derive(Deserialize)]
pub struct Toml {
pub struct CargoToml {
pub package: Package,
pub deploy: Option<Deploy>,
}

#[derive(Deserialize)]
pub struct DeployToml {
pub deploy: Deploy,
}

pub async fn get_deploy_config() -> Result<Deploy> {
let config_contents = read_to_string("Cargo.toml")
let config_contents = read_to_string("sewup.toml")
.await
.context("can not read Cargo.toml")?;
let config: Toml = toml::from_str(config_contents.as_str())?;
.context("can not read sewup.toml")?;
let config: DeployToml = toml::from_str(config_contents.as_str())?;

if let Some(deploy) = config.deploy {
Ok(deploy)
} else {
Err(DeployError::ConfigIncorrect.into())
}
Ok(config.deploy)
}
7 changes: 0 additions & 7 deletions examples/default-contract/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,6 @@ opt-level = "z"
incremental = false
opt-level = "z"

[deploy]
url = "http://localhost:8545"
private = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
address = "0xXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
gas = 5000000
gas_price = 1

[features]
constructor = []
constructor-test = []
7 changes: 7 additions & 0 deletions examples/default-contract/sewup.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# This config file is for examples, it is good for you to ignore this config in your sewup project
[deploy]
url = "http://localhost:8545"
private = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
address = "0xXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
gas = 5000000
gas_price = 1
5 changes: 0 additions & 5 deletions examples/erc1155-contract/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@ opt-level = "z"
incremental = false
opt-level = "z"

[deploy]
url = "http://localhost:8545"
private = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
address = "0xXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"

[features]
constructor = []
constructor-test = []
5 changes: 5 additions & 0 deletions examples/erc1155-contract/sewup.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# This config file is for examples, it is good for you to ignore this config in your sewup project
[deploy]
url = "http://localhost:8545"
private = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
address = "0xXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
5 changes: 0 additions & 5 deletions examples/erc20-contract/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@ opt-level = "z"
incremental = false
opt-level = "z"

[deploy]
url = "http://localhost:8545"
private = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
address = "0xXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"

[features]
constructor = []
constructor-test = []
5 changes: 5 additions & 0 deletions examples/erc20-contract/sewup.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# This config file is for examples, it is good for you to ignore this config in your sewup project
[deploy]
url = "http://localhost:8545"
private = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
address = "0xXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
5 changes: 0 additions & 5 deletions examples/erc721-contract/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@ opt-level = "z"
incremental = false
opt-level = "z"

[deploy]
url = "http://localhost:8545"
private = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
address = "0xXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"

[features]
constructor = []
constructor-test = []
5 changes: 5 additions & 0 deletions examples/erc721-contract/sewup.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# This config file is for examples, it is good for you to ignore this config in your sewup project
[deploy]
url = "http://localhost:8545"
private = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
address = "0xXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
5 changes: 0 additions & 5 deletions examples/hello-contract/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,6 @@ opt-level = "z"
incremental = false
opt-level = "z"

[deploy]
url = "http://localhost:8545"
private = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
address = "0xXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"

[features]
constructor = []
constructor-test = []
Expand Down
5 changes: 5 additions & 0 deletions examples/hello-contract/sewup.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# This config file is for examples, it is good for you to ignore this config in your sewup project
[deploy]
url = "http://localhost:8545"
private = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
address = "0xXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
5 changes: 0 additions & 5 deletions examples/kv-contract/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,6 @@ opt-level = "z"
incremental = false
opt-level = "z"

[deploy]
url = "http://localhost:8545"
private = "0000000000000000000000000000000000000000000000000000000000000000"
address = "0x0000000000000000000000000000000000000000"

[features]
client = [ "web3", "tokio", "secp256k1", "reqwest", "serde_json", "bincode", "cargo-sewup"]
constructor = []
Expand Down
5 changes: 5 additions & 0 deletions examples/kv-contract/sewup.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# This config file is for examples, it is good for you to ignore this config in your sewup project
[deploy]
url = "http://localhost:8545"
private = "0000000000000000000000000000000000000000000000000000000000000000"
address = "0x0000000000000000000000000000000000000000"
5 changes: 0 additions & 5 deletions examples/rdb-contract/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,6 @@ opt-level = "z"
incremental = false
opt-level = "z"

[deploy]
url = "http://localhost:8545"
private = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
address = "0xXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"

[features]
client = [ "web3", "tokio", "secp256k1", "reqwest", "serde_json", "bincode", "cargo-sewup"]
constructor = []
Expand Down
5 changes: 5 additions & 0 deletions examples/rdb-contract/sewup.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# This config file is for examples, it is good for you to ignore this config in your sewup project
[deploy]
url = "http://localhost:8545"
private = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
address = "0xXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
5 changes: 0 additions & 5 deletions examples/rusty-contract/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,6 @@ opt-level = "z"
incremental = false
opt-level = "z"

[deploy]
url = "http://localhost:8545"
private = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
address = "0xXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"

[features]
constructor = []
constructor-test = []
5 changes: 5 additions & 0 deletions examples/rusty-contract/sewup.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# This config file is for examples, it is good for you to ignore this config in your sewup project
[deploy]
url = "http://localhost:8545"
private = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
address = "0xXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"

0 comments on commit e21c7eb

Please sign in to comment.