Skip to content

Commit

Permalink
[Framework] Rename Rooch GasCoin symbol to RGas (rooch-network#2557)
Browse files Browse the repository at this point in the history
* rename gas coin to rgas

* Support passing icon parameter when coin register
  • Loading branch information
baichuan3 authored Sep 2, 2024
1 parent fce626d commit d572c03
Show file tree
Hide file tree
Showing 50 changed files with 163 additions and 127 deletions.
2 changes: 1 addition & 1 deletion crates/rooch-faucet/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ impl App {
.rooch
.get_balance(
faucet_address.into(),
StructTagView::from_str("0x3::gas_coin::GasCoin").unwrap(),
StructTagView::from_str("0x3::gas_coin::RGas").unwrap(),
)
.await
.map_err(FaucetError::internal)?;
Expand Down
2 changes: 1 addition & 1 deletion crates/rooch-faucet/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub enum FaucetError {
InvalidAddress(String),

#[error("Timed out waiting for a coin from the gas coin pool")]
NoGasCoinAvailable,
NoRGasAvailable,

#[error("Wallet Error: `{0}`")]
Wallet(String),
Expand Down
4 changes: 2 additions & 2 deletions crates/rooch-faucet/src/faucet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ impl Faucet {
let state = self.state.write().await;

let move_action = TransferModule::create_transfer_coin_to_multichain_address_action(
StructTag::from_str("0x3::gas_coin::GasCoin").unwrap(),
StructTag::from_str("0x3::gas_coin::RGas").unwrap(),
recipient,
state.config.faucet_grant_amount.into(),
);
Expand All @@ -190,7 +190,7 @@ impl Faucet {
let state = self.state.write().await;

let move_action = TransferModule::create_transfer_coin_action(
StructTag::from_str("0x3::gas_coin::GasCoin").unwrap(),
StructTag::from_str("0x3::gas_coin::RGas").unwrap(),
recipient.into(),
state.config.faucet_grant_amount.into(),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use rooch_types::crypto::{RoochKeyPair, RoochSignature};
use rooch_types::framework::auth_payload::{MultisignAuthPayload, SignData};
use rooch_types::framework::auth_validator::BuiltinAuthValidator;
use rooch_types::framework::empty::Empty;
use rooch_types::framework::gas_coin::GasCoin;
use rooch_types::framework::gas_coin::RGas;
use rooch_types::framework::transfer::TransferModule;
use rooch_types::transaction::rooch::RoochTransactionData;
use rooch_types::transaction::{Authenticator, RoochTransaction};
Expand Down Expand Up @@ -56,7 +56,7 @@ async fn test_validate() {
//transfer gas free to multisign account

let gas_action = TransferModule::create_transfer_coin_action(
GasCoin::struct_tag(),
RGas::struct_tag(),
multisign_address.into(),
U256::from(1000000000u128),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,29 @@
script {

use rooch_framework::coin_store::CoinStore;
use rooch_framework::gas_coin::GasCoin;
use rooch_framework::gas_coin::RGas;

fun main(sender: &signer) {
let account_addr = moveos_std::signer::address_of(sender);
let object_id = moveos_std::object::account_named_object_id<CoinStore<GasCoin>>(account_addr);
let object_id = moveos_std::object::account_named_object_id<CoinStore<RGas>>(account_addr);
std::debug::print(&object_id);
std::debug::print(&rooch_framework::coin::is_registered<GasCoin>());
std::debug::print(&rooch_framework::account_coin_store::balance<GasCoin>(account_addr));
std::debug::print(&rooch_framework::coin::is_registered<RGas>());
std::debug::print(&rooch_framework::account_coin_store::balance<RGas>(account_addr));
}
}

//Get gas from faucet
//# run rooch_framework::gas_coin::faucet_entry --signers test --args u256:100000000000

//Transfer via coin store
//# run --signers test --args object:0x5f065f9c2b57613760fc9065bf00f597d7273697699634c16eb3793ef741eec7
//# run --signers test --args object:0x562409111a2ca55814e56eb42186470c4adda4a04a4a84140690f4d68e8e1c06
script {
use moveos_std::object::{Object};

use rooch_framework::coin_store::{Self, CoinStore};
use rooch_framework::gas_coin::{Self, GasCoin};
use rooch_framework::gas_coin::{Self, RGas};

fun main(coin_store: &mut Object<CoinStore<GasCoin>>) {
fun main(coin_store: &mut Object<CoinStore<RGas>>) {
let gas_coin = coin_store::withdraw(coin_store, 100);
gas_coin::burn(gas_coin);
}
Expand Down
8 changes: 4 additions & 4 deletions crates/rooch-indexer/src/tests/test_indexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use moveos_types::transaction::{TransactionExecutionInfo, VerifiedMoveOSTransact
use rand::random;
use rooch_config::store_config::DEFAULT_DB_INDEXER_SUBDIR;
use rooch_types::framework::coin_store::CoinStore;
use rooch_types::framework::gas_coin::GasCoin;
use rooch_types::framework::gas_coin::RGas;
use rooch_types::indexer::event::{EventFilter, IndexerEvent};
use rooch_types::indexer::state::{IndexerObjectState, ObjectStateFilter, ObjectStateType};
use rooch_types::indexer::transaction::{IndexerTransaction, TransactionFilter};
Expand Down Expand Up @@ -158,14 +158,14 @@ async fn test_object_type_query() -> Result<()> {
0,
0,
0,
CoinStore::<GasCoin>::new(100u64.into(), false),
CoinStore::<RGas>::new(100u64.into(), false),
);
let raw_obj = coin_store_obj.into_state();
let state = IndexerObjectState::new(raw_obj.metadata, 0, 0);
let object_states = vec![state];
indexer_store.persist_or_update_object_states(object_states.clone())?;
// filter by exact object type
let filter = ObjectStateFilter::ObjectType(CoinStore::<GasCoin>::struct_tag());
let filter = ObjectStateFilter::ObjectType(CoinStore::<RGas>::struct_tag());
let query_object_states = indexer_reader.query_object_ids_with_filter(
filter,
None,
Expand All @@ -176,7 +176,7 @@ async fn test_object_type_query() -> Result<()> {
assert_eq!(query_object_states.len(), 1);
// filter by object type and owner
let filter = ObjectStateFilter::ObjectTypeWithOwner {
object_type: CoinStore::<GasCoin>::struct_tag(),
object_type: CoinStore::<RGas>::struct_tag(),
filter_out: false,
owner,
};
Expand Down
4 changes: 2 additions & 2 deletions crates/rooch-test-transaction-builder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use moveos_verifier::build::run_verifier;
use rooch_types::crypto::RoochKeyPair;
use rooch_types::error::RoochError;
use rooch_types::framework::empty::Empty;
use rooch_types::framework::gas_coin::GasCoin;
use rooch_types::framework::gas_coin::RGas;
use rooch_types::framework::transfer::TransferModule;
use rooch_types::test_utils::{random_string, random_string_with_size};
use rooch_types::transaction::rooch::RoochTransactionData;
Expand Down Expand Up @@ -78,7 +78,7 @@ impl TestTransactionBuilder {

pub fn call_transfer_create(&self) -> MoveAction {
TransferModule::create_transfer_coin_action(
GasCoin::struct_tag(),
RGas::struct_tag(),
AccountAddress::random(),
U256::from(100u128),
)
Expand Down
6 changes: 6 additions & 0 deletions crates/rooch-types/src/framework/coin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use move_core_types::language_storage::StructTag;
use move_core_types::u256::U256;
use move_core_types::{account_address::AccountAddress, ident_str, identifier::IdentStr};
use moveos_types::module_binding::{ModuleBinding, MoveFunctionCaller};
use moveos_types::move_std::option::MoveOption;
use moveos_types::move_std::string::MoveString;
use moveos_types::move_types;
use moveos_types::moveos_std::object::{self, ObjectID};
Expand Down Expand Up @@ -93,6 +94,7 @@ pub struct CoinInfo<CoinType> {
coin_type: MoveString,
name: MoveString,
symbol: MoveString,
icon_url: MoveOption<MoveString>,
decimals: u8,
supply: U256,
phantom: std::marker::PhantomData<CoinType>,
Expand Down Expand Up @@ -125,6 +127,7 @@ where
MoveString::type_layout(),
MoveString::type_layout(),
MoveString::type_layout(),
MoveOption::<MoveString>::type_layout(),
move_core_types::value::MoveTypeLayout::U8,
move_core_types::value::MoveTypeLayout::U256,
])
Expand Down Expand Up @@ -169,6 +172,9 @@ impl<CoinType> CoinInfo<CoinType> {
pub fn symbol(&self) -> String {
self.symbol.to_string()
}
pub fn icon_url(&self) -> Option<String> {
self.icon_url.clone().map(|v| v.to_string()).into()
}
pub fn decimals(&self) -> u8 {
self.decimals
}
Expand Down
8 changes: 4 additions & 4 deletions crates/rooch-types/src/framework/gas_coin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ pub const MODULE_NAME: &IdentStr = ident_str!("gas_coin");
pub const DECIMALS: u8 = 18;

#[derive(Debug, Clone)]
pub struct GasCoin;
pub struct RGas;

impl MoveStructType for GasCoin {
impl MoveStructType for RGas {
const ADDRESS: AccountAddress = ROOCH_FRAMEWORK_ADDRESS;
const MODULE_NAME: &'static IdentStr = MODULE_NAME;
const STRUCT_NAME: &'static IdentStr = ident_str!("GasCoin");
const STRUCT_NAME: &'static IdentStr = ident_str!("RGas");
}

impl GasCoin {
impl RGas {
pub fn scaling<I: Into<U256>>(value: I) -> U256 {
U256::from(10u64.pow(DECIMALS as u32)) * value.into()
}
Expand Down
2 changes: 1 addition & 1 deletion crates/rooch/src/commands/account/commands/balance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub struct BalanceCommand {
address: ParsedAddress,

/// Struct name as `<ADDRESS>::<MODULE_ID>::<STRUCT_NAME><TypeParam>`
/// Example: `0x3::gas_coin::GasCoin`, `0x123::Coin::Box<0x123::coin_box::FCoin>`
/// Example: `0x3::gas_coin::RGas`, `0x123::Coin::Box<0x123::coin_box::FCoin>`
#[clap(long, value_parser=ParsedStructType::parse)]
coin_type: Option<ParsedStructType>,

Expand Down
2 changes: 1 addition & 1 deletion crates/rooch/src/commands/account/commands/transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub struct TransferCommand {
to: ParsedAddress,

/// Struct name as `<ADDRESS>::<MODULE_ID>::<STRUCT_NAME><TypeParam>`
/// Example: `0x3::gas_coin::GasCoin`, `0x123::Coin::Box<0x123::coin_box::FCoin>`
/// Example: `0x3::gas_coin::RGas`, `0x123::Coin::Box<0x123::coin_box::FCoin>`
#[clap(short = 'c', long, value_parser=ParsedStructType::parse)]
coin_type: ParsedStructType,

Expand Down
14 changes: 7 additions & 7 deletions crates/testsuite/features/cmd.feature
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ Feature: Rooch CLI integration tests
# use nostr_public_key
Then cmd: "account nullify -a {{$.account[-2].account0.nostr_public_key}}"

Then cmd: "rpc request --method rooch_getBalance --params '["{{$.address_mapping.default}}", "0x3::gas_coin::GasCoin"]' --json"
Then assert: "'{{$.rpc[-1].coin_type}}' == '0x3::gas_coin::GasCoin'"
Then cmd: "rpc request --method rooch_getBalance --params '["{{$.address_mapping.default}}", "0x3::gas_coin::RGas"]' --json"
Then assert: "'{{$.rpc[-1].coin_type}}' == '0x3::gas_coin::RGas'"
Then assert: "'{{$.rpc[-1].balance}}' == '0'"

# Get gas
Expand Down Expand Up @@ -80,8 +80,8 @@ Feature: Rooch CLI integration tests

# account balance
Then cmd: "account balance"
Then cmd: "account balance --coin-type rooch_framework::gas_coin::GasCoin"
Then cmd: "rpc request --method rooch_getBalance --params '["{{$.address_mapping.default}}", "0x3::gas_coin::GasCoin"]' --json"
Then cmd: "account balance --coin-type rooch_framework::gas_coin::RGas"
Then cmd: "rpc request --method rooch_getBalance --params '["{{$.address_mapping.default}}", "0x3::gas_coin::RGas"]' --json"
Then assert: "'{{$.rpc[-1].balance}}' != '0'"

Then stop the server
Expand All @@ -101,8 +101,8 @@ Feature: Rooch CLI integration tests
Then assert: "{{$.state[-1][0].decoded_value.value.id}} == 4"
Then cmd: "state --access-path /object/0x3::address_mapping::RoochToBitcoinAddressMapping"
Then assert: "{{$.state[-1][0].object_type}} == '0x3::address_mapping::RoochToBitcoinAddressMapping'"
Then cmd: "state --access-path /object/0x3::coin::CoinInfo<0x3::gas_coin::GasCoin>"
Then assert: "{{$.state[-1][0].object_type}} == '0x3::coin::CoinInfo<0x3::gas_coin::GasCoin>'"
Then cmd: "state --access-path /object/0x3::coin::CoinInfo<0x3::gas_coin::RGas>"
Then assert: "{{$.state[-1][0].object_type}} == '0x3::coin::CoinInfo<0x3::gas_coin::RGas>'"
Then stop the server

@serial
Expand Down Expand Up @@ -161,7 +161,7 @@ Feature: Rooch CLI integration tests
# Sync states
Then cmd: "object -t 0x3::coin::CoinInfo --limit 10 -d"
Then assert: "{{$.object[-1].data[0].tx_order}} == 1"
Then assert: "{{$.object[-1].data[0].object_type}} == 0x3::coin::CoinInfo<0x3::gas_coin::GasCoin>"
Then assert: "{{$.object[-1].data[0].object_type}} == 0x3::coin::CoinInfo<0x3::gas_coin::RGas>"
Then assert: "{{$.object[-1].has_next_page}} == false"

Then cmd: "rpc request --method rooch_listFieldStates --params '["{{$.address_mapping.default}}", null, "10", {"descending": true,"showDisplay":false}]' --json"
Expand Down
2 changes: 1 addition & 1 deletion crates/testsuite/features/multisign.feature
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Feature: Rooch CLI multisign integration tests
Then assert: "'{{$.account[-1]}}' not_contains error"

#transfer some gas to multisign account
Then cmd: "account transfer --to {{$.account[-1].multisign_address}} --amount 10000000000 --coin-type rooch_framework::gas_coin::GasCoin"
Then cmd: "account transfer --to {{$.account[-1].multisign_address}} --amount 10000000000 --coin-type rooch_framework::gas_coin::RGas"
Then assert: "{{$.account[-1].execution_info.status.type}} == executed"

# transaction
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Note: The Developer Testnet automatically updates to the `main` branch of the [R

## Deploying the Example Contract

Currently, the Developer Testnet automatically assigns `GasCoin` to developers, allowing them to deploy contracts directly through commands.
Currently, the Developer Testnet automatically assigns `RGas` to developers, allowing them to deploy contracts directly through commands.

```bash
git clone https://github.com/rooch-network/rooch.git
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ rooch env list

## 部署 Example 合约

当前,开发者测试网会自动给开发者分配 `GasCoin`,开发者可直接通过命令部署合约。
当前,开发者测试网会自动给开发者分配 `RGas`,开发者可直接通过命令部署合约。

```bash
git clone https://github.com/rooch-network/rooch.git
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ rooch account balance

Coin Type | Symbol | Decimals | Balance
--------------------------------------------------------------------
0x3::gas_coin::GasCoin | RGC | 8 | 1939625968
0x3::gas_coin::RGas | RGAS | 8 | 1939625968
```

[Get Rooch Gas Coin](./get-gas-coin.en-US)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ rooch account balance

Coin Type | Symbol | Decimals | Balance
--------------------------------------------------------------------
0x3::gas_coin::GasCoin | RGC | 8 | 1939625968
0x3::gas_coin::RGas | RGAS | 8 | 1939625968
```

[获取 Rooch Gas Coin](./get-gas-coin.zh-CN)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ This example will demonstrate the use of having a public type Coin.

```move
module coins::fixed_supply_coin {
use std::option;
use std::string;
use moveos_std::signer;
use moveos_std::object::{Self, Object};
Expand All @@ -44,6 +45,7 @@ module coins::fixed_supply_coin {
let coin_info_obj = coin::register_extend<FSC>(
string::utf8(b"Fixed Supply Coin"),
string::utf8(b"FSC"),
option::none(),
DECIMALS,
);
// Mint the total supply of coins, and store it to the treasury
Expand Down Expand Up @@ -91,6 +93,7 @@ This example introduces the usage of the private type Coin.
```move
module coins::private_coin {
use std::option;
use std::string;
use moveos_std::signer;
use moveos_std::object::{Self, Object};
Expand All @@ -112,6 +115,7 @@ module coins::private_coin {
let coin_info_obj = coin::register_extend<PRC>(
string::utf8(b"Private Coin"),
string::utf8(b"PRC"),
option::none(),
1,
);
object::transfer(coin_info_obj, @coins);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

```move
module coins::fixed_supply_coin {
use std::option;
use std::string;
use moveos_std::signer;
use moveos_std::object::{Self, Object};
Expand All @@ -44,6 +45,7 @@ module coins::fixed_supply_coin {
let coin_info_obj = coin::register_extend<FSC>(
string::utf8(b"Fixed Supply Coin"),
string::utf8(b"FSC"),
option::none(),
DECIMALS,
);
// Mint the total supply of coins, and store it to the treasury
Expand Down Expand Up @@ -91,6 +93,7 @@ module coins::fixed_supply_coin {
```move
module coins::private_coin {
use std::option;
use std::string;
use moveos_std::signer;
use moveos_std::object::{Self, Object};
Expand All @@ -112,6 +115,7 @@ module coins::private_coin {
let coin_info_obj = coin::register_extend<PRC>(
string::utf8(b"Private Coin"),
string::utf8(b"PRC"),
option::none(),
1,
);
object::transfer(coin_info_obj, @coins);
Expand Down
Loading

0 comments on commit d572c03

Please sign in to comment.