From d6dbcead25e6e7cc2fb229e3b1ef79ea6371f423 Mon Sep 17 00:00:00 2001 From: Omar Date: Mon, 13 Feb 2023 16:59:16 +0300 Subject: [PATCH] Update to betanet-v2-da72287e6 --- radix-engine-toolkit/Cargo.toml | 10 ++--- radix-engine-toolkit/src/error.rs | 9 ++++ .../model/address/non_fungible_local_id.rs | 44 +++++++++++++------ radix-engine-toolkit/src/model/value.rs | 2 +- radix-engine-toolkit/tests/aliasing.rs | 5 ++- .../tests/test_vector/instruction.rs | 12 ++--- .../tests/test_vector/value.rs | 21 +++++---- schema/Cargo.toml | 10 ++--- 8 files changed, 72 insertions(+), 41 deletions(-) diff --git a/radix-engine-toolkit/Cargo.toml b/radix-engine-toolkit/Cargo.toml index ba8069d5..c76e1fac 100644 --- a/radix-engine-toolkit/Cargo.toml +++ b/radix-engine-toolkit/Cargo.toml @@ -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. diff --git a/radix-engine-toolkit/src/error.rs b/radix-engine-toolkit/src/error.rs index 340732aa..f478599c 100644 --- a/radix-engine-toolkit/src/error.rs +++ b/radix-engine-toolkit/src/error.rs @@ -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 // ========= @@ -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,)*) => { diff --git a/radix-engine-toolkit/src/model/address/non_fungible_local_id.rs b/radix-engine-toolkit/src/model/address/non_fungible_local_id.rs index 44c0cf6d..404ae03c 100644 --- a/radix-engine-toolkit/src/model/address/non_fungible_local_id.rs +++ b/radix-engine-toolkit/src/model/address/non_fungible_local_id.rs @@ -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 @@ -54,24 +60,36 @@ pub enum NonFungibleLocalId { String(#[schemars(length(min = 1, max = 64))] String), } -impl From for NonFungibleLocalId { - fn from(value: ScryptoNonFungibleLocalId) -> Self { +impl TryFrom for NonFungibleLocalId { + type Error = Error; + + fn try_from(value: ScryptoNonFungibleLocalId) -> Result { 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 for ScryptoNonFungibleLocalId { - fn from(value: NonFungibleLocalId) -> Self { +impl TryFrom for ScryptoNonFungibleLocalId { + type Error = Error; + + fn try_from(value: NonFungibleLocalId) -> Result { 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), } } } diff --git a/radix-engine-toolkit/src/model/value.rs b/radix-engine-toolkit/src/model/value.rs index 56facec0..4ab43980 100644 --- a/radix-engine-toolkit/src/model/value.rs +++ b/radix-engine-toolkit/src/model/value.rs @@ -300,7 +300,7 @@ pub enum Value { /// non-fungible ids may be. NonFungibleLocalId { #[schemars(with = "crate::NonFungibleLocalId")] - #[serde_as(as = "serde_with::FromInto")] + #[serde_as(as = "serde_with::TryFromInto")] value: NonFungibleLocalId, }, diff --git a/radix-engine-toolkit/tests/aliasing.rs b/radix-engine-toolkit/tests/aliasing.rs index cf0badc2..949fb480 100644 --- a/radix-engine-toolkit/tests/aliasing.rs +++ b/radix-engine-toolkit/tests/aliasing.rs @@ -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() { @@ -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)) } , ] }], }], }], @@ -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)) } }], }], }], diff --git a/radix-engine-toolkit/tests/test_vector/instruction.rs b/radix-engine-toolkit/tests/test_vector/instruction.rs index d0a013e8..68b84ec2 100644 --- a/radix-engine-toolkit/tests/test_vector/instruction.rs +++ b/radix-engine-toolkit/tests/test_vector/instruction.rs @@ -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() }), @@ -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#" @@ -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() }), @@ -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)), }, }, }, @@ -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, @@ -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, diff --git a/radix-engine-toolkit/tests/test_vector/value.rs b/radix-engine-toolkit/tests/test_vector/value.rs index 6c102cd1..384d00f4 100644 --- a/radix-engine-toolkit/tests/test_vector/value.rs +++ b/radix-engine-toolkit/tests/test_vector/value.rs @@ -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; @@ -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("")"#, ), 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]")"#, ), @@ -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"}}}"#, @@ -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"}}}"#, @@ -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"}}}"#, @@ -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"}}}"#, diff --git a/schema/Cargo.toml b/schema/Cargo.toml index 23602b53..aa6aaa9f 100644 --- a/schema/Cargo.toml +++ b/schema/Cargo.toml @@ -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" } \ No newline at end of file +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" } \ No newline at end of file