Skip to content

Commit

Permalink
sui-types: move to crates directory
Browse files Browse the repository at this point in the history
  • Loading branch information
bmwill committed May 16, 2022
1 parent 48f2840 commit 0caeabf
Show file tree
Hide file tree
Showing 34 changed files with 176 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
members = [
"crates/sui-config",
"crates/sui-network",
"crates/sui-types",
"crates/x",
"faucet",
"sui",
Expand All @@ -13,7 +14,6 @@ members = [
"sui_programmability/framework",
"sui_programmability/transactional-test-runner",
"sui_programmability/verifier",
"sui_types",
"test_utils",
]

Expand Down
2 changes: 1 addition & 1 deletion crates/sui-config/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ move-package = { git = "https://github.com/move-language/move", rev = "1b2d3b427

sui-framework = { path = "../../sui_programmability/framework" }
sui-adapter = { path = "../../sui_programmability/adapter" }
sui-types = { path = "../../sui_types" }
sui-types = { path = "../sui-types" }
2 changes: 1 addition & 1 deletion crates/sui-network/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ tonic = "0.7"
prost = "0.10"
bincode = "1.3.3"
serde = "1.0.136"
sui-types = { path = "../../sui_types" }
sui-types = { path = "../sui-types" }

mysten-network = { git = "https://github.com/MystenLabs/mysten-infra", rev = "7c247967e5a5abd59ecaa75bc62b05bcdf4503fe" }

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
165 changes: 165 additions & 0 deletions crates/sui-types/src/json_schema.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
// Copyright (c) 2022, Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

/// This file contains JsonSchema implementation for a few of the move types that is exposed through the GatewayAPI
/// These types are being use by `schemars` to create schema using the `#[schemars(with = "<type>")]` tag.
use crate::readable_serde::encoding;
use crate::readable_serde::Readable;
use schemars::gen::SchemaGenerator;
use schemars::schema::Schema;
use schemars::JsonSchema;
use serde::Deserialize;
use serde::Serialize;
use serde_with::serde_as;
use std::ops::Deref;
#[derive(Deserialize, Serialize)]
pub struct StructTag;

impl JsonSchema for StructTag {
fn schema_name() -> String {
"StructTag".to_string()
}

fn json_schema(gen: &mut SchemaGenerator) -> Schema {
#[derive(Deserialize, Serialize, JsonSchema)]
struct StructTag {
pub address: AccountAddress,
pub module: Identifier,
pub name: Identifier,
pub type_args: Vec<TypeTag>,
}
StructTag::json_schema(gen)
}
}
#[derive(Deserialize, Serialize)]
pub struct TypeTag;

impl JsonSchema for TypeTag {
fn schema_name() -> String {
"TypeTag".to_string()
}

fn json_schema(gen: &mut SchemaGenerator) -> Schema {
#[derive(Deserialize, Serialize, JsonSchema)]
#[serde(rename_all = "camelCase")]
enum TypeTag {
Bool,
U8,
U64,
U128,
Address,
Signer,
Vector(Box<TypeTag>),
Struct(StructTag),
}
TypeTag::json_schema(gen)
}
}

#[derive(Deserialize, Serialize)]
pub struct Identifier;

impl JsonSchema for Identifier {
fn schema_name() -> String {
"Identifier".to_string()
}

fn json_schema(gen: &mut SchemaGenerator) -> Schema {
#[derive(Serialize, Deserialize, JsonSchema)]
struct Identifier(Box<str>);
Identifier::json_schema(gen)
}
}
#[derive(Deserialize, Serialize, JsonSchema)]
pub struct AccountAddress(Hex);

#[serde_as]
#[derive(Deserialize, Serialize)]
pub struct Base64(#[serde_as(as = "Readable<encoding::Base64, _>")] pub Vec<u8>);

impl JsonSchema for Base64 {
fn schema_name() -> String {
"Base64".to_string()
}

fn json_schema(gen: &mut SchemaGenerator) -> Schema {
#[derive(Serialize, Deserialize, JsonSchema)]
struct Base64(String);
Base64::json_schema(gen)
}
}

impl Deref for Base64 {
type Target = [u8];

fn deref(&self) -> &Self::Target {
&self.0
}
}

#[derive(Deserialize, Serialize, JsonSchema)]
pub struct Hex(String);

#[derive(Deserialize, Serialize)]
pub struct MoveStructLayout;

impl JsonSchema for MoveStructLayout {
fn schema_name() -> String {
"MoveStructLayout".to_string()
}

fn json_schema(gen: &mut SchemaGenerator) -> Schema {
#[derive(Deserialize, Serialize, JsonSchema)]
enum MoveStructLayout {
Runtime(Vec<MoveTypeLayout>),
WithFields(Vec<MoveFieldLayout>),
WithTypes {
type_: StructTag,
fields: Vec<MoveFieldLayout>,
},
}
MoveStructLayout::json_schema(gen)
}
}

#[derive(Deserialize, Serialize)]
struct MoveTypeLayout;

impl JsonSchema for MoveTypeLayout {
fn schema_name() -> String {
"MoveTypeLayout".to_string()
}

fn json_schema(gen: &mut SchemaGenerator) -> Schema {
#[derive(Deserialize, Serialize, JsonSchema)]
#[serde(rename_all = "camelCase")]
enum MoveTypeLayout {
Bool,
U8,
U64,
U128,
Address,
Vector(Box<MoveTypeLayout>),
Struct(MoveStructLayout),
Signer,
}
MoveTypeLayout::json_schema(gen)
}
}
#[derive(Serialize, Deserialize)]
pub struct MoveFieldLayout;

impl JsonSchema for MoveFieldLayout {
fn schema_name() -> String {
"MoveFieldLayout".to_string()
}

fn json_schema(gen: &mut SchemaGenerator) -> Schema {
#[derive(Deserialize, Serialize, JsonSchema)]
struct MoveFieldLayout {
name: Identifier,
layout: MoveTypeLayout,
}
MoveFieldLayout::json_schema(gen)
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion faucet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ serde_json = "1.0.80"
tower = { version = "0.4.12", features = ["util", "timeout", "load-shed", "limit"] }

sui = { path = "../sui" }
sui-types = { path = "../sui_types" }
sui-types = { path = "../crates/sui-types" }
sui_core = { path = "../sui_core" }

[dev-dependencies]
Expand Down
2 changes: 1 addition & 1 deletion sui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ sui-adapter = { path = "../sui_programmability/adapter" }
sui-framework = { path = "../sui_programmability/framework" }
sui-network = { path = "../crates/sui-network" }
sui-config = { path = "../crates/sui-config" }
sui-types = { path = "../sui_types" }
sui-types = { path = "../crates/sui-types" }
sui-verifier = { path = "../sui_programmability/verifier" }
sui-open-rpc = { path = "open_rpc" }
sui-open-rpc-macros = { path = "open_rpc/macros" }
Expand Down
2 changes: 1 addition & 1 deletion sui_core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ once_cell = "1.10.0"
sui-adapter = { path = "../sui_programmability/adapter" }
sui-framework = { path = "../sui_programmability/framework" }
sui-network = { path = "../crates/sui-network" }
sui-types = { path = "../sui_types" }
sui-types = { path = "../crates/sui-types" }
sui-config = { path = "../crates/sui-config" }

move-binary-format = { git = "https://github.com/move-language/move", rev = "1b2d3b4274345f5b4b6a1a1bde5aee452003ab5b" }
Expand Down
2 changes: 1 addition & 1 deletion sui_programmability/adapter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ move-vm-types = { git = "https://github.com/move-language/move", rev = "1b2d3b42

sui-framework = { path = "../framework" }
sui-verifier = { path = "../verifier" }
sui-types = { path = "../../sui_types" }
sui-types = { path = "../../crates/sui-types" }

[dev-dependencies]
move-package = { git = "https://github.com/move-language/move", rev = "1b2d3b4274345f5b4b6a1a1bde5aee452003ab5b" }
2 changes: 1 addition & 1 deletion sui_programmability/framework/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ base64 = "0.13.0"
smallvec = "1.8.0"
num_enum = "0.5.7"

sui-types = { path = "../../sui_types" }
sui-types = { path = "../../crates/sui-types" }
sui-verifier = { path = "../verifier" }

move-binary-format = { git = "https://github.com/move-language/move", rev = "1b2d3b4274345f5b4b6a1a1bde5aee452003ab5b" }
Expand Down
2 changes: 1 addition & 1 deletion sui_programmability/transactional-test-runner/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ move-vm-types = { git = "https://github.com/move-language/move", rev = "1b2d3b42

sui-framework = { path = "../framework" }
sui-verifier = { path = "../verifier" }
sui-types = { path = "../../sui_types" }
sui-types = { path = "../../crates/sui-types" }
sui-adapter = { path = "../adapter" }
sui_core = { path = "../../sui_core" }
2 changes: 1 addition & 1 deletion sui_programmability/verifier/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ move-core-types = { git = "https://github.com/move-language/move", rev = "1b2d3b
move-disassembler = { git = "https://github.com/move-language/move", rev = "1b2d3b4274345f5b4b6a1a1bde5aee452003ab5b" }
move-ir-types = { git = "https://github.com/move-language/move", rev = "1b2d3b4274345f5b4b6a1a1bde5aee452003ab5b" }

sui-types = { path = "../../sui_types" }
sui-types = { path = "../../crates/sui-types" }
2 changes: 1 addition & 1 deletion test_utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ typed-store = { git = "https://github.com/MystenLabs/mysten-infra", rev ="7c2479
narwhal-config = { git = "https://github.com/MystenLabs/narwhal", rev = "23745f48103656eae4a4205d0b3edd53ad8894de", package = "config" }

sui-config = { path = "../crates/sui-config" }
sui-types = { path = "../sui_types" }
sui-types = { path = "../crates/sui-types" }
sui_core = { path = "../sui_core" }
sui-network = { path = "../crates/sui-network" }
sui = { path = "../sui" }

0 comments on commit 0caeabf

Please sign in to comment.