diff --git a/Cargo.lock b/Cargo.lock
index 87de1048dc..6486d5fb6b 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -640,6 +640,18 @@ dependencies = [
"syn 1.0.109",
]
+[[package]]
+name = "bigdecimal"
+version = "0.3.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a6773ddc0eafc0e509fb60e48dff7f450f8e674a0686ae8605e8d9901bd5eefa"
+dependencies = [
+ "num-bigint",
+ "num-integer",
+ "num-traits 0.2.16",
+ "serde 1.0.188",
+]
+
[[package]]
name = "binascii"
version = "0.1.4"
@@ -7492,6 +7504,7 @@ dependencies = [
"anyhow",
"async-trait",
"bcs",
+ "bigdecimal",
"chrono",
"clap 3.2.25",
"coerce",
@@ -7566,6 +7579,7 @@ dependencies = [
"hex",
"hyper",
"jsonrpsee",
+ "lazy_static 1.4.0",
"log",
"move-binary-format",
"move-bytecode-utils",
diff --git a/Cargo.toml b/Cargo.toml
index 67022cc8bc..2261f9ad42 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -121,7 +121,7 @@ ethereum-types = "0.14.1"
ethers = { version = "2.0.7", features = ["legacy"] }
eyre = "0.6.8"
fastcrypto = { git = "https://github.com/rooch-network/fastcrypto", rev = "aa5f9f308b6598779820db8b673050c10cfcc3c1" }
-futures = "0.3"
+futures = "0.3.28"
hex = "0.4.3"
rustc-hex = "1.0"
rust-embed = "6.8.1"
@@ -165,7 +165,7 @@ smallvec = "1.6.1"
thiserror = "1.0.34"
tiny-keccak = { version = "2", features = ["keccak", "sha3"] }
tiny-bip39 = "1.0.0"
-tokio = { version = "1", features = ["full"] }
+tokio = { version = "1.28.1", features = ["full"] }
tonic = { version = "0.8", features = ["gzip"] }
tracing = "0.1"
tracing-subscriber = "0.3"
@@ -202,6 +202,7 @@ bitcoin-bech32 = "0.13.0"
bs58 = "0.5.0"
dirs-next = "2.0.0"
anstream = { version = "0.3" }
+bigdecimal = { version = "0.3.0", features = ["serde"] }
# Note: the BEGIN and END comments below are required for external tooling. Do not remove.
# BEGIN MOVE DEPENDENCIES
diff --git a/crates/rooch-framework/doc/coin.md b/crates/rooch-framework/doc/coin.md
index 2a1aeb8caf..873743af39 100644
--- a/crates/rooch-framework/doc/coin.md
+++ b/crates/rooch-framework/doc/coin.md
@@ -28,6 +28,7 @@ This module provides the foundation for typesafe Coins.
- [Function `supply`](#0x3_coin_supply)
- [Function `is_same_coin`](#0x3_coin_is_same_coin)
- [Function `coin_store_handle`](#0x3_coin_coin_store_handle)
+- [Function `coin_info_handle`](#0x3_coin_coin_info_handle)
- [Function `is_account_accept_coin`](#0x3_coin_is_account_accept_coin)
- [Function `can_auto_accept_coin`](#0x3_coin_can_auto_accept_coin)
- [Function `do_accept_coin`](#0x3_coin_do_accept_coin)
@@ -853,6 +854,33 @@ Return coin store handle for addr
+
+
+
+
+## Function `coin_info_handle`
+
+Return coin info handle
+
+
+
public fun coin_info_handle(ctx: &storage_context::StorageContext): object_id::ObjectID
+
+
+
+
+
+Implementation
+
+
+public fun coin_info_handle(ctx: &StorageContext): ObjectID {
+ // coin info ensured via the Genesis transaction, so it should always exist
+ let coin_infos = account_storage::global_borrow<CoinInfos>(ctx, @rooch_framework);
+ *type_table::handle(&coin_infos.coin_infos)
+}
+
+
+
+
diff --git a/crates/rooch-framework/sources/coin.move b/crates/rooch-framework/sources/coin.move
index ce22c3b816..1f26e328b4 100644
--- a/crates/rooch-framework/sources/coin.move
+++ b/crates/rooch-framework/sources/coin.move
@@ -239,6 +239,13 @@ module rooch_framework::coin {
}
}
+ /// Return coin info handle
+ public fun coin_info_handle(ctx: &StorageContext): ObjectID {
+ // coin info ensured via the Genesis transaction, so it should always exist
+ let coin_infos = account_storage::global_borrow(ctx, @rooch_framework);
+ *type_table::handle(&coin_infos.coin_infos)
+ }
+
//
// Helper functions
//
diff --git a/crates/rooch-open-rpc-spec/schemas/openrpc.json b/crates/rooch-open-rpc-spec/schemas/openrpc.json
index 56f0b7e557..6504e6236d 100644
--- a/crates/rooch-open-rpc-spec/schemas/openrpc.json
+++ b/crates/rooch-open-rpc-spec/schemas/openrpc.json
@@ -85,6 +85,46 @@
}
}
},
+ {
+ "name": "rooch_getBalances",
+ "description": "get account balances by AccountAddress",
+ "params": [
+ {
+ "name": "account_addr",
+ "required": true,
+ "schema": {
+ "$ref": "#/components/schemas/move_core_types::account_address::AccountAddress"
+ }
+ },
+ {
+ "name": "coin_type",
+ "schema": {
+ "$ref": "#/components/schemas/move_core_types::language_storage::StructTag"
+ }
+ },
+ {
+ "name": "cursor",
+ "schema": {
+ "$ref": "#/components/schemas/alloc::vec::Vec"
+ }
+ },
+ {
+ "name": "limit",
+ "schema": {
+ "type": "integer",
+ "format": "uint",
+ "minimum": 0.0
+ }
+ }
+ ],
+ "result": {
+ "name": "ListBalanceInfoPageView",
+ "required": true,
+ "schema": {
+ "$ref": "#/components/schemas/PageView_for_Nullable_BalanceInfoView_and_alloc::vec::Vec"
+ }
+ }
+ },
{
"name": "rooch_getEvents",
"description": "Get the events by event filter",
@@ -563,6 +603,31 @@
}
}
},
+ "BalanceInfoView": {
+ "type": "object",
+ "required": [
+ "balance",
+ "coin_type",
+ "decimals",
+ "symbol"
+ ],
+ "properties": {
+ "balance": {
+ "$ref": "#/components/schemas/move_core_types::u256::U256"
+ },
+ "coin_type": {
+ "$ref": "#/components/schemas/move_core_types::language_storage::StructTag"
+ },
+ "decimals": {
+ "type": "integer",
+ "format": "uint8",
+ "minimum": 0.0
+ },
+ "symbol": {
+ "type": "string"
+ }
+ }
+ },
"EventFilterView": {
"oneOf": [
{
@@ -1156,6 +1221,42 @@
}
}
},
+ "PageView_for_Nullable_BalanceInfoView_and_alloc::vec::Vec": {
+ "description": "`next_cursor` points to the last item in the page; Reading with `next_cursor` will start from the next item after `next_cursor` if `next_cursor` is `Some`, otherwise it will start from the first item.",
+ "type": "object",
+ "required": [
+ "data",
+ "has_next_page"
+ ],
+ "properties": {
+ "data": {
+ "type": "array",
+ "items": {
+ "anyOf": [
+ {
+ "$ref": "#/components/schemas/BalanceInfoView"
+ },
+ {
+ "type": "null"
+ }
+ ]
+ }
+ },
+ "has_next_page": {
+ "type": "boolean"
+ },
+ "next_cursor": {
+ "anyOf": [
+ {
+ "$ref": "#/components/schemas/alloc::vec::Vec"
+ },
+ {
+ "type": "null"
+ }
+ ]
+ }
+ }
+ },
"PageView_for_Nullable_StateView_and_alloc::vec::Vec": {
"description": "`next_cursor` points to the last item in the page; Reading with `next_cursor` will start from the next item after `next_cursor` if `next_cursor` is `Some`, otherwise it will start from the first item.",
"type": "object",
diff --git a/crates/rooch-rpc-api/Cargo.toml b/crates/rooch-rpc-api/Cargo.toml
index 0e52c64020..9d00feb4eb 100644
--- a/crates/rooch-rpc-api/Cargo.toml
+++ b/crates/rooch-rpc-api/Cargo.toml
@@ -34,6 +34,7 @@ schemars = { workspace = true }
serde_with = { workspace = true }
rand = { workspace = true }
fastcrypto = { workspace = true }
+bigdecimal = { workspace = true }
move-core-types = { workspace = true }
move-resource-viewer = { workspace = true }
diff --git a/crates/rooch-rpc-api/src/api/mod.rs b/crates/rooch-rpc-api/src/api/mod.rs
index a976711c9a..78f06baa41 100644
--- a/crates/rooch-rpc-api/src/api/mod.rs
+++ b/crates/rooch-rpc-api/src/api/mod.rs
@@ -7,7 +7,10 @@ pub mod eth_api;
pub mod rooch_api;
pub mod wallet_api;
-pub const MAX_RESULT_LIMIT: u64 = 50;
+pub const DEFAULT_RESULT_LIMIT: u64 = 50;
+pub const DEFAULT_RESULT_LIMIT_USIZE: usize = DEFAULT_RESULT_LIMIT as usize;
+
+pub const MAX_RESULT_LIMIT: u64 = 200;
pub const MAX_RESULT_LIMIT_USIZE: usize = MAX_RESULT_LIMIT as usize;
// pub fn validate_limit(limit: Option, max: usize) -> Result {
diff --git a/crates/rooch-rpc-api/src/api/rooch_api.rs b/crates/rooch-rpc-api/src/api/rooch_api.rs
index 45e7ccc2d8..61e49f2a03 100644
--- a/crates/rooch-rpc-api/src/api/rooch_api.rs
+++ b/crates/rooch-rpc-api/src/api/rooch_api.rs
@@ -2,10 +2,11 @@
// SPDX-License-Identifier: Apache-2.0
use crate::jsonrpc_types::{
- AccessPathView, AnnotatedEventView, AnnotatedFunctionResultView, AnnotatedStateView,
- EventFilterView, EventPageView, ExecuteTransactionResponseView, FunctionCallView, H256View,
- ListAnnotatedStatesPageView, ListStatesPageView, StateView, StrView, StructTagView,
- TransactionExecutionInfoView, TransactionInfoPageView, TransactionView,
+ AccessPathView, AccountAddressView, AnnotatedEventView, AnnotatedFunctionResultView,
+ AnnotatedStateView, EventFilterView, EventPageView, ExecuteTransactionResponseView,
+ FunctionCallView, H256View, ListAnnotatedStatesPageView, ListBalanceInfoPageView,
+ ListStatesPageView, StateView, StrView, StructTagView, TransactionExecutionInfoView,
+ TransactionInfoPageView, TransactionView,
};
use jsonrpsee::core::RpcResult;
use jsonrpsee::proc_macros::rpc;
@@ -104,4 +105,14 @@ pub trait RoochAPI {
&self,
tx_hashes: Vec,
) -> RpcResult>>;
+
+ /// get account balances by AccountAddress
+ #[method(name = "getBalances")]
+ async fn get_balances(
+ &self,
+ account_addr: AccountAddressView,
+ coin_type: Option,
+ cursor: Option>>,
+ limit: Option,
+ ) -> RpcResult;
}
diff --git a/crates/rooch-rpc-api/src/jsonrpc_types/account_view.rs b/crates/rooch-rpc-api/src/jsonrpc_types/account_view.rs
index fa31e87dda..0aa5c5fec0 100644
--- a/crates/rooch-rpc-api/src/jsonrpc_types/account_view.rs
+++ b/crates/rooch-rpc-api/src/jsonrpc_types/account_view.rs
@@ -1,12 +1,14 @@
// Copyright (c) RoochNetwork
// SPDX-License-Identifier: Apache-2.0
-use crate::jsonrpc_types::StructTagView;
+use crate::jsonrpc_types::{StrView, StructTagView};
use move_core_types::u256::U256;
use rooch_types::account::{AccountInfo, BalanceInfo};
+use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
+use std::ops::Div;
-#[derive(Debug, Clone, Serialize, Deserialize)]
+#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
pub struct AccountInfoView {
pub sequence_number: u64,
pub balances: Vec