-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
219 additions
and
52 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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,55 @@ | ||
// Internal imports | ||
|
||
use arcade_slot::helpers::json::{JsonifiableString, JsonifiableTrait}; | ||
|
||
// Constants | ||
|
||
const COLOR_LENGTH: usize = 7; | ||
|
||
#[derive(Clone, Drop)] | ||
pub struct Metadata { | ||
color: felt252, | ||
name: ByteArray, | ||
description: ByteArray, | ||
image: ByteArray, | ||
banner: ByteArray, | ||
} | ||
|
||
// Implementations | ||
|
||
pub impl MetadataJsonifiable of JsonifiableTrait<Metadata> { | ||
fn jsonify(self: Metadata) -> ByteArray { | ||
let mut color = ""; | ||
color.append_word(self.color, COLOR_LENGTH); | ||
let mut string = "{"; | ||
string += JsonifiableString::jsonify("color", format!("{}", color)); | ||
string += "," + JsonifiableString::jsonify("name", format!("{}", self.name)); | ||
string += "," + JsonifiableString::jsonify("description", format!("{}", self.description)); | ||
string += "," + JsonifiableString::jsonify("image", format!("{}", self.image)); | ||
string += "," + JsonifiableString::jsonify("banner", format!("{}", self.banner)); | ||
string + "}" | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
// Local imports | ||
|
||
use super::{Metadata, JsonifiableTrait}; | ||
|
||
#[test] | ||
fn test_metadata_jsonify() { | ||
let metadata = Metadata { | ||
color: '#123456', | ||
name: "name", | ||
description: "description", | ||
image: "image", | ||
banner: "banner", | ||
}; | ||
let json = metadata.jsonify(); | ||
assert_eq!( | ||
json, | ||
"{\"color\":\"#123456\",\"name\":\"name\",\"description\":\"description\",\"image\":\"image\",\"banner\":\"banner\"}" | ||
); | ||
} | ||
} |
Oops, something went wrong.