-
Notifications
You must be signed in to change notification settings - Fork 126
Implement new commands build and check + introduce bundles (.contract files)
#97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
5d26731
806929f
7161a6d
5e3f520
e7fbaba
61f7261
6cc0a67
d9eb49e
4d1edfa
0eb1949
3b3206e
f5450d6
c71639f
2aa7c96
9fc63a0
b40a82e
bd6477f
294d206
bb6f5e5
8b7f712
e89b6df
0850779
4dc41b7
85efad8
44d3a85
63a7131
54a7105
73d8e94
134c07a
1e7dabb
c7e2ffe
8229246
3500946
d2290c4
f8246d3
939a19b
007bb65
c99bd37
c74e3aa
bc965c7
da0c4ef
c521d61
8b2b3d2
d08a6f1
9ed109b
693f987
160b992
c699312
923cded
fcb66c6
c5296ad
4cdc220
930a309
4403bd7
0c596f0
d9a0f10
8737b9b
234b45f
8474209
b6b9cad
1c067d9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,15 +27,16 @@ | |
| //! | ||
| //! let language = SourceLanguage::new(Language::Ink, Version::new(2, 1, 0)); | ||
| //! let compiler = SourceCompiler::new(Compiler::RustC, Version::parse("1.46.0-nightly").unwrap()); | ||
| //! let source = Source::new([0u8; 32], language, compiler); | ||
| //! let wasm = SourceWasm::new(vec![0u8]); | ||
| //! let source = Source::new(Some(wasm), Some(CodeHash([0u8; 32])), language, compiler); | ||
| //! let contract = Contract::builder() | ||
| //! .name("incrementer".to_string()) | ||
| //! .version(Version::new(2, 1, 0)) | ||
| //! .authors(vec!["Parity Technologies <admin@parity.io>".to_string()]) | ||
| //! .description("increment a value".to_string()) | ||
| //! .documentation(Url::parse("http:docs.rs/").unwrap()) | ||
| //! .repository(Url::parse("http:github.com/paritytech/ink/").unwrap()) | ||
| //! .homepage(Url::parse("http:example.com/").unwrap()) | ||
| //! .documentation(Url::parse("http://docs.rs/").unwrap()) | ||
| //! .repository(Url::parse("http://github.com/paritytech/ink/").unwrap()) | ||
| //! .homepage(Url::parse("http://example.com/").unwrap()) | ||
| //! .license("Apache-2.0".to_string()) | ||
| //! .build() | ||
| //! .unwrap(); | ||
|
|
@@ -60,7 +61,7 @@ use url::Url; | |
| const METADATA_VERSION: &str = "0.1.0"; | ||
|
|
||
| /// Smart contract metadata. | ||
| #[derive(Debug, Serialize)] | ||
| #[derive(Clone, Debug, Serialize)] | ||
| pub struct ContractMetadata { | ||
| #[serde(rename = "metadataVersion")] | ||
| metadata_version: semver::Version, | ||
|
|
@@ -92,29 +93,86 @@ impl ContractMetadata { | |
| abi, | ||
| } | ||
| } | ||
|
|
||
| pub fn remove_source_wasm_attribute(&mut self) { | ||
| self.source.wasm = None; | ||
| } | ||
| } | ||
|
|
||
| /// Representation of the Wasm code hash. | ||
| #[derive(Clone, Debug, Eq, PartialEq)] | ||
| pub struct CodeHash(pub [u8; 32]); | ||
|
|
||
| impl Serialize for CodeHash { | ||
| fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> | ||
| where | ||
| S: Serializer, | ||
| { | ||
| serialize_as_byte_str(&self.0[..], serializer) | ||
| } | ||
| } | ||
|
|
||
| #[derive(Debug, Serialize)] | ||
| #[derive(Clone, Debug, Serialize)] | ||
| pub struct Source { | ||
| #[serde(serialize_with = "serialize_as_byte_str")] | ||
| hash: [u8; 32], | ||
| #[serde(skip_serializing_if = "Option::is_none")] | ||
| hash: Option<CodeHash>, | ||
|
Comment on lines
+117
to
+118
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When is this ever
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Discussion happened above, here.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What I read from the discussion is that we still always want the
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I understood the discussion in the way that we want to omit the hash:
|
||
| language: SourceLanguage, | ||
| compiler: SourceCompiler, | ||
| #[serde(skip_serializing_if = "Option::is_none")] | ||
| wasm: Option<SourceWasm>, | ||
| } | ||
|
|
||
| impl Source { | ||
| /// Constructs a new InkProjectSource. | ||
| pub fn new(hash: [u8; 32], language: SourceLanguage, compiler: SourceCompiler) -> Self { | ||
| pub fn new( | ||
| wasm: Option<SourceWasm>, | ||
| hash: Option<CodeHash>, | ||
| language: SourceLanguage, | ||
| compiler: SourceCompiler, | ||
| ) -> Self { | ||
| Source { | ||
| hash, | ||
| language, | ||
| compiler, | ||
| wasm, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /// The bytes of the compiled Wasm smart contract. | ||
| #[derive(Clone, Debug)] | ||
| pub struct SourceWasm { | ||
| wasm: Vec<u8>, | ||
| } | ||
|
|
||
| impl SourceWasm { | ||
| /// Constructs a new `SourceWasm`. | ||
| pub fn new(wasm: Vec<u8>) -> Self { | ||
| SourceWasm { wasm } | ||
| } | ||
| } | ||
|
|
||
| impl Serialize for SourceWasm { | ||
| fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> | ||
| where | ||
| S: Serializer, | ||
| { | ||
| serialize_as_byte_str(&self.wasm[..], serializer) | ||
| } | ||
| } | ||
|
|
||
| impl Display for SourceWasm { | ||
| fn fmt(&self, f: &mut Formatter<'_>) -> DisplayResult { | ||
| write!(f, "0x").expect("failed writing to string"); | ||
| for byte in &self.wasm { | ||
| write!(f, "{:02x}", byte).expect("failed writing to string"); | ||
| } | ||
| write!(f, "") | ||
| } | ||
| } | ||
|
|
||
| /// The language and version in which a smart contract is written. | ||
| #[derive(Debug)] | ||
| #[derive(Clone, Debug)] | ||
| pub struct SourceLanguage { | ||
| language: Language, | ||
| version: Version, | ||
|
|
@@ -143,7 +201,7 @@ impl Display for SourceLanguage { | |
| } | ||
|
|
||
| /// The language in which the smart contract is written. | ||
| #[derive(Debug)] | ||
| #[derive(Clone, Debug)] | ||
| pub enum Language { | ||
| Ink, | ||
| Solidity, | ||
|
|
@@ -161,7 +219,7 @@ impl Display for Language { | |
| } | ||
|
|
||
| /// A compiler used to compile a smart contract. | ||
| #[derive(Debug)] | ||
| #[derive(Clone, Debug)] | ||
| pub struct SourceCompiler { | ||
| compiler: Compiler, | ||
| version: Version, | ||
|
|
@@ -189,7 +247,7 @@ impl SourceCompiler { | |
| } | ||
|
|
||
| /// Compilers used to compile a smart contract. | ||
| #[derive(Debug, Serialize)] | ||
| #[derive(Clone, Debug, Serialize)] | ||
| pub enum Compiler { | ||
| RustC, | ||
| Solang, | ||
|
|
@@ -205,7 +263,7 @@ impl Display for Compiler { | |
| } | ||
|
|
||
| /// Metadata about a smart contract. | ||
| #[derive(Debug, Serialize)] | ||
| #[derive(Clone, Debug, Serialize)] | ||
| pub struct Contract { | ||
| name: String, | ||
| version: Version, | ||
|
|
@@ -229,7 +287,7 @@ impl Contract { | |
| } | ||
|
|
||
| /// Additional user defined metadata, can be any valid json. | ||
| #[derive(Debug, Serialize)] | ||
| #[derive(Clone, Debug, Serialize)] | ||
| pub struct User { | ||
| #[serde(flatten)] | ||
| json: Map<String, Value>, | ||
|
|
@@ -463,7 +521,8 @@ mod tests { | |
| let language = SourceLanguage::new(Language::Ink, Version::new(2, 1, 0)); | ||
| let compiler = | ||
| SourceCompiler::new(Compiler::RustC, Version::parse("1.46.0-nightly").unwrap()); | ||
| let source = Source::new([0u8; 32], language, compiler); | ||
| let wasm = SourceWasm::new(vec![0u8, 1u8, 2u8]); | ||
| let source = Source::new(Some(wasm), Some(CodeHash([0u8; 32])), language, compiler); | ||
| let contract = Contract::builder() | ||
| .name("incrementer".to_string()) | ||
| .version(Version::new(2, 1, 0)) | ||
|
|
@@ -507,7 +566,8 @@ mod tests { | |
| "source": { | ||
| "hash": "0x0000000000000000000000000000000000000000000000000000000000000000", | ||
| "language": "ink! 2.1.0", | ||
| "compiler": "rustc 1.46.0-nightly" | ||
| "compiler": "rustc 1.46.0-nightly", | ||
| "wasm": "0x000102" | ||
| }, | ||
| "contract": { | ||
| "name": "incrementer", | ||
|
|
@@ -544,7 +604,7 @@ mod tests { | |
| let language = SourceLanguage::new(Language::Ink, Version::new(2, 1, 0)); | ||
| let compiler = | ||
| SourceCompiler::new(Compiler::RustC, Version::parse("1.46.0-nightly").unwrap()); | ||
| let source = Source::new([0u8; 32], language, compiler); | ||
| let source = Source::new(None, Some(CodeHash([0u8; 32])), language, compiler); | ||
| let contract = Contract::builder() | ||
| .name("incrementer".to_string()) | ||
| .version(Version::new(2, 1, 0)) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should mention that this step also deploys (or will deploy) some custom checks that we implement on top besides just making sure that things compile for Wasm.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, but would only add it once we actually have some checks on top.