-
Notifications
You must be signed in to change notification settings - Fork 3
fix: Remove unimplemented publish type #321
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
7b28bb1
fix: Remove unimplemented publish type
DaughterOfMars 47d52a3
impl FFI type
DaughterOfMars 9181f5b
add upgrade policy
DaughterOfMars edf6738
clippy
DaughterOfMars 599f112
compatible
DaughterOfMars 82723e5
Merge branch 'sdk-bindings' into fix/remove-package-kind
DaughterOfMars ebaa124
missed extra param
DaughterOfMars 225b76a
docs
DaughterOfMars e1e96d9
Merge branch 'sdk-bindings' into fix/remove-package-kind
thibault-martinez File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,131 @@ | ||
| // Copyright 2025 IOTA Stiftung | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| use crate::{Digest, ObjectId}; | ||
|
|
||
| /// Type corresponding to the output of `iota move build | ||
| /// --dump-bytecode-as-base64` | ||
| #[derive(Clone, Debug)] | ||
| #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] | ||
| pub struct MovePackageData { | ||
| /// The package modules as a series of bytes | ||
| #[cfg_attr(feature = "serde", serde(with = "serialization::modules"))] | ||
| pub modules: Vec<Vec<u8>>, | ||
| /// The package dependencies, specified by their object IDs. | ||
| pub dependencies: Vec<ObjectId>, | ||
| /// The package digest. | ||
| #[cfg_attr(feature = "serde", serde(with = "serialization::digest"))] | ||
| pub digest: Digest, | ||
| } | ||
|
|
||
| impl MovePackageData { | ||
| #[cfg(feature = "hash")] | ||
| pub fn new(modules: Vec<Vec<u8>>, dependencies: Vec<ObjectId>) -> Self { | ||
| use crate::hash::Hasher; | ||
| let mut components = dependencies | ||
| .iter() | ||
| .map(|o| o.into_inner()) | ||
| .chain(modules.iter().map(|module| { | ||
| let mut hasher = Hasher::new(); | ||
| hasher.update(module); | ||
| hasher.finalize().into_inner() | ||
| })) | ||
| .collect::<Vec<_>>(); | ||
|
|
||
| // Sort so the order of the modules and the order of the dependencies | ||
| // does not matter. | ||
| components.sort(); | ||
|
|
||
| let mut hasher = Hasher::new(); | ||
| for c in components { | ||
| hasher.update(c); | ||
| } | ||
|
|
||
| Self { | ||
| modules, | ||
| dependencies, | ||
| digest: Digest::from(hasher.finalize().into_inner()), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| #[cfg(feature = "serde")] | ||
| mod serialization { | ||
| use base64ct::Encoding; | ||
| use serde::{Deserialize, Deserializer, Serialize, Serializer}; | ||
|
|
||
| use super::*; | ||
|
|
||
| impl MovePackageData { | ||
| pub fn to_base64(&self) -> String { | ||
| base64ct::Base64::encode_string(&bcs::to_bytes(self).expect("bcs encoding failed")) | ||
| } | ||
|
|
||
| pub fn from_base64(base64: &str) -> Result<Self, bcs::Error> { | ||
| use serde::de::Error; | ||
| bcs::from_bytes(&base64ct::Base64::decode_vec(base64).map_err(bcs::Error::custom)?) | ||
| } | ||
| } | ||
|
|
||
| pub mod modules { | ||
| use super::*; | ||
|
|
||
| pub fn serialize<S: Serializer>( | ||
| value: &Vec<Vec<u8>>, | ||
| serializer: S, | ||
| ) -> Result<S::Ok, S::Error> { | ||
| value | ||
| .iter() | ||
| .map(|v| base64ct::Base64::encode_string(v)) | ||
| .collect::<Vec<_>>() | ||
| .serialize(serializer) | ||
| } | ||
|
|
||
| pub fn deserialize<'de, D>(deserializer: D) -> Result<Vec<Vec<u8>>, D::Error> | ||
| where | ||
| D: Deserializer<'de>, | ||
| { | ||
| let bcs = Vec::<String>::deserialize(deserializer)?; | ||
| bcs.into_iter() | ||
| .map(|s| base64ct::Base64::decode_vec(&s).map_err(serde::de::Error::custom)) | ||
| .collect() | ||
| } | ||
| } | ||
|
|
||
| pub mod digest { | ||
| use super::*; | ||
|
|
||
| pub fn serialize<S: Serializer>(value: &Digest, serializer: S) -> Result<S::Ok, S::Error> { | ||
| value.as_bytes().serialize(serializer) | ||
| } | ||
|
|
||
| pub fn deserialize<'de, D>(deserializer: D) -> Result<Digest, D::Error> | ||
| where | ||
| D: Deserializer<'de>, | ||
| { | ||
| let bytes = Vec::<u8>::deserialize(deserializer)?; | ||
| Digest::from_bytes(bytes).map_err(|e| serde::de::Error::custom(format!("{e}"))) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
|
|
||
| const PACKAGE: &str = r#"{"modules":["oRzrCwYAAAAKAQAIAggUAxw+BFoGBWBBB6EBwQEI4gJACqIDGgy8A5cBDdMEBgAKAQ0BEwEUAAIMAAABCAAAAAgAAQQEAAMDAgAACAABAAAJAgMAABACAwAAEgQDAAAMBQYAAAYHAQAAEQgBAAAFCQoAAQsACwACDg8BAQwCEw8BAQgDDwwNAAoOCgYJBgEHCAQAAQYIAAEDAQYIAQQHCAEDAwcIBAEIAAQDAwUHCAQDCAAFBwgEAgMHCAQBCAIBCAMBBggEAQUBCAECCQAFBkNvbmZpZwVGb3JnZQVTd29yZAlUeENvbnRleHQDVUlEDWNyZWF0ZV9jb25maWcMY3JlYXRlX3N3b3JkAmlkBGluaXQFbWFnaWMJbXlfbW9kdWxlA25ldwluZXdfc3dvcmQGb2JqZWN0D3B1YmxpY190cmFuc2ZlcgZzZW5kZXIIc3RyZW5ndGgOc3dvcmRfdHJhbnNmZXIOc3dvcmRzX2NyZWF0ZWQIdHJhbnNmZXIKdHhfY29udGV4dAV2YWx1ZQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAIAAgMHCAMJAxADAQICBwgDEgMCAgIHCAMVAwAAAAABCQoAEQgGAAAAAAAAAAASAQsALhELOAACAQEAAAEECwAQABQCAgEAAAEECwAQARQCAwEAAAEECwAQAhQCBAEAAAEOCgAQAhQGAQAAAAAAAAAWCwAPAhULAxEICwELAhIAAgUBAAABCAsDEQgLAAsBEgALAjgBAgYBAAABBAsACwE4AgIHAQAAAQULAREICwASAgIAAQACAQEA"],"dependencies":["0x0000000000000000000000000000000000000000000000000000000000000002","0x0000000000000000000000000000000000000000000000000000000000000001"],"digest":[246,127,102,77,186,19,68,12,161,181,56,248,210,0,91,211,245,251,165,152,0,197,250,135,171,37,177,240,133,76,122,124]}"#; | ||
|
|
||
| #[test] | ||
| fn test_serialization() { | ||
| let package: MovePackageData = serde_json::from_str(PACKAGE).unwrap(); | ||
| let new_json = serde_json::to_string(&package).unwrap(); | ||
| assert_eq!(new_json, PACKAGE); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_digest() { | ||
| let json_package: MovePackageData = serde_json::from_str(PACKAGE).unwrap(); | ||
| let package = MovePackageData::new(json_package.modules, json_package.dependencies); | ||
| assert_eq!(json_package.digest, package.digest); | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.