Skip to content

Commit

Permalink
unify ascii::String to string::String
Browse files Browse the repository at this point in the history
  • Loading branch information
pause125 committed May 30, 2024
1 parent bb65fc3 commit 646f71f
Show file tree
Hide file tree
Showing 34 changed files with 153 additions and 163 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use move_core_types::language_storage::ModuleId;
use move_core_types::value::MoveValue;
use move_core_types::vm_status::{AbortLocation, KeptVMStatus, VMStatus};
use moveos_types::module_binding::MoveFunctionCaller;
use moveos_types::move_std::ascii::MoveAsciiString;
use moveos_types::move_std::string::MoveString;
use moveos_types::move_types::FunctionId;
use moveos_types::{module_binding::ModuleBinding, transaction::MoveAction};
Expand All @@ -33,7 +32,7 @@ fn test_session_key_rooch() {

let session_scope = SessionScope::new(ROOCH_FRAMEWORK_ADDRESS, "*", "*").unwrap();
let app_name = MoveString::from_str("test").unwrap();
let app_url = MoveAsciiString::from_str("https:://test.rooch.network").unwrap();
let app_url = MoveString::from_str("https:://test.rooch.network").unwrap();
let max_inactive_interval = 100;
let action = rooch_types::framework::session_key::SessionKeyModule::create_session_key_action(
app_name.clone(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,12 @@
//# publish
module creator::test {
use std::string;
use std::ascii;
use moveos_std::object;

entry public fun test_entry_function_valid_struct_string(_str: string::String){

}

entry public fun test_entry_function_valid_struct_ascii(_ascii_str: ascii::String){

}

entry public fun test_entry_function_valid_struct_object_id(_id: object::ObjectID){

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ module creator::test {

//# publish
module creator::test {
use std::ascii;
use std::string;

fun init(_: ascii::String){
fun init(_: string::String){

}
}
5 changes: 2 additions & 3 deletions crates/rooch-genesis/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use moveos::moveos::{MoveOS, MoveOSConfig};
use moveos_store::{config_store::ConfigDBStore, MoveOSStore};
use moveos_types::genesis_info::GenesisInfo;
use moveos_types::h256::H256;
use moveos_types::move_std::ascii::MoveAsciiString;
use moveos_types::move_std::string::MoveString;
use moveos_types::moveos_std::gas_schedule::{GasEntry, GasSchedule, GasScheduleConfig};
use moveos_types::moveos_std::object::{ObjectEntity, RootObjectEntity};
use moveos_types::state_resolver::RootObjectResolver;
Expand Down Expand Up @@ -73,8 +73,7 @@ impl FrameworksGasParameters {
entries: entries
.into_iter()
.map(|(key, val)| GasEntry {
key: MoveAsciiString::from_str(key.as_str())
.expect("GasEntry key must be ascii"),
key: MoveString::from_str(key.as_str()).expect("GasEntry key must be ascii"),
val,
})
.collect(),
Expand Down
6 changes: 4 additions & 2 deletions crates/rooch-rpc-api/src/jsonrpc_types/move_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use move_core_types::{
u256,
};
use move_resource_viewer::{AnnotatedMoveStruct, AnnotatedMoveValue};
use moveos_types::move_std::string::MoveString;
use moveos_types::move_types::parse_module_id;
use moveos_types::moveos_std::object::ObjectID;
use moveos_types::moveos_std::type_info::TypeInfo;
Expand All @@ -21,7 +20,10 @@ use moveos_types::{
moveos_std::object::AnnotatedObject,
transaction::{FunctionCall, ScriptCall},
};
use moveos_types::{move_std::ascii::MoveAsciiString, state::MoveStructType};
use moveos_types::{
move_std::{ascii::MoveAsciiString, string::MoveString},
state::MoveStructType,
};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use std::collections::BTreeMap;
Expand Down
13 changes: 5 additions & 8 deletions crates/rooch-types/src/framework/auth_validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use moveos_types::function_return_value::DecodedFunctionResult;
use moveos_types::move_std::option::MoveOption;
use moveos_types::{
module_binding::MoveFunctionCaller,
move_std::ascii::MoveAsciiString,
move_std::string::MoveString,
move_types::FunctionId,
moveos_std::tx_context::TxContext,
state::{MoveStructState, MoveStructType},
Expand Down Expand Up @@ -86,20 +86,17 @@ impl BuiltinAuthValidator {
BuiltinAuthValidator::Rooch => AuthValidator {
id: self.flag().into(),
module_address: ROOCH_FRAMEWORK_ADDRESS,
module_name: MoveAsciiString::from_str("native_validator")
.expect("Should be valid"),
module_name: MoveString::from_str("native_validator").expect("Should be valid"),
},
BuiltinAuthValidator::Ethereum => AuthValidator {
id: self.flag().into(),
module_address: ROOCH_FRAMEWORK_ADDRESS,
module_name: MoveAsciiString::from_str("ethereum_validator")
.expect("Should be valid"),
module_name: MoveString::from_str("ethereum_validator").expect("Should be valid"),
},
BuiltinAuthValidator::Bitcoin => AuthValidator {
id: self.flag().into(),
module_address: ROOCH_FRAMEWORK_ADDRESS,
module_name: MoveAsciiString::from_str("bitcoin_validator")
.expect("Should be valid"),
module_name: MoveString::from_str("bitcoin_validator").expect("Should be valid"),
},
}
}
Expand All @@ -109,7 +106,7 @@ impl BuiltinAuthValidator {
pub struct AuthValidator {
pub id: u64,
pub module_address: AccountAddress,
pub module_name: MoveAsciiString,
pub module_name: MoveString,
}

impl MoveStructType for AuthValidator {
Expand Down
31 changes: 15 additions & 16 deletions crates/rooch-types/src/framework/session_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ use crate::authentication_key::AuthenticationKey;
use anyhow::Result;
use move_core_types::value::MoveValue;
use move_core_types::{account_address::AccountAddress, ident_str, identifier::IdentStr};
use moveos_types::move_std::string::MoveString;
use moveos_types::{
module_binding::{ModuleBinding, MoveFunctionCaller},
move_std::ascii::MoveAsciiString,
move_std::option::MoveOption,
move_std::string::MoveString,
moveos_std::tx_context::TxContext,
serde::Readable,
state::{MoveState, MoveStructState, MoveStructType},
Expand All @@ -28,8 +27,8 @@ pub const MODULE_NAME: &IdentStr = ident_str!("session_key");
#[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq, Hash)]
pub struct SessionScope {
pub module_address: AccountAddress,
pub module_name: MoveAsciiString,
pub function_name: MoveAsciiString,
pub module_name: MoveString,
pub function_name: MoveString,
}

impl SessionScope {
Expand All @@ -38,16 +37,16 @@ impl SessionScope {
module_name: &str,
function_name: &str,
) -> Result<Self> {
let module_name_value = MoveAsciiString::from_str(module_name)?;
let function_name_value = MoveAsciiString::from_str(function_name)?;
let module_name_value = MoveString::from_str(module_name)?;
let function_name_value = MoveString::from_str(function_name)?;
Ok(Self {
module_address,
module_name: module_name_value,
function_name: function_name_value,
})
}

fn is_asterisk(s: &MoveAsciiString) -> bool {
fn is_asterisk(s: &MoveString) -> bool {
s.as_bytes() == b"*"
}

Expand Down Expand Up @@ -81,8 +80,8 @@ impl MoveStructState for SessionScope {
fn struct_layout() -> move_core_types::value::MoveStructLayout {
move_core_types::value::MoveStructLayout::new(vec![
move_core_types::value::MoveTypeLayout::Address,
MoveAsciiString::type_layout(),
MoveAsciiString::type_layout(),
MoveString::type_layout(),
MoveString::type_layout(),
])
}
}
Expand Down Expand Up @@ -123,7 +122,7 @@ pub struct SessionKey {
#[serde(default)]
pub app_name: MoveString,
#[serde(default)]
pub app_url: MoveAsciiString,
pub app_url: MoveString,
#[serde_as(as = "Readable<Hex, _>")]
pub authentication_key: Vec<u8>,
#[serde_as(as = "Vec<Readable<DisplayFromStr, _>>")]
Expand Down Expand Up @@ -226,7 +225,7 @@ impl<'a> SessionKeyModule<'a> {

pub fn create_session_key_action(
app_name: MoveString,
app_url: MoveAsciiString,
app_url: MoveString,
authentication_key: Vec<u8>,
scope: SessionScope,
max_inactive_interval: u64,
Expand Down Expand Up @@ -266,7 +265,7 @@ mod tests {
use super::SessionScope;
use move_core_types::{account_address::AccountAddress, ident_str, language_storage::ModuleId};
use moveos_types::{
move_std::ascii::MoveAsciiString, move_types::FunctionId, transaction::FunctionCall,
move_std::string::MoveString, move_types::FunctionId, transaction::FunctionCall,
};

fn do_test_scope_match(scope: &SessionScope, function: &FunctionCall, expect: bool) {
Expand All @@ -283,8 +282,8 @@ mod tests {
fn test_scope_match() {
let session_scope = SessionScope {
module_address: AccountAddress::ONE,
module_name: MoveAsciiString::from_str("test").unwrap(),
function_name: MoveAsciiString::from_str("test").unwrap(),
module_name: MoveString::from_str("test").unwrap(),
function_name: MoveString::from_str("test").unwrap(),
};
let cases = vec![
(
Expand Down Expand Up @@ -341,8 +340,8 @@ mod tests {
fn test_check_scope_match_asterisk() {
let session_scope = SessionScope {
module_address: AccountAddress::ONE,
module_name: MoveAsciiString::from_str("*").unwrap(),
function_name: MoveAsciiString::from_str("*").unwrap(),
module_name: MoveString::from_str("*").unwrap(),
function_name: MoveString::from_str("*").unwrap(),
};
let cases = vec![
(
Expand Down
3 changes: 1 addition & 2 deletions crates/rooch/src/commands/session_key/commands/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
use crate::cli_types::{TransactionOptions, WalletContextOptions};
use clap::Parser;
use moveos_types::module_binding::MoveFunctionCaller;
use moveos_types::move_std::ascii::MoveAsciiString;
use moveos_types::move_std::string::MoveString;
use rooch_key::key_derive::verify_password;
use rooch_key::keystore::account_keystore::AccountKeystore;
Expand All @@ -21,7 +20,7 @@ pub struct CreateCommand {
#[clap(long)]
pub app_name: MoveString,
#[clap(long)]
pub app_url: MoveAsciiString,
pub app_url: MoveString,

/// The scope of the session key, format: address::module_name::function_name.
/// The module_name and function_name must be valid Move identifiers or '*'. `*` means any module or function.
Expand Down
5 changes: 4 additions & 1 deletion examples/btc_blind_box/sources/blind_box.move
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ module btc_blind_box::blind_box {
use moveos_std::account as moveos_account;
use rooch_framework::timestamp;
use bitcoin_move::bitcoin;
use bitcoin_move::types::{Self, Header};
use bitcoin_move::types::Header;

const ErrorNoPermission: u64 = 1;
const ErrorSoldOut: u64 = 2;
Expand Down Expand Up @@ -154,6 +154,9 @@ module btc_blind_box::blind_box {
#[test_only]
use rooch_framework::account;

#[test_only]
use bitcoin_move::types;

#[test(sender=@0x42)]
fun test_request_and_claim(sender: &signer) {
rooch_framework::genesis::init_for_test();
Expand Down
3 changes: 0 additions & 3 deletions examples/complex_struct/sources/complex_struct.move
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ module rooch_examples::complex_struct {
field_u256: u256,
field_address: address,
field_object: Object<SimpleStruct>,
field_ascii_str: std::ascii::String,
field_str: std::string::String,
field_struct: SimpleStruct,
field_vec_u8: vector<u8>,
Expand Down Expand Up @@ -68,7 +67,6 @@ module rooch_examples::complex_struct {
field_u256: 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF,
field_address: @rooch_examples,
field_object: simple_object,
field_ascii_str: std::ascii::string(b"hello"),
field_str: utf8_str,
field_struct: simple_struct,
field_vec_u8: bcs::to_bytes(&@rooch_examples),
Expand All @@ -90,7 +88,6 @@ module rooch_examples::complex_struct {
field_u256: _,
field_address: _,
field_object,
field_ascii_str: _,
field_str: _,
field_struct: _,
field_vec_u8: _,
Expand Down
Loading

0 comments on commit 646f71f

Please sign in to comment.