Skip to content

Commit

Permalink
Update to betanet-v2-da72287e6
Browse files Browse the repository at this point in the history
  • Loading branch information
0xOmarA committed Feb 13, 2023
1 parent 9a70e72 commit d6dbcea
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 41 deletions.
10 changes: 5 additions & 5 deletions radix-engine-toolkit/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ schemars = { version = "0.8.11", features = ["preserve_order"] }
serializable = { path = "../serializable" }

# Scrypto dependencies required for the core-toolkit
sbor = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "betanet-v2-c816729" }
scrypto = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "betanet-v2-c816729" }
scrypto_utils = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "betanet-v2-c816729", package = "utils" }
native_transaction = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "betanet-v2-c816729", package = "transaction" }
radix-engine-constants = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "betanet-v2-c816729" }
sbor = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "betanet-v2-da72287e6" }
scrypto = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "betanet-v2-da72287e6" }
scrypto_utils = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "betanet-v2-da72287e6", package = "utils" }
native_transaction = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "betanet-v2-da72287e6", package = "transaction" }
radix-engine-constants = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "betanet-v2-da72287e6" }

# Hex is used for the internal hex encoding and decoding of values - serde_with::Hex is used for the
# hex representation during serialization.
Expand Down
9 changes: 9 additions & 0 deletions radix-engine-toolkit/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,12 @@ pub enum Error {
/// for processing.
UnrecognizedAddressFormat,

/// An error emitted when the validation of the content of a Scrypto type fails. Currently,
/// this is emitted if the validation of non-fungible local ids fails.
ContentValidationError {
message: String,
},

// =========
// Requests
// =========
Expand Down Expand Up @@ -199,6 +205,9 @@ generate_from_error!(std::str::Utf8Error as InvalidRequestString);
generate_from_error!(
native_transaction::manifest::generator::GeneratorError as ManifestGenerationError
);
generate_from_error!(
scrypto::radix_engine_interface::model::ContentValidationError as ContentValidationError
);

macro_rules! impl_from_parse_error {
($($error_type: ty => $kind: ident,)*) => {
Expand Down
44 changes: 31 additions & 13 deletions radix-engine-toolkit/src/model/address/non_fungible_local_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,15 @@
// specific language governing permissions and limitations
// under the License.

use scrypto::prelude::NonFungibleLocalId as ScryptoNonFungibleLocalId;
use scrypto::prelude::{
BytesNonFungibleLocalId, IntegerNonFungibleLocalId,
NonFungibleLocalId as ScryptoNonFungibleLocalId, StringNonFungibleLocalId,
UUIDNonFungibleLocalId,
};
use serializable::serializable;

use crate::{Error, Result};

#[serializable]
#[serde(tag = "type", content = "value")]
/// Represents non-fungible ids which is a discriminated union of the different types that
Expand Down Expand Up @@ -54,24 +60,36 @@ pub enum NonFungibleLocalId {
String(#[schemars(length(min = 1, max = 64))] String),
}

impl From<ScryptoNonFungibleLocalId> for NonFungibleLocalId {
fn from(value: ScryptoNonFungibleLocalId) -> Self {
impl TryFrom<ScryptoNonFungibleLocalId> for NonFungibleLocalId {
type Error = Error;

fn try_from(value: ScryptoNonFungibleLocalId) -> Result<Self> {
match value {
ScryptoNonFungibleLocalId::Integer(value) => Self::Integer(value),
ScryptoNonFungibleLocalId::UUID(value) => Self::UUID(value),
ScryptoNonFungibleLocalId::String(value) => Self::String(value),
ScryptoNonFungibleLocalId::Bytes(value) => Self::Bytes(value),
ScryptoNonFungibleLocalId::Integer(value) => Ok(Self::Integer(value.value())),
ScryptoNonFungibleLocalId::UUID(value) => Ok(Self::UUID(value.value())),
ScryptoNonFungibleLocalId::String(value) => Ok(Self::String(value.value().to_owned())),
ScryptoNonFungibleLocalId::Bytes(value) => Ok(Self::Bytes(value.value().to_owned())),
}
}
}

impl From<NonFungibleLocalId> for ScryptoNonFungibleLocalId {
fn from(value: NonFungibleLocalId) -> Self {
impl TryFrom<NonFungibleLocalId> for ScryptoNonFungibleLocalId {
type Error = Error;

fn try_from(value: NonFungibleLocalId) -> Result<Self> {
match value {
NonFungibleLocalId::Integer(value) => Self::Integer(value),
NonFungibleLocalId::UUID(value) => Self::UUID(value),
NonFungibleLocalId::String(value) => Self::String(value),
NonFungibleLocalId::Bytes(value) => Self::Bytes(value),
NonFungibleLocalId::Integer(value) => {
Ok(Self::Integer(IntegerNonFungibleLocalId::new(value)))
}
NonFungibleLocalId::UUID(value) => UUIDNonFungibleLocalId::new(value)
.map(Self::UUID)
.map_err(Error::from),
NonFungibleLocalId::String(value) => StringNonFungibleLocalId::new(value)
.map(Self::String)
.map_err(Error::from),
NonFungibleLocalId::Bytes(value) => BytesNonFungibleLocalId::new(value)
.map(Self::Bytes)
.map_err(Error::from),
}
}
}
2 changes: 1 addition & 1 deletion radix-engine-toolkit/src/model/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ pub enum Value {
/// non-fungible ids may be.
NonFungibleLocalId {
#[schemars(with = "crate::NonFungibleLocalId")]
#[serde_as(as = "serde_with::FromInto<crate::NonFungibleLocalId>")]
#[serde_as(as = "serde_with::TryFromInto<crate::NonFungibleLocalId>")]
value: NonFungibleLocalId,
},

Expand Down
5 changes: 3 additions & 2 deletions radix-engine-toolkit/tests/aliasing.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use radix_engine_toolkit::{
model::Value, traverse_value, NonFungibleGlobalId, ValueAliasingVisitor, ValueKind,
};
use scrypto::prelude::IntegerNonFungibleLocalId;

#[test]
fn aliasing_of_deeply_nested_structures_works() {
Expand Down Expand Up @@ -37,7 +38,7 @@ fn aliasing_of_deeply_nested_structures_works() {
element_kind: ValueKind::Tuple,
elements: vec![Value::Tuple { elements: vec![
Value::ResourceAddress { address: "resource_sim1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqz8qety".parse().unwrap() },
Value::NonFungibleLocalId { value: scrypto::prelude::NonFungibleLocalId::Integer(1) } ,
Value::NonFungibleLocalId { value: scrypto::prelude::NonFungibleLocalId::Integer(IntegerNonFungibleLocalId::new(1)) } ,
] }],
}],
}],
Expand Down Expand Up @@ -80,7 +81,7 @@ fn aliasing_of_deeply_nested_structures_works() {
element_kind: ValueKind::Tuple,
elements: vec![Value::NonFungibleGlobalId { address: NonFungibleGlobalId {
resource_address: "resource_sim1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqz8qety".parse().unwrap(),
non_fungible_local_id: scrypto::prelude::NonFungibleLocalId::Integer(1)
non_fungible_local_id: scrypto::prelude::NonFungibleLocalId::Integer(IntegerNonFungibleLocalId::new(1))
} }],
}],
}],
Expand Down
12 changes: 6 additions & 6 deletions radix-engine-toolkit/tests/test_vector/instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ lazy_static::lazy_static! {
},
},
ids: vec![Value::NonFungibleLocalId {
value: scrypto::prelude::NonFungibleLocalId::Integer(1),
value: scrypto::prelude::NonFungibleLocalId::Integer(IntegerNonFungibleLocalId::new(1)),
}],
into_bucket: Value::Bucket {
identifier: BucketId(TransientIdentifier::String { value: "ident".into() }),
Expand Down Expand Up @@ -410,7 +410,7 @@ lazy_static::lazy_static! {
},
},
ids: vec![Value::NonFungibleLocalId {
value: scrypto::prelude::NonFungibleLocalId::Integer(1),
value: scrypto::prelude::NonFungibleLocalId::Integer(IntegerNonFungibleLocalId::new(1)),
}],
},
r#"
Expand Down Expand Up @@ -579,7 +579,7 @@ lazy_static::lazy_static! {
},
},
ids: vec![Value::NonFungibleLocalId {
value: scrypto::prelude::NonFungibleLocalId::Integer(1),
value: scrypto::prelude::NonFungibleLocalId::Integer(IntegerNonFungibleLocalId::new(1)),
}],
into_proof: Value::Proof {
identifier: ProofId(TransientIdentifier::String { value: "ident".into() }),
Expand Down Expand Up @@ -819,7 +819,7 @@ lazy_static::lazy_static! {
network_id: 0xf2,
address: RADIX_TOKEN,
},
non_fungible_local_id: NonFungibleLocalId::Integer(1),
non_fungible_local_id: NonFungibleLocalId::Integer(IntegerNonFungibleLocalId::new(1)),
},
},
},
Expand Down Expand Up @@ -1353,7 +1353,7 @@ lazy_static::lazy_static! {
network_id: 0xf2,
address: RADIX_TOKEN,
},
non_fungible_local_id: NonFungibleLocalId::Integer(1),
non_fungible_local_id: NonFungibleLocalId::Integer(IntegerNonFungibleLocalId::new(1)),
},
},
initial_supply: Value::None,
Expand Down Expand Up @@ -1468,7 +1468,7 @@ lazy_static::lazy_static! {
network_id: 0xf2,
address: RADIX_TOKEN,
},
non_fungible_local_id: NonFungibleLocalId::Integer(1),
non_fungible_local_id: NonFungibleLocalId::Integer(IntegerNonFungibleLocalId::new(1)),
},
},
initial_supply: Value::None,
Expand Down
21 changes: 12 additions & 9 deletions radix-engine-toolkit/tests/test_vector/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ use native_transaction::manifest::generator::{generate_value, NameResolver};
use native_transaction::manifest::lexer::tokenize;
use radix_engine_toolkit::{address::*, BucketId, ProofId, TransientIdentifier};
use radix_engine_toolkit::{Value, ValueKind};
use scrypto::prelude::{Hash, ScryptoValue};
use scrypto::prelude::{
BytesNonFungibleLocalId, Hash, IntegerNonFungibleLocalId, ScryptoValue,
StringNonFungibleLocalId, UUIDNonFungibleLocalId,
};
use scrypto::runtime::ManifestBlobRef;
extern crate lazy_static;

Expand Down Expand Up @@ -346,22 +349,22 @@ lazy_static::lazy_static! {
// ==========================

ValueRepresentationTestVector::new(
Value::NonFungibleLocalId { value: scrypto::prelude::NonFungibleLocalId::Integer(114441894733333) },
Value::NonFungibleLocalId { value: scrypto::prelude::NonFungibleLocalId::Integer(IntegerNonFungibleLocalId::new(114441894733333)) },
r#"{"type": "NonFungibleLocalId", "value": {"type": "Integer", "value": "114441894733333"}}"#,
"NonFungibleLocalId(\"#114441894733333#\")"
),
ValueRepresentationTestVector::new(
Value::NonFungibleLocalId { value: scrypto::prelude::NonFungibleLocalId::UUID(238510006928098330588051703199685491739) },
Value::NonFungibleLocalId { value: scrypto::prelude::NonFungibleLocalId::UUID(UUIDNonFungibleLocalId::new(238510006928098330588051703199685491739).unwrap()) },
r#"{"type": "NonFungibleLocalId", "value": {"type": "UUID", "value": "238510006928098330588051703199685491739"}}"#,
r#"NonFungibleLocalId("{b36f5b3f-835b-406c-980f-7788d8f13c1b}")"#,
),
ValueRepresentationTestVector::new(
Value::NonFungibleLocalId { value: scrypto::prelude::NonFungibleLocalId::String("hello_world".into()) },
Value::NonFungibleLocalId { value: scrypto::prelude::NonFungibleLocalId::String(StringNonFungibleLocalId::new("hello_world".into()).unwrap()) },
r#"{"type": "NonFungibleLocalId", "value": {"type": "String", "value": "hello_world"}}"#,
r#"NonFungibleLocalId("<hello_world>")"#,
),
ValueRepresentationTestVector::new(
Value::NonFungibleLocalId { value: scrypto::prelude::NonFungibleLocalId::Bytes(vec![0x10, 0xa2, 0x31, 0x01]) },
Value::NonFungibleLocalId { value: scrypto::prelude::NonFungibleLocalId::Bytes(BytesNonFungibleLocalId::new(vec![0x10, 0xa2, 0x31, 0x01]).unwrap()) },
r#"{"type": "NonFungibleLocalId", "value": {"type": "Bytes", "value": "10a23101"}}"#,
r#"NonFungibleLocalId("[10a23101]")"#,
),
Expand All @@ -373,7 +376,7 @@ lazy_static::lazy_static! {
network_id: 0xf2,
address: scrypto::prelude::ResourceAddress::Normal([0; 26]),
},
non_fungible_local_id: scrypto::prelude::NonFungibleLocalId::Integer(114441894733333)
non_fungible_local_id: scrypto::prelude::NonFungibleLocalId::Integer(IntegerNonFungibleLocalId::new(114441894733333))
}
},
r#"{"type": "NonFungibleGlobalId", "resource_address": {"type": "ResourceAddress", "address": "resource_sim1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqz8qety"}, "non_fungible_local_id": {"type": "NonFungibleLocalId", "value": {"type": "Integer", "value": "114441894733333"}}}"#,
Expand All @@ -386,7 +389,7 @@ lazy_static::lazy_static! {
network_id: 0xf2,
address: scrypto::prelude::ResourceAddress::Normal([0; 26]),
},
non_fungible_local_id: scrypto::prelude::NonFungibleLocalId::UUID(238510006928098330588051703199685491739)
non_fungible_local_id: scrypto::prelude::NonFungibleLocalId::UUID(UUIDNonFungibleLocalId::new(238510006928098330588051703199685491739).unwrap())
}
},
r#"{"type": "NonFungibleGlobalId", "resource_address": {"type": "ResourceAddress", "address": "resource_sim1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqz8qety"}, "non_fungible_local_id": {"type": "NonFungibleLocalId", "value": {"type": "UUID", "value": "238510006928098330588051703199685491739"}}}"#,
Expand All @@ -399,7 +402,7 @@ lazy_static::lazy_static! {
network_id: 0xf2,
address: scrypto::prelude::ResourceAddress::Normal([0; 26]),
},
non_fungible_local_id: scrypto::prelude::NonFungibleLocalId::String("hello_world".into())
non_fungible_local_id: scrypto::prelude::NonFungibleLocalId::String(StringNonFungibleLocalId::new("hello_world".into()).unwrap())
}
},
r#"{"type": "NonFungibleGlobalId", "resource_address": {"type": "ResourceAddress", "address": "resource_sim1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqz8qety"}, "non_fungible_local_id": {"type": "NonFungibleLocalId", "value": {"type": "String", "value": "hello_world"}}}"#,
Expand All @@ -412,7 +415,7 @@ lazy_static::lazy_static! {
network_id: 0xf2,
address: scrypto::prelude::ResourceAddress::Normal([0; 26]),
},
non_fungible_local_id: scrypto::prelude::NonFungibleLocalId::Bytes(vec![0x10, 0xa2, 0x31, 0x01])
non_fungible_local_id: scrypto::prelude::NonFungibleLocalId::Bytes(BytesNonFungibleLocalId::new(vec![0x10, 0xa2, 0x31, 0x01]).unwrap())
}
},
r#"{"type": "NonFungibleGlobalId", "resource_address": {"type": "ResourceAddress", "address": "resource_sim1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqz8qety"}, "non_fungible_local_id": {"type": "NonFungibleLocalId", "value": {"type": "Bytes", "value": "10a23101"}}}"#,
Expand Down
10 changes: 5 additions & 5 deletions schema/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ radix-engine-toolkit = { path = "../radix-engine-toolkit" }
serde = "1.0.152"
convert_case = "0.6.0"

sbor = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "betanet-v2-c816729" }
scrypto = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "betanet-v2-c816729" }
scrypto_utils = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "betanet-v2-c816729", package = "utils" }
native_transaction = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "betanet-v2-c816729", package = "transaction" }
radix-engine-constants = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "betanet-v2-c816729" }
sbor = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "betanet-v2-da72287e6" }
scrypto = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "betanet-v2-da72287e6" }
scrypto_utils = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "betanet-v2-da72287e6", package = "utils" }
native_transaction = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "betanet-v2-da72287e6", package = "transaction" }
radix-engine-constants = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "betanet-v2-da72287e6" }

0 comments on commit d6dbcea

Please sign in to comment.