Skip to content

Commit

Permalink
Deprecate sui move utf8 (MystenLabs#4278)
Browse files Browse the repository at this point in the history
* deprecate utf8.move
  • Loading branch information
oxade authored Aug 25, 2022
1 parent d027c4f commit 94e5bca
Show file tree
Hide file tree
Showing 12 changed files with 50 additions and 90 deletions.

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions crates/sui-core/src/unit_tests/event_handler_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use sui_json_rpc_types::SuiMoveStruct;

use sui_types::base_types::ObjectID;
use sui_types::gas_coin::GasCoin;
use sui_types::SUI_FRAMEWORK_ADDRESS;
use sui_types::{MOVE_STDLIB_ADDRESS, SUI_FRAMEWORK_ADDRESS};

#[test]
fn test_to_json_value() {
Expand Down Expand Up @@ -105,7 +105,7 @@ impl TestEvent {
}
}

// Rust version of the Move sui::utf8::String type
// Rust version of the Move std::string::String type
// TODO: Do we need this in the sui-types lib?
#[derive(Debug, Serialize, Deserialize, Clone, Eq, PartialEq)]
struct UTF8String {
Expand All @@ -123,9 +123,9 @@ impl From<&str> for UTF8String {
impl UTF8String {
fn type_() -> StructTag {
StructTag {
address: SUI_FRAMEWORK_ADDRESS,
address: MOVE_STDLIB_ADDRESS,
name: Identifier::new("String").unwrap(),
module: Identifier::new("utf8").unwrap(),
module: Identifier::new("string").unwrap(),
type_params: vec![],
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,39 @@ source: crates/sui-cost/tests/snapshot_tests.rs
expression: common_costs
---
Publish:
computationCost: 526
computationCost: 521
storageCost: 83
storageRebate: 16
MergeCoin:
computationCost: 468
computationCost: 463
storageCost: 32
storageRebate: 0
? SplitCoin: 0
: computationCost: 451
: computationCost: 446
storageCost: 32
storageRebate: 0
? SplitCoin: 1
: computationCost: 494
: computationCost: 488
storageCost: 48
storageRebate: 0
? SplitCoin: 2
: computationCost: 536
: computationCost: 531
storageCost: 64
storageRebate: 0
? SplitCoin: 3
: computationCost: 579
: computationCost: 574
storageCost: 80
storageRebate: 0
? SplitCoinEqual: 1
: computationCost: 460
: computationCost: 455
storageCost: 32
storageRebate: 0
? SplitCoinEqual: 2
: computationCost: 500
: computationCost: 495
storageCost: 48
storageRebate: 0
? SplitCoinEqual: 3
: computationCost: 541
: computationCost: 536
storageCost: 64
storageRebate: 0
TransferWholeCoin:
Expand Down
22 changes: 11 additions & 11 deletions crates/sui-framework/sources/devnet_nft.move
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
/// `wallet example-nft --name <Name> --description <Description> --url <URL>`
module sui::devnet_nft {
use sui::url::{Self, Url};
use sui::utf8;
use std::string;
use sui::object::{Self, ID, UID};
use sui::event;
use sui::transfer;
Expand All @@ -17,9 +17,9 @@ module sui::devnet_nft {
struct DevNetNFT has key, store {
id: UID,
/// Name for the token
name: utf8::String,
name: string::String,
/// Description of the token
description: utf8::String,
description: string::String,
/// URL for the token
url: Url,
// TODO: allow custom attributes
Expand All @@ -31,7 +31,7 @@ module sui::devnet_nft {
// The creator of the NFT
creator: address,
// The name of the NFT
name: utf8::String,
name: string::String,
}

/// Create a new devnet_nft
Expand All @@ -43,8 +43,8 @@ module sui::devnet_nft {
) {
let nft = DevNetNFT {
id: object::new(ctx),
name: utf8::string_unsafe(name),
description: utf8::string_unsafe(description),
name: string::utf8(name),
description: string::utf8(description),
url: url::new_unsafe_from_bytes(url)
};
let sender = tx_context::sender(ctx);
Expand All @@ -62,7 +62,7 @@ module sui::devnet_nft {
new_description: vector<u8>,
_: &mut TxContext
) {
nft.description = utf8::string_unsafe(new_description)
nft.description = string::utf8(new_description)
}

/// Permanently delete `nft`
Expand All @@ -72,12 +72,12 @@ module sui::devnet_nft {
}

/// Get the NFT's `name`
public fun name(nft: &DevNetNFT): &utf8::String {
public fun name(nft: &DevNetNFT): &string::String {
&nft.name
}

/// Get the NFT's `description`
public fun description(nft: &DevNetNFT): &utf8::String {
public fun description(nft: &DevNetNFT): &string::String {
&nft.description
}

Expand All @@ -92,7 +92,7 @@ module sui::devnet_nftTests {
use sui::devnet_nft::{Self, DevNetNFT};
use sui::test_scenario;
use sui::transfer;
use sui::utf8;
use std::string;

#[test]
fun mint_transfer_update() {
Expand All @@ -114,7 +114,7 @@ module sui::devnet_nftTests {
{
let nft = test_scenario::take_owned<DevNetNFT>(&mut scenario);
devnet_nft::update_description(&mut nft, b"a new description", test_scenario::ctx(&mut scenario)) ;
assert!(*utf8::bytes(devnet_nft::description(&nft)) == b"a new description", 0);
assert!(*string::bytes(devnet_nft::description(&nft)) == b"a new description", 0);
test_scenario::return_owned(&mut scenario, nft);
};
// burn it
Expand Down
8 changes: 4 additions & 4 deletions crates/sui-framework/sources/erc721_metadata.move
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
module sui::erc721_metadata {
use std::ascii;
use sui::url::{Self, Url};
use sui::utf8;
use std::string;

// TODO: add symbol()?
/// A wrapper type for the ERC721 metadata standard https://eips.ethereum.org/EIPS/eip-721
Expand All @@ -14,7 +14,7 @@ module sui::erc721_metadata {
/// A descriptive name for a collection of NFTs in this contract.
/// This corresponds to the `name()` method in the
/// ERC721Metadata interface in EIP-721.
name: utf8::String,
name: string::String,
/// A distinct Uniform Resource Identifier (URI) for a given asset.
/// This corresponds to the `tokenURI()` method in the ERC721Metadata
/// interface in EIP-721.
Expand All @@ -35,7 +35,7 @@ module sui::erc721_metadata {
let uri_str = ascii::string(token_uri);
ERC721Metadata {
token_id,
name: utf8::string_unsafe(name),
name: string::utf8(name),
token_uri: url::new_unsafe(uri_str),
}
}
Expand All @@ -52,7 +52,7 @@ module sui::erc721_metadata {
&self.token_uri
}

public fun name(self: &ERC721Metadata): &utf8::String {
public fun name(self: &ERC721Metadata): &string::String {
&self.name
}
}
40 changes: 0 additions & 40 deletions crates/sui-framework/sources/utf8.move

This file was deleted.

2 changes: 1 addition & 1 deletion crates/sui-json-rpc-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1183,7 +1183,7 @@ fn try_convert_type(type_: &StructTag, fields: &[(Identifier, MoveValue)]) -> Op
.map(|(id, value)| (id.to_string(), value.clone().into()))
.collect::<BTreeMap<_, SuiMoveValue>>();
match struct_name.as_str() {
"0x2::utf8::String" | "0x1::ascii::String" => {
"0x1::string::String" | "0x1::ascii::String" => {
if let Some(SuiMoveValue::Bytearray(bytes)) = fields.get("bytes") {
if let Ok(bytes) = bytes.to_vec() {
if let Ok(s) = String::from_utf8(bytes) {
Expand Down
10 changes: 5 additions & 5 deletions crates/sui-json-rpc-types/src/unit_tests/rpc_types_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use sui_types::base_types::{ObjectID, SuiAddress};
use sui_types::gas_coin::GasCoin;
use sui_types::object::MoveObject;
use sui_types::sui_serde::Base64;
use sui_types::SUI_FRAMEWORK_ADDRESS;
use sui_types::{MOVE_STDLIB_ADDRESS, SUI_FRAMEWORK_ADDRESS};

#[test]
fn test_move_value_to_sui_bytearray() {
Expand Down Expand Up @@ -56,8 +56,8 @@ fn test_move_value_to_string() {

let move_value = MoveValue::Struct(MoveStruct::WithTypes {
type_: StructTag {
address: SUI_FRAMEWORK_ADDRESS,
module: ident_str!("utf8").to_owned(),
address: MOVE_STDLIB_ADDRESS,
module: ident_str!("string").to_owned(),
name: ident_str!("String").to_owned(),
type_params: vec![],
},
Expand All @@ -80,8 +80,8 @@ fn test_move_value_to_url() {

let string_move_value = MoveValue::Struct(MoveStruct::WithTypes {
type_: StructTag {
address: SUI_FRAMEWORK_ADDRESS,
module: ident_str!("utf8").to_owned(),
address: MOVE_STDLIB_ADDRESS,
module: ident_str!("string").to_owned(),
name: ident_str!("String").to_owned(),
type_params: vec![],
},
Expand Down
4 changes: 2 additions & 2 deletions doc/book/examples/sources/basics/strings.move
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module examples::strings {
use sui::tx_context::TxContext;

// Use this dependency to get a type wrapper for UTF-8 strings
use sui::utf8::{Self, String};
use std::string::{Self, String};

/// A dummy Object that holds a String type
struct Name has key, store {
Expand All @@ -22,7 +22,7 @@ module examples::strings {
): Name {
Name {
id: object::new(ctx),
name: utf8::string_unsafe(name_bytes)
name: string::utf8(name_bytes)
}
}
}
4 changes: 2 additions & 2 deletions doc/book/examples/sources/basics/transfer.move
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ module examples::wrapper {
module examples::profile {
use sui::transfer;
use sui::url::{Self, Url};
use sui::utf8::{Self, String};
use std::string::{Self, String};
use sui::tx_context::{Self, TxContext};

// using Wrapper functionality
Expand Down Expand Up @@ -69,7 +69,7 @@ module examples::profile {
) {
// create a new container and wrap ProfileInfo into it
let container = wrapper::create(ProfileInfo {
name: utf8::string_unsafe(name),
name: string::utf8(name),
url: url::new_unsafe_from_bytes(url)
}, ctx);

Expand Down
4 changes: 2 additions & 2 deletions doc/book/examples/sources/patterns/capability.move
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
module examples::item {
use sui::transfer;
use sui::object::{Self, UID};
use sui::utf8::{Self, String};
use std::string::{Self, String};
use sui::tx_context::{Self, TxContext};

/// Type that marks Capability to create new `Item`s.
Expand All @@ -29,7 +29,7 @@ module examples::item {
) {
transfer::transfer(Item {
id: object::new(ctx),
name: utf8::string_unsafe(name)
name: string::utf8(name)
}, to)
}
}
18 changes: 9 additions & 9 deletions doc/book/examples/sources/samples/nft.move
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

module examples::devnet_nft {
use sui::url::{Self, Url};
use sui::utf8;
use std::string;
use sui::object::{Self, ID, UID};
use sui::event;
use sui::transfer;
Expand All @@ -13,9 +13,9 @@ module examples::devnet_nft {
struct DevNetNFT has key, store {
id: UID,
/// Name for the token
name: utf8::String,
name: string::String,
/// Description of the token
description: utf8::String,
description: string::String,
/// URL for the token
url: Url,
// TODO: allow custom attributes
Expand All @@ -29,18 +29,18 @@ module examples::devnet_nft {
// The creator of the NFT
creator: address,
// The name of the NFT
name: utf8::String,
name: string::String,
}

// ===== Public view functions =====

/// Get the NFT's `name`
public fun name(nft: &DevNetNFT): &utf8::String {
public fun name(nft: &DevNetNFT): &string::String {
&nft.name
}

/// Get the NFT's `description`
public fun description(nft: &DevNetNFT): &utf8::String {
public fun description(nft: &DevNetNFT): &string::String {
&nft.description
}

Expand All @@ -61,8 +61,8 @@ module examples::devnet_nft {
let sender = tx_context::sender(ctx);
let nft = DevNetNFT {
id: object::new(ctx),
name: utf8::string_unsafe(name),
description: utf8::string_unsafe(description),
name: string::utf8(name),
description: string::utf8(description),
url: url::new_unsafe_from_bytes(url)
};

Expand All @@ -88,7 +88,7 @@ module examples::devnet_nft {
new_description: vector<u8>,
_: &mut TxContext
) {
nft.description = utf8::string_unsafe(new_description)
nft.description = string::utf8(new_description)
}

/// Permanently delete `nft`
Expand Down

0 comments on commit 94e5bca

Please sign in to comment.