Skip to content

Commit

Permalink
[refactor] Add prefix G_ to global static variables (#3336)
Browse files Browse the repository at this point in the history
  • Loading branch information
liby committed Apr 13, 2022
1 parent d07e82d commit 1aeb4c3
Show file tree
Hide file tree
Showing 74 changed files with 511 additions and 506 deletions.
6 changes: 3 additions & 3 deletions account/api/src/rich_wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use serde::Serialize;
use serde::{Deserialize, Deserializer};
use starcoin_types::account_address::AccountAddress;
use starcoin_types::account_config::token_code::TokenCode;
use starcoin_types::account_config::STC_TOKEN_CODE;
use starcoin_types::account_config::G_STC_TOKEN_CODE;
use starcoin_types::transaction::{RawUserTransaction, SignedUserTransaction, TransactionPayload};
use std::fmt;
use std::marker::PhantomData;
Expand Down Expand Up @@ -62,7 +62,7 @@ impl Setting {
Setting {
default_expiration_timeout: 3600,
default_gas_price: 1,
default_gas_token: STC_TOKEN_CODE.clone(),
default_gas_token: G_STC_TOKEN_CODE.clone(),
is_default: false,
is_readonly: false,
}
Expand All @@ -72,7 +72,7 @@ impl Setting {
Setting {
default_expiration_timeout: 3600,
default_gas_price: 1,
default_gas_token: STC_TOKEN_CODE.clone(),
default_gas_token: G_STC_TOKEN_CODE.clone(),
is_default: false,
is_readonly: true,
}
Expand Down
6 changes: 3 additions & 3 deletions account/service/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use starcoin_crypto::ValidCryptoMaterial;
use starcoin_logger::prelude::*;
use starcoin_service_registry::mocker::MockHandler;
use starcoin_service_registry::{ActorService, ServiceContext, ServiceFactory, ServiceHandler};
use starcoin_types::account_config::{association_address, STC_TOKEN_CODE};
use starcoin_types::account_config::{association_address, G_STC_TOKEN_CODE};
use starcoin_types::genesis_config::ChainId;
use std::any::Any;
use std::sync::Arc;
Expand Down Expand Up @@ -177,8 +177,8 @@ impl ServiceHandler<AccountService, AccountRequest> for AccountService {
AccountRequest::AccountAcceptedTokens { address } => {
let mut tokens = self.manager.accepted_tokens(address)?;
//auto add STC to accepted tokens.
if !tokens.contains(&STC_TOKEN_CODE) {
tokens.push(STC_TOKEN_CODE.clone())
if !tokens.contains(&G_STC_TOKEN_CODE) {
tokens.push(G_STC_TOKEN_CODE.clone())
}
AccountResponse::AcceptedTokens(tokens)
}
Expand Down
4 changes: 2 additions & 2 deletions block-relayer/src/block_relayer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use crate::metrics::BlockRelayerMetrics;
use anyhow::{ensure, format_err, Result};
use config::NodeConfig;
use config::CRATE_VERSION;
use config::G_CRATE_VERSION;
use crypto::HashValue;
use futures::FutureExt;
use logger::prelude::*;
Expand Down Expand Up @@ -215,7 +215,7 @@ impl BlockRelayer {
if let Ok(Some((_, _, _, version))) =
txpool.get_store().get_failed_block_by_id(block_id)
{
if version == *CRATE_VERSION {
if version == *G_CRATE_VERSION {
warn!("Block is failed block : {:?}", block_id);
}
} else {
Expand Down
4 changes: 2 additions & 2 deletions cmd/airdrop/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use starcoin_types::language_storage::ModuleId;
use starcoin_types::transaction::authenticator::AccountPrivateKey;
use starcoin_types::transaction::{RawUserTransaction, ScriptFunction};
use starcoin_vm_types::account_config::auto_accept_token::AutoAcceptToken;
use starcoin_vm_types::account_config::{stc_type_tag, BalanceResource, STC_TOKEN_CODE};
use starcoin_vm_types::account_config::{stc_type_tag, BalanceResource, G_STC_TOKEN_CODE};
use starcoin_vm_types::language_storage::{StructTag, TypeTag};
use starcoin_vm_types::move_resource::MoveResource;
use starcoin_vm_types::token::token_code::TokenCode;
Expand Down Expand Up @@ -122,7 +122,7 @@ async fn main() -> Result<()> {

let token_type: StructTag = options
.token_code
.unwrap_or_else(|| STC_TOKEN_CODE.clone())
.unwrap_or_else(|| G_STC_TOKEN_CODE.clone())
.try_into()?;
let is_stc = stc_type_tag().eq(&TypeTag::Struct(token_type.clone()));

Expand Down
7 changes: 4 additions & 3 deletions cmd/faucet/src/web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ fn response(result: Result<serde_json::Value>) -> Response<Cursor<String>> {
}
}

static CONTENT_TYPE: Lazy<Header> = Lazy::new(|| Header {
static G_CONTENT_TYPE: Lazy<Header> = Lazy::new(|| Header {
field: "Content-Type".parse().unwrap(),
value: AsciiString::from_ascii("text/html; charset=utf8").unwrap(),
});
Expand All @@ -69,12 +69,13 @@ pub async fn run(server: Server, faucet: Faucet) {
match url {
"/" => {
let response =
Response::from_string(index_html()).with_header(CONTENT_TYPE.clone());
Response::from_string(index_html()).with_header(G_CONTENT_TYPE.clone());
let _err = request.respond(response);
}
"/api/fund" => {
let resp = handle_fund(&faucet, &mut request).await;
if let Err(err) = request.respond(response(resp).with_header(CONTENT_TYPE.clone()))
if let Err(err) =
request.respond(response(resp).with_header(G_CONTENT_TYPE.clone()))
{
error!("response err: {}", err)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/generator/src/gen_genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ impl CommandAction for GenGenesisCommand {
init_or_load_data_dir(global_opt, opt.password.clone())?;
Ok(GenGenesisResult {
net: config.net().id().clone(),
config_path: config.data_dir().join(starcoin_config::CONFIG_FILE_PATH),
config_path: config.data_dir().join(starcoin_config::G_CONFIG_FILE_PATH),
account_info: account,
genesis: chain_info.genesis_hash(),
})
Expand Down
2 changes: 1 addition & 1 deletion cmd/generator/src/gen_genesis_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ impl CommandAction for GenGenesisConfigCommand {

let config_path = base
.data_dir()
.join(starcoin_config::GENESIS_CONFIG_FILE_NAME);
.join(starcoin_config::G_GENESIS_CONFIG_FILE_NAME);
// genesis config file auto generate in BaseConfig::default_with_opt
ensure!(
config_path.exists(),
Expand Down
6 changes: 3 additions & 3 deletions cmd/generator/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

use anyhow::Result;
use scmd::CmdContext;
use starcoin_config::{StarcoinOpt, APP_VERSION, CRATE_VERSION};
use starcoin_config::{StarcoinOpt, G_APP_VERSION, G_CRATE_VERSION};
use starcoin_generator::cli_state::CliState;
use starcoin_generator::gen_data::GenDataCommand;
use starcoin_generator::gen_genesis::GenGenesisCommand;
Expand All @@ -12,8 +12,8 @@ use starcoin_logger::prelude::*;

fn run() -> Result<()> {
let context = CmdContext::<CliState, StarcoinOpt>::with_state(
CRATE_VERSION,
Some(APP_VERSION.as_str()),
G_CRATE_VERSION,
Some(G_APP_VERSION.as_str()),
CliState,
);
context
Expand Down
4 changes: 2 additions & 2 deletions cmd/starcoin/src/account/transfer_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use anyhow::Result;
use clap::Parser;
use scmd::{CommandAction, ExecContext};
use starcoin_types::account_address::AccountAddress;
use starcoin_vm_types::token::stc::STC_TOKEN_CODE;
use starcoin_vm_types::token::stc::G_STC_TOKEN_CODE;
use starcoin_vm_types::token::token_code::TokenCode;
use starcoin_vm_types::transaction::TransactionPayload;

Expand Down Expand Up @@ -56,7 +56,7 @@ impl CommandAction for TransferCommand {
let token_code = opt
.token_code
.clone()
.unwrap_or_else(|| STC_TOKEN_CODE.clone());
.unwrap_or_else(|| G_STC_TOKEN_CODE.clone());
let script_function = starcoin_executor::encode_transfer_script_by_token_code(
receiver_address,
opt.amount,
Expand Down
6 changes: 3 additions & 3 deletions cmd/starcoin/src/cli_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use std::path::{Path, PathBuf};
use std::sync::Arc;
use std::time::Duration;

static HISTORY_FILE_NAME: &str = "history";
static G_HISTORY_FILE_NAME: &str = "history";

pub struct CliState {
net: ChainNetworkID,
Expand All @@ -52,7 +52,7 @@ impl CliState {
node_handle: Option<NodeHandle>,
account_client: Box<dyn AccountProvider>,
) -> CliState {
let data_dir = starcoin_config::DEFAULT_BASE_DATA_DIR
let data_dir = starcoin_config::G_DEFAULT_BASE_DATA_DIR
.clone()
.join("cli")
.join(net.to_string());
Expand Down Expand Up @@ -99,7 +99,7 @@ impl CliState {
}

pub fn history_file(&self) -> PathBuf {
self.data_dir().join(HISTORY_FILE_NAME)
self.data_dir().join(G_HISTORY_FILE_NAME)
}

pub fn node_handle(&self) -> Option<&NodeHandle> {
Expand Down
4 changes: 2 additions & 2 deletions cmd/starcoin/src/dev/get_coin_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use starcoin_transaction_builder::encode_transfer_script_by_token_code;
use starcoin_types::account_address::AccountAddress;
use starcoin_types::account_config;
use starcoin_types::account_config::STCUnit;
use starcoin_vm_types::account_config::STC_TOKEN_CODE;
use starcoin_vm_types::account_config::G_STC_TOKEN_CODE;
use starcoin_vm_types::token::token_value::TokenValue;
use starcoin_vm_types::transaction::TransactionPayload;
use std::time::Duration;
Expand Down Expand Up @@ -69,7 +69,7 @@ impl CommandAction for GetCoinCommand {
TransactionPayload::ScriptFunction(encode_transfer_script_by_token_code(
to.address,
opt.amount.scaling(),
STC_TOKEN_CODE.clone(),
G_STC_TOKEN_CODE.clone(),
)),
)?
.get_transaction_info()
Expand Down
10 changes: 5 additions & 5 deletions cmd/starcoin/src/dev/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use starcoin_vm_types::account_address::AccountAddress;
use starcoin_vm_types::account_config::core_code_address;
use starcoin_vm_types::identifier::Identifier;
use starcoin_vm_types::language_storage::ModuleId;
use starcoin_vm_types::token::stc::STC_TOKEN_CODE;
use starcoin_vm_types::token::stc::G_STC_TOKEN_CODE;
use starcoin_vm_types::transaction::{
RawUserTransaction, SignedUserTransaction, TransactionPayload,
};
Expand Down Expand Up @@ -231,7 +231,7 @@ fn test_upgrade_module() {
2,
dao_config.min_action_delay,
false,
STC_TOKEN_CODE.clone(),
G_STC_TOKEN_CODE.clone(),
config.net().stdlib_version(),
);

Expand Down Expand Up @@ -274,7 +274,7 @@ fn test_upgrade_module() {
let proposal_id = 0;
let mut type_tags: Vec<TypeTag> = Vec::new();
let module = parse_type_tag("0x1::UpgradeModuleDaoProposal::UpgradeModuleV2").unwrap();
type_tags.push(STC_TOKEN_CODE.clone().try_into().unwrap());
type_tags.push(G_STC_TOKEN_CODE.clone().try_into().unwrap());
type_tags.push(module);
let mut args: Vec<TransactionArgument> = Vec::new();
let arg_1 = parse_transaction_argument("0x0000000000000000000000000a550c18").unwrap();
Expand Down Expand Up @@ -329,7 +329,7 @@ fn test_upgrade_module() {
let module_upgrade_queue = build_module_upgrade_queue(
association_address(),
proposal_id,
STC_TOKEN_CODE.clone(),
G_STC_TOKEN_CODE.clone(),
config.net().stdlib_version(),
);
let queue_txn = sign_txn_with_account_by_rpc_client(
Expand Down Expand Up @@ -365,7 +365,7 @@ fn test_upgrade_module() {

// 7. plan
let module_upgrade_plan =
build_module_upgrade_plan(association_address(), proposal_id, STC_TOKEN_CODE.clone());
build_module_upgrade_plan(association_address(), proposal_id, G_STC_TOKEN_CODE.clone());
let plan_txn = sign_txn_with_account_by_rpc_client(
&cli_state,
default_account.address,
Expand Down
58 changes: 29 additions & 29 deletions cmd/starcoin/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use scmd::CmdContext;
use starcoin_account_provider::ProviderFactory;
use starcoin_cmd::*;
use starcoin_cmd::{CliState, StarcoinOpt};
use starcoin_config::{Connect, APP_VERSION, CRATE_VERSION};
use starcoin_config::{Connect, G_APP_VERSION, G_CRATE_VERSION};
use starcoin_logger::prelude::*;
use starcoin_node_api::errors::NodeStartError;
use starcoin_rpc_client::RpcClient;
Expand All @@ -15,13 +15,13 @@ use std::time::Duration;

/// This exit code means is that the node failed to start and required human intervention.
/// Node start script can do auto task when meet this exist code.
static EXIT_CODE_NEED_HELP: i32 = 120;
static G_EXIT_CODE_NEED_HELP: i32 = 120;

fn run() -> Result<()> {
let logger_handle = starcoin_logger::init();
let context = CmdContext::<CliState, StarcoinOpt>::with_default_action(
CRATE_VERSION,
Some(APP_VERSION.as_str()),
G_CRATE_VERSION,
Some(G_APP_VERSION.as_str()),
|opt| -> Result<CliState> {
info!("Starcoin opts: {}", opt);
let connect = opt.connect.as_ref().unwrap_or(&Connect::IPC(None));
Expand Down Expand Up @@ -108,7 +108,7 @@ fn run() -> Result<()> {
info!("Start console, disable stderr output.");
logger_handle.disable_stderr();
print_logo();
(*scmd::DEFAULT_CONSOLE_CONFIG, Some(state.history_file()))
(*scmd::G_DEFAULT_CONSOLE_CONFIG, Some(state.history_file()))
},
|_, _, state| {
let (_, _, handle) = state.into_inner();
Expand All @@ -125,34 +125,34 @@ fn run() -> Result<()> {
#[rustfmt::skip]
#[allow(clippy::print_literal)]
fn print_logo(){
println!("{}{}{}","\x1b[34;1m",r#"
(%&&&&(%&%( &#
,#%%%&%%%#/ (%&&%
%#%#%%%%#&&% %&
/ %%% #&
&#%%%#%%%%# *&%
println!("{}{}{}","\x1b[34;1m",r#"
(%&&&&(%&%( &#
,#%%%&%%%#/ (%&&%
%#%#%%%%#&&% %&
/ %%% #&
&#%%%#%%%%# *&%
(#%%%#/ %%%%%%# #&%
#%#%%#&& #%%%%%%%( &%%&
(#%%## #%%%%%%%%%/ *%%
#%%%&#%%##&&&&%%%(%%%%%%%%%%%&&&&&&&& &% (&#/#
((##%%%%%%%%%%%%%%%%%%%%%%%%&&&&&&&%% ####
###%#(& &#%%%%%%%%%%%%%%%%%%%%%&&&&%##&(%&%
(#%## (#%%%%%%%%%%%%%%%%%%&%#(#%%#
(###(% &&#%%%%%%%%%%%%%%&%%#&&
#### %%%%%%%%%%%%( %%
/###/ #%%%%%%%%#%%# %%#
/###( (%%%%%%#%%%##%%%( *%%#
###( (%%%%###&# %&#%%&(%%%
(##(& &#%#(# %%&&%
(###%# (%%%#((& &&%#
#%#%%#&& #%%%%%%%( &%%&
(#%%## #%%%%%%%%%/ *%%
#%%%&#%%##&&&&%%%(%%%%%%%%%%%&&&&&&&& &% (&#/#
((##%%%%%%%%%%%%%%%%%%%%%%%%&&&&&&&%% ####
###%#(& &#%%%%%%%%%%%%%%%%%%%%%&&&&%##&(%&%
(#%## (#%%%%%%%%%%%%%%%%%%&%#(#%%#
(###(% &&#%%%%%%%%%%%%%%&%%#&&
#### %%%%%%%%%%%%( %%
/###/ #%%%%%%%%#%%# %%#
/###( (%%%%%%#%%%##%%%( *%%#
###( (%%%%###&# %&#%%&(%%%
(##(& &#%#(# %%&&%
(###%# (%%%#((& &&%#
(#%%%%%%#(
██████╗████████╗ █████╗ ██████╗ █████╗ █████╗ ██╗███╗ ██╗
██╔════╝╚══██╔══╝██╔══██╗██╔══██╗██╔══██╗██╔══██╗██║████╗ ██║
╚█████╗ ██║ ███████║██████╔╝██║ ╚═╝██║ ██║██║██╔██╗██║
╚═══██╗ ██║ ██╔══██║██╔══██╗██║ ██╗██║ ██║██║██║╚████║
██████╔╝ ██║ ██║ ██║██║ ██║╚█████╔╝╚█████╔╝██║██║ ╚███║
╚═════╝ ╚═╝ ╚═╝ ╚═╝╚═╝ ╚═╝ ╚════╝ ╚════╝ ╚═╝╚═╝ ╚══╝
╚═════╝ ╚═╝ ╚═╝ ╚═╝╚═╝ ╚═╝ ╚════╝ ╚════╝ ╚═╝╚═╝ ╚══╝
"#,"\x1b[0m");
}

Expand All @@ -165,15 +165,15 @@ fn main() {
//TODO not suggest clean data dir in main network.
NodeStartError::LoadConfigError(e) => {
error!("{:?}, please fix config.", e);
std::process::exit(EXIT_CODE_NEED_HELP);
std::process::exit(G_EXIT_CODE_NEED_HELP);
}
NodeStartError::StorageInitError(e) => {
error!("{:?}, please clean your data dir.", e);
std::process::exit(EXIT_CODE_NEED_HELP);
std::process::exit(G_EXIT_CODE_NEED_HELP);
}
NodeStartError::GenesisError(e) => {
error!("{:?}, please clean your data dir.", e);
std::process::exit(EXIT_CODE_NEED_HELP);
std::process::exit(G_EXIT_CODE_NEED_HELP);
}
NodeStartError::Other(e) => {
error!("Node exit for an unexpected error: {:?}", e);
Expand Down
4 changes: 2 additions & 2 deletions commons/accumulator/src/node.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) The Starcoin Core Contributors
// SPDX-License-Identifier: Apache-2.0

use crate::node_index::{NodeIndex, NODE_ERROR_INDEX};
use crate::node_index::{NodeIndex, G_NODE_ERROR_INDEX};
use anyhow::Result;
use serde::{Deserialize, Serialize};
use starcoin_crypto::{
Expand Down Expand Up @@ -48,7 +48,7 @@ impl AccumulatorNode {
AccumulatorNode::Leaf(leaf) => leaf.index(),
AccumulatorNode::Empty => {
// bail!("error for get index");
*NODE_ERROR_INDEX
*G_NODE_ERROR_INDEX
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion commons/accumulator/src/node_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use serde::{Deserialize, Serialize};
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash, Serialize, Deserialize)]
pub struct NodeIndex(u64);
pub const MAX_ACCUMULATOR_PROOF_DEPTH: usize = 63;
pub static NODE_ERROR_INDEX: Lazy<NodeIndex> =
pub static G_NODE_ERROR_INDEX: Lazy<NodeIndex> =
Lazy::new(|| NodeIndex::from_inorder_index(u64::max_value()));

#[derive(Debug, Eq, PartialEq)]
Expand Down
Loading

0 comments on commit 1aeb4c3

Please sign in to comment.