diff --git a/CHANGELOG.md b/CHANGELOG.md index 10f26fcf3..b2f77fb3b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +# [v0.4.4](https://github.com/nervosnetwork/mercury/compare/v0.4.3...v0.4.4) (2022-10-08) + +## 🚀 Features + +- feat(rpc): add `extra` para in rpc `get_balance` (#450) + # [v0.4.3](https://github.com/nervosnetwork/mercury/compare/v0.4.2...v0.4.3) (2022-09-19) ## 🐛 Bug Fixes diff --git a/Cargo.lock b/Cargo.lock index ce4f53368..8e9e74be9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -451,7 +451,7 @@ dependencies = [ [[package]] name = "common" -version = "0.4.3" +version = "0.4.4" dependencies = [ "anyhow", "async-trait", @@ -491,7 +491,7 @@ checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e" [[package]] name = "core-ckb-client" -version = "0.4.3" +version = "0.4.4" dependencies = [ "ckb-jsonrpc-types", "ckb-types", @@ -508,7 +508,7 @@ dependencies = [ [[package]] name = "core-cli" -version = "0.4.3" +version = "0.4.4" dependencies = [ "ansi_term", "ckb-jsonrpc-types", @@ -544,7 +544,7 @@ checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc" [[package]] name = "core-rpc" -version = "0.4.3" +version = "0.4.4" dependencies = [ "arc-swap 1.5.0", "ckb-dao-utils", @@ -580,7 +580,7 @@ dependencies = [ [[package]] name = "core-rpc-types" -version = "0.4.3" +version = "0.4.4" dependencies = [ "arc-swap 1.5.0", "ckb-jsonrpc-types", @@ -597,7 +597,7 @@ dependencies = [ [[package]] name = "core-service" -version = "0.4.3" +version = "0.4.4" dependencies = [ "ckb-jsonrpc-types", "ckb-types", @@ -617,7 +617,7 @@ dependencies = [ [[package]] name = "core-storage" -version = "0.4.3" +version = "0.4.4" dependencies = [ "arc-swap 1.5.0", "ckb-jsonrpc-types", @@ -645,7 +645,7 @@ dependencies = [ [[package]] name = "core-synchronization" -version = "0.4.3" +version = "0.4.4" dependencies = [ "ckb-jsonrpc-types", "ckb-types", @@ -1873,7 +1873,7 @@ dependencies = [ [[package]] name = "mercury" -version = "0.4.3" +version = "0.4.4" dependencies = [ "core-cli", "criterion", @@ -2368,7 +2368,7 @@ dependencies = [ [[package]] name = "protocol" -version = "0.4.3" +version = "0.4.4" dependencies = [ "ckb-jsonrpc-types", "ckb-types", diff --git a/Cargo.toml b/Cargo.toml index 77541a921..5ad0f4e83 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "mercury" description = "Mercury is a tool that handles application development on CKB." -version = "0.4.3" +version = "0.4.4" authors = ["Nervos Network"] edition = "2021" diff --git a/common/Cargo.toml b/common/Cargo.toml index 5f45ed307..24fe3fa40 100644 --- a/common/Cargo.toml +++ b/common/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "common" -version = "0.4.3" +version = "0.4.4" authors = ["Nervos Network"] edition = "2021" diff --git a/core/ckb-client/Cargo.toml b/core/ckb-client/Cargo.toml index fc1f0ffd9..bdabb265a 100644 --- a/core/ckb-client/Cargo.toml +++ b/core/ckb-client/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "core-ckb-client" -version = "0.4.3" +version = "0.4.4" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/core/cli/Cargo.toml b/core/cli/Cargo.toml index 47bbbc009..4db622595 100644 --- a/core/cli/Cargo.toml +++ b/core/cli/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "core-cli" -version = "0.4.3" +version = "0.4.4" authors = ["Nervos Network"] edition = "2021" diff --git a/core/rpc/README.md b/core/rpc/README.md index 7f31df7a6..f4726f992 100644 --- a/core/rpc/README.md +++ b/core/rpc/README.md @@ -116,6 +116,7 @@ The error code ranges are as follows: - `item`: [`JsonItem`](#type-jsonitem) - `asset_infos`: `Array<`[`AssetInfo`](#type-assetinfo)`>` - `tip_block_number`: [`BlockNumber`](#type-blocknumber)`|null` + - `extra`: `"Dao"|"Cellbase"|null` - result - `tip_block_number`: [`BlockNumber`](#type-blocknumber) - `balances`: `Array<`[`Balance`](#type-balance)`>` @@ -135,6 +136,10 @@ To return the balance of specified assets for the given item. - If `tip_block_number` is not null, the query is based on the historical blockchain with the specified tip. - `asset_infos` - Specify a set of asset types for the query. - If `asset_infos` is empty, the query returns the balance of any asset matching the query parameters. +- `extra` - Specify the filter applying to the querying. + - If `extra` is null, the query does not apply extra filter. + - If `extra` is `Dao`, the query will filter and keep the balance of cells that satisfy `type script` as `Dao`. + - If `extra` is `Cellbase`, the query will filter and keep the balance of cells satisfying `Cellbase`. **Returns** @@ -1793,7 +1798,7 @@ echo '{ { "jsonrpc": "2.0", "result": { - "mercury_version": "0.4.3", + "mercury_version": "0.4.4", "ckb_node_version": "0.104.0 (4dd90d4 2022-07-19)", "network_type": "Testnet", "enabled_extensions": [ ] @@ -1837,7 +1842,7 @@ echo '{ { "jsonrpc": "2.0", "result": { - "version": "0.4.3", + "version": "0.4.4", "db": "PostgreSQL", "conn_size": 100, "center_id": 0, diff --git a/core/rpc/core/Cargo.toml b/core/rpc/core/Cargo.toml index aedc4b15e..86c5a5e5d 100644 --- a/core/rpc/core/Cargo.toml +++ b/core/rpc/core/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "core-rpc" -version = "0.4.3" +version = "0.4.4" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/core/rpc/core/src/impl/query.rs b/core/rpc/core/src/impl/query.rs index 5eb9f196f..bec52b8a3 100644 --- a/core/rpc/core/src/impl/query.rs +++ b/core/rpc/core/src/impl/query.rs @@ -55,7 +55,7 @@ impl MercuryRpcImpl { payload.tip_block_number.map(Into::into), tip_epoch_number.clone(), None, - None, + payload.extra, &mut PaginationRequest::default(), ) .await?; diff --git a/core/rpc/types/Cargo.toml b/core/rpc/types/Cargo.toml index 78028fba4..a1a0dc805 100644 --- a/core/rpc/types/Cargo.toml +++ b/core/rpc/types/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "core-rpc-types" -version = "0.4.3" +version = "0.4.4" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/core/rpc/types/src/lib.rs b/core/rpc/types/src/lib.rs index 539d643bd..ae60cf866 100644 --- a/core/rpc/types/src/lib.rs +++ b/core/rpc/types/src/lib.rs @@ -323,6 +323,7 @@ pub struct BurnInfo { pub struct GetBalancePayload { pub item: JsonItem, pub asset_infos: HashSet, + pub extra: Option, pub tip_block_number: Option, } diff --git a/core/service/Cargo.toml b/core/service/Cargo.toml index e86076a44..172ef727a 100644 --- a/core/service/Cargo.toml +++ b/core/service/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "core-service" -version = "0.4.3" +version = "0.4.4" authors = ["Nervos Network"] edition = "2021" diff --git a/core/storage/Cargo.toml b/core/storage/Cargo.toml index ae5bd1299..852ff5b6a 100644 --- a/core/storage/Cargo.toml +++ b/core/storage/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "core-storage" -version = "0.4.3" +version = "0.4.4" authors = ["Nervos Network"] edition = "2021" diff --git a/core/storage/src/relational/insert.rs b/core/storage/src/relational/insert.rs index aa284c2b0..aad7a11f8 100644 --- a/core/storage/src/relational/insert.rs +++ b/core/storage/src/relational/insert.rs @@ -22,16 +22,6 @@ pub const BLAKE_160_HSAH_LEN: usize = 20; pub const IO_TYPE_INPUT: u8 = 0; pub const IO_TYPE_OUTPUT: u8 = 1; -#[macro_export] -macro_rules! save_batch_slice { - ($tx: expr$ (, $table: expr)*) => {{ - $(if $tx.save_batch_slice(&$table, BATCH_SIZE_THRESHOLD, &[]).await.is_err() { - $tx.rollback().await?; - return Ok(()); - })* - }}; -} - impl RelationalStorage { pub(crate) async fn insert_block_table( &self, diff --git a/core/synchronization/Cargo.toml b/core/synchronization/Cargo.toml index 3c2a13172..bf9958a1a 100644 --- a/core/synchronization/Cargo.toml +++ b/core/synchronization/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "core-synchronization" -version = "0.4.3" +version = "0.4.4" authors = ["Nervos Network"] edition = "2021" diff --git a/docker-compose.yml b/docker-compose.yml index 9eb130462..b7f719587 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -41,7 +41,7 @@ services: mercury: container_name: mercury restart: always - image: nervos/mercury:v0.4.3 + image: nervos/mercury:v0.4.4 ports: - 8116:8116 volumes: diff --git a/docs/migration.md b/docs/migration.md index bf2a4e76c..e43b92b1a 100644 --- a/docs/migration.md +++ b/docs/migration.md @@ -1,5 +1,9 @@ # Migration instruction +## 0.4.4 Release + +No migration matters. + ## 0.4.3 Release No migration matters. diff --git a/docs/setup.md b/docs/setup.md index 00d582b5e..f955de1c3 100644 --- a/docs/setup.md +++ b/docs/setup.md @@ -27,7 +27,7 @@ Clone the repository and checkout the tag of the version you intend to use. Usin ```sh git clone https://github.com/nervosnetwork/mercury.git cd mercury -git checkout v0.4.3 +git checkout v0.4.4 ``` ### Step 3: Build Mercury @@ -55,13 +55,13 @@ We will not be building from source, but there are still some valuable files. Cl ```sh git clone https://github.com/nervosnetwork/mercury.git cd mercury -git checkout v0.4.3 +git checkout v0.4.4 ``` ### Step 3: Download and Extract a Precompiled Binary ```sh -wget https://github.com/nervosnetwork/mercury/releases/download/v0.4.3/mercury-x86_64-unknown-linux-gnu.tar.gz +wget https://github.com/nervosnetwork/mercury/releases/download/v0.4.4/mercury-x86_64-unknown-linux-gnu.tar.gz tar xzf mercury-x86_64-unknown-linux-gnu.tar.gz ``` diff --git a/integration/Cargo.lock b/integration/Cargo.lock index 2e9c63284..a56dd732f 100644 --- a/integration/Cargo.lock +++ b/integration/Cargo.lock @@ -301,7 +301,7 @@ dependencies = [ [[package]] name = "common" -version = "0.4.3" +version = "0.4.4" dependencies = [ "anyhow", "async-trait", @@ -341,7 +341,7 @@ checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc" [[package]] name = "core-rpc-types" -version = "0.4.3" +version = "0.4.4" dependencies = [ "arc-swap", "ckb-jsonrpc-types", @@ -1171,7 +1171,7 @@ dependencies = [ [[package]] name = "protocol" -version = "0.4.3" +version = "0.4.4" dependencies = [ "ckb-jsonrpc-types", "ckb-types", diff --git a/integration/src/tests/build_adjust_account_transaction.rs b/integration/src/tests/build_adjust_account_transaction.rs index 4173f7e82..72b38ab47 100644 --- a/integration/src/tests/build_adjust_account_transaction.rs +++ b/integration/src/tests/build_adjust_account_transaction.rs @@ -38,6 +38,7 @@ fn test_adjust_account() { let payload = GetBalancePayload { item: JsonItem::Address(acp_address.to_string()), asset_infos, + extra: None, tip_block_number: None, }; let response = mercury_client.get_balance(payload.clone()).unwrap(); @@ -79,6 +80,7 @@ fn test_adjust_account_pw_lock() { let payload = GetBalancePayload { item: JsonItem::Address(pw_lock_address.to_string()), asset_infos, + extra: None, tip_block_number: None, }; let response = mercury_client.get_balance(payload.clone()).unwrap(); @@ -144,6 +146,7 @@ fn test_adjust_account_from_multi() { let payload = GetBalancePayload { item: JsonItem::Address(acp_address.to_string()), asset_infos, + extra: None, tip_block_number: None, }; let response = mercury_client.get_balance(payload.clone()).unwrap(); diff --git a/integration/src/tests/build_dao_related_transaction.rs b/integration/src/tests/build_dao_related_transaction.rs index 2797d60c9..92eebd95b 100644 --- a/integration/src/tests/build_dao_related_transaction.rs +++ b/integration/src/tests/build_dao_related_transaction.rs @@ -44,6 +44,7 @@ fn test_dao_by_address() { let balance_payload = GetBalancePayload { item: JsonItem::Address(address.to_string()), asset_infos, + extra: None, tip_block_number: None, }; let balance = mercury_client.get_balance(balance_payload.clone()).unwrap(); @@ -193,6 +194,7 @@ fn test_dao_pool_money() { let balance_payload = GetBalancePayload { item: JsonItem::Address(address.to_string()), asset_infos, + extra: None, tip_block_number: None, }; let balance = mercury_client.get_balance(balance_payload).unwrap(); @@ -257,6 +259,7 @@ fn test_dao_by_out_point() { let balance_payload_1 = GetBalancePayload { item: JsonItem::Address(address_1.to_string()), asset_infos: asset_infos.clone(), + extra: None, tip_block_number: None, }; let balance = mercury_client @@ -270,6 +273,7 @@ fn test_dao_by_out_point() { let balance_payload_2 = GetBalancePayload { item: JsonItem::Address(address_2.to_string()), asset_infos, + extra: None, tip_block_number: None, }; let balance = mercury_client diff --git a/integration/src/tests/build_simple_transfer_transaction.rs b/integration/src/tests/build_simple_transfer_transaction.rs index 6dcd5f099..2bbeef326 100644 --- a/integration/src/tests/build_simple_transfer_transaction.rs +++ b/integration/src/tests/build_simple_transfer_transaction.rs @@ -53,6 +53,7 @@ fn test_simple_transfer_ckb() { let payload = GetBalancePayload { item: JsonItem::Address(to_address.to_string()), asset_infos, + extra: None, tip_block_number: None, }; let to_balance = mercury_client.get_balance(payload).unwrap(); @@ -67,6 +68,7 @@ fn test_simple_transfer_ckb() { let payload = GetBalancePayload { item: JsonItem::Address(from_address.to_string()), asset_infos, + extra: None, tip_block_number: None, }; let from_balance = mercury_client.get_balance(payload).unwrap(); @@ -130,6 +132,7 @@ fn test_simple_transfer_udt_to_provide_capacity() { let payload = GetBalancePayload { item: JsonItem::Identity(hex::encode(to_identity.0)), asset_infos, + extra: None, tip_block_number: None, }; let to_balance = mercury_client.get_balance(payload).unwrap(); @@ -201,6 +204,7 @@ fn test_simple_transfer_udt_from_provide_capacity() { let payload = GetBalancePayload { item: JsonItem::Identity(hex::encode(to_identity.0)), asset_infos, + extra: None, tip_block_number: None, }; let to_balance = mercury_client.get_balance(payload).unwrap(); @@ -212,6 +216,7 @@ fn test_simple_transfer_udt_from_provide_capacity() { let payload = GetBalancePayload { item: JsonItem::Address(from_address.to_string()), asset_infos, + extra: None, tip_block_number: None, }; let from_balance = mercury_client.get_balance(payload).unwrap(); diff --git a/integration/src/tests/build_sudt_issue_transaction.rs b/integration/src/tests/build_sudt_issue_transaction.rs index 772c3dcf5..7b08c1fc7 100644 --- a/integration/src/tests/build_sudt_issue_transaction.rs +++ b/integration/src/tests/build_sudt_issue_transaction.rs @@ -40,6 +40,7 @@ fn test_issue_udt_from_provide_capacity() { let payload_to = GetBalancePayload { item: JsonItem::Identity(to_identity.encode()), asset_infos, + extra: None, tip_block_number: None, }; let to_balance = mercury_client.get_balance(payload_to).unwrap(); @@ -110,6 +111,7 @@ fn test_issue_udt_from_multi_item() { let payload_to = GetBalancePayload { item: JsonItem::Identity(to_identity.encode()), asset_infos, + extra: None, tip_block_number: None, }; let to_balance = mercury_client.get_balance(payload_to.clone()).unwrap(); diff --git a/integration/src/tests/build_transfer_transaction_ckb.rs b/integration/src/tests/build_transfer_transaction_ckb.rs index b5f3a4d0b..9381dc317 100644 --- a/integration/src/tests/build_transfer_transaction_ckb.rs +++ b/integration/src/tests/build_transfer_transaction_ckb.rs @@ -51,6 +51,7 @@ fn test_transfer_ckb_from_provide_capacity() { let payload = GetBalancePayload { item: JsonItem::Address(to_address.to_string()), asset_infos, + extra: None, tip_block_number: None, }; let to_balance = mercury_client.get_balance(payload).unwrap(); @@ -65,6 +66,7 @@ fn test_transfer_ckb_from_provide_capacity() { let payload = GetBalancePayload { item: JsonItem::Address(from_address.to_string()), asset_infos, + extra: None, tip_block_number: None, }; let from_balance = mercury_client.get_balance(payload).unwrap(); @@ -131,6 +133,7 @@ fn test_transfer_ckb_to_provide_capacity() { let payload = GetBalancePayload { item: JsonItem::Address(from_address.to_string()), asset_infos, + extra: None, tip_block_number: None, }; let from_balance = mercury_client.get_balance(payload).unwrap(); @@ -181,6 +184,7 @@ fn test_change_to_new_output() { let payload = GetBalancePayload { item: JsonItem::Address(from_address_1.to_string()), asset_infos: asset_infos.clone(), + extra: None, tip_block_number: None, }; let balance = mercury_client.get_balance(payload).unwrap(); @@ -189,6 +193,7 @@ fn test_change_to_new_output() { let payload = GetBalancePayload { item: JsonItem::Address(from_acp_address_1.to_string()), asset_infos, + extra: None, tip_block_number: None, }; let balance = mercury_client.get_balance(payload).unwrap(); @@ -226,6 +231,7 @@ fn test_change_to_new_output() { let payload = GetBalancePayload { item: JsonItem::Address(from_address_2.to_string()), asset_infos, + extra: None, tip_block_number: None, }; let balance = mercury_client.get_balance(payload).unwrap(); @@ -295,6 +301,7 @@ fn test_transfer_ckb_from_provide_capacity_out_point() { let payload = GetBalancePayload { item: JsonItem::Address(from_2_address.to_string()), asset_infos, + extra: None, tip_block_number: None, }; let balance = mercury_client.get_balance(payload).unwrap(); @@ -343,6 +350,7 @@ fn test_transfer_ckb_from_provide_capacity_to_acp_address() { let payload = GetBalancePayload { item: JsonItem::Address(to_acp_address.to_string()), asset_infos, + extra: None, tip_block_number: None, }; let balance = mercury_client.get_balance(payload).unwrap(); @@ -390,6 +398,7 @@ fn test_transfer_ckb_from_provide_capacity_pay_fee_to() { let payload = GetBalancePayload { item: JsonItem::Address(from_address.to_string()), asset_infos, + extra: None, tip_block_number: None, }; let from_balance = mercury_client.get_balance(payload).unwrap(); @@ -408,6 +417,7 @@ fn test_transfer_ckb_from_provide_capacity_pay_fee_to() { let payload = GetBalancePayload { item: JsonItem::Address(to_address_secp.to_string()), asset_infos, + extra: None, tip_block_number: None, }; let balance = mercury_client.get_balance(payload).unwrap(); @@ -471,6 +481,7 @@ fn test_transfer_ckb_to_provide_capacity_to_pay_fee() { let payload = GetBalancePayload { item: JsonItem::Address(from_address.to_string()), asset_infos, + extra: None, tip_block_number: None, }; let balance = mercury_client.get_balance(payload).unwrap(); @@ -486,6 +497,7 @@ fn test_transfer_ckb_to_provide_capacity_to_pay_fee() { let payload = GetBalancePayload { item: JsonItem::Address(to_acp_address.to_string()), asset_infos, + extra: None, tip_block_number: None, }; let balance = mercury_client.get_balance(payload).unwrap(); @@ -543,6 +555,7 @@ fn test_change_to_new_acp() { let payload = GetBalancePayload { item: JsonItem::Address(from_address_1.to_string()), asset_infos: asset_infos.clone(), + extra: None, tip_block_number: None, }; let balance = mercury_client.get_balance(payload).unwrap(); @@ -551,6 +564,7 @@ fn test_change_to_new_acp() { let payload = GetBalancePayload { item: JsonItem::Address(from_acp_address_1.to_string()), asset_infos, + extra: None, tip_block_number: None, }; let balance = mercury_client.get_balance(payload).unwrap(); @@ -590,6 +604,7 @@ fn test_change_to_new_acp() { let payload = GetBalancePayload { item: JsonItem::Address(from_address_3.to_string()), asset_infos: asset_infos.clone(), + extra: None, tip_block_number: None, }; let balance = mercury_client.get_balance(payload).unwrap(); @@ -601,6 +616,7 @@ fn test_change_to_new_acp() { let payload = GetBalancePayload { item: JsonItem::Address(from_acp_address_2.to_string()), asset_infos, + extra: None, tip_block_number: None, }; let balance = mercury_client.get_balance(payload).unwrap(); @@ -614,6 +630,7 @@ fn test_change_to_new_acp() { let payload = GetBalancePayload { item: JsonItem::Address(from_acp_address_1.to_string()), asset_infos: asset_infos.clone(), + extra: None, tip_block_number: None, }; let balance = mercury_client.get_balance(payload).unwrap(); @@ -674,6 +691,7 @@ fn test_change_need_pool() { let payload = GetBalancePayload { item: JsonItem::Address(from_address_2.to_string()), asset_infos: asset_infos.clone(), + extra: None, tip_block_number: None, }; let balance = mercury_client.get_balance(payload).unwrap(); @@ -756,6 +774,7 @@ fn test_change_to_output_acp() { let payload = GetBalancePayload { item: JsonItem::Address(from_address_3.to_string()), asset_infos: asset_infos.clone(), + extra: None, tip_block_number: None, }; let balance = mercury_client.get_balance(payload).unwrap(); @@ -765,6 +784,7 @@ fn test_change_to_output_acp() { let payload = GetBalancePayload { item: JsonItem::Address(from_acp_address_2.to_string()), asset_infos, + extra: None, tip_block_number: None, }; let balance = mercury_client.get_balance(payload).unwrap(); @@ -780,6 +800,7 @@ fn test_change_to_output_acp() { let payload = GetBalancePayload { item: JsonItem::Address(from_acp_address_1.to_string()), asset_infos: asset_infos.clone(), + extra: None, tip_block_number: None, }; let balance = mercury_client.get_balance(payload).unwrap(); diff --git a/integration/src/tests/build_transfer_transaction_ckb_pw.rs b/integration/src/tests/build_transfer_transaction_ckb_pw.rs index f60020309..618f49454 100644 --- a/integration/src/tests/build_transfer_transaction_ckb_pw.rs +++ b/integration/src/tests/build_transfer_transaction_ckb_pw.rs @@ -47,6 +47,7 @@ fn test_transfer_ckb_from_provide_capacity_pw() { let payload = GetBalancePayload { item: JsonItem::Address(to_address.to_string()), asset_infos, + extra: None, tip_block_number: None, }; let to_balance = mercury_client.get_balance(payload).unwrap(); @@ -61,6 +62,7 @@ fn test_transfer_ckb_from_provide_capacity_pw() { let payload = GetBalancePayload { item: JsonItem::Address(from_address.to_string()), asset_infos, + extra: None, tip_block_number: None, }; let from_balance = mercury_client.get_balance(payload).unwrap(); @@ -111,6 +113,7 @@ fn test_transfer_ckb_from_provide_capacity_pw_pay_fee_to() { let payload = GetBalancePayload { item: JsonItem::Address(to_address.to_string()), asset_infos, + extra: None, tip_block_number: None, }; let to_balance = mercury_client.get_balance(payload).unwrap(); @@ -126,6 +129,7 @@ fn test_transfer_ckb_from_provide_capacity_pw_pay_fee_to() { let payload = GetBalancePayload { item: JsonItem::Address(from_address.to_string()), asset_infos, + extra: None, tip_block_number: None, }; let from_balance = mercury_client.get_balance(payload).unwrap(); diff --git a/integration/src/tests/build_transfer_transaction_udt.rs b/integration/src/tests/build_transfer_transaction_udt.rs index 267fe7363..5fb1cd560 100644 --- a/integration/src/tests/build_transfer_transaction_udt.rs +++ b/integration/src/tests/build_transfer_transaction_udt.rs @@ -96,6 +96,7 @@ fn test_transfer_udt_to_provide_capacity_from_identity_has_in_lock_cheque() { let payload = GetBalancePayload { item: JsonItem::Address(receiver_address.to_string()), asset_infos: HashSet::new(), + extra: None, tip_block_number: None, }; let from_balance = mercury_client.get_balance(payload).unwrap(); @@ -161,6 +162,7 @@ fn test_transfer_udt_to_provide_capacity_from_sender_cheque() { let payload = GetBalancePayload { item: JsonItem::Address(sender_address.to_string()), asset_infos: HashSet::new(), + extra: None, tip_block_number: None, }; let from_balance = mercury_client.get_balance(payload).unwrap(); @@ -227,6 +229,7 @@ fn test_transfer_udt_to_provide_capacity_from_receiver_cheque() { let payload = GetBalancePayload { item: JsonItem::Address(receiver_address.to_string()), asset_infos: HashSet::new(), + extra: None, tip_block_number: None, }; let from_balance = mercury_client.get_balance(payload).unwrap(); @@ -291,6 +294,7 @@ fn test_transfer_udt_to_provide_capacity_from_receiver_cheque_change_udt() { let payload = GetBalancePayload { item: JsonItem::Address(receiver_address.to_string()), asset_infos: HashSet::new(), + extra: None, tip_block_number: None, }; let from_balance = mercury_client.get_balance(payload).unwrap(); @@ -304,6 +308,7 @@ fn test_transfer_udt_to_provide_capacity_from_receiver_cheque_change_udt() { let payload = GetBalancePayload { item: JsonItem::Address(sender_address.to_string()), asset_infos: HashSet::new(), + extra: None, tip_block_number: None, }; let balance = mercury_client.get_balance(payload).unwrap(); @@ -375,6 +380,7 @@ fn test_transfer_udt_to_provide_capacity_from_receiver_has_cheque_change_udt_to_ let payload = GetBalancePayload { item: JsonItem::Identity(hex::encode(udt_identity.0)), asset_infos: HashSet::new(), + extra: None, tip_block_number: None, }; let from_balance = mercury_client.get_balance(payload).unwrap(); @@ -388,6 +394,7 @@ fn test_transfer_udt_to_provide_capacity_from_receiver_has_cheque_change_udt_to_ let payload = GetBalancePayload { item: JsonItem::Address(sender_address.to_string()), asset_infos: HashSet::new(), + extra: None, tip_block_number: None, }; let balance = mercury_client.get_balance(payload).unwrap(); @@ -462,6 +469,7 @@ fn test_transfer_udt_to_provide_capacity_from_out_point_cheque_part_claim() { let payload = GetBalancePayload { item: JsonItem::Address(receiver_address.to_string()), asset_infos: HashSet::new(), + extra: None, tip_block_number: None, }; let balance = mercury_client.get_balance(payload).unwrap(); @@ -474,6 +482,7 @@ fn test_transfer_udt_to_provide_capacity_from_out_point_cheque_part_claim() { let payload = GetBalancePayload { item: JsonItem::Address(sender_address.to_string()), asset_infos: HashSet::new(), + extra: None, tip_block_number: None, }; let balance = mercury_client.get_balance(payload).unwrap(); @@ -542,6 +551,7 @@ fn test_transfer_udt_to_provide_capacity_from_cheque_address_part_claim() { let payload = GetBalancePayload { item: JsonItem::Address(receiver_address.to_string()), asset_infos: HashSet::new(), + extra: None, tip_block_number: None, }; let balance = mercury_client.get_balance(payload).unwrap(); @@ -554,6 +564,7 @@ fn test_transfer_udt_to_provide_capacity_from_cheque_address_part_claim() { let payload = GetBalancePayload { item: JsonItem::Address(sender_address.to_string()), asset_infos: HashSet::new(), + extra: None, tip_block_number: None, }; let balance = mercury_client.get_balance(payload).unwrap(); @@ -604,6 +615,7 @@ fn test_transfer_udt_from_provide_capacity_acp() { let payload = GetBalancePayload { item: JsonItem::Identity(hex::encode(to_identity.0)), asset_infos, + extra: None, tip_block_number: None, }; let to_balance = mercury_client.get_balance(payload).unwrap(); @@ -673,6 +685,7 @@ fn test_transfer_udt_to_provide_capacity_from_sender_has_cheque_part_withdraw() let payload = GetBalancePayload { item: JsonItem::Identity(hex::encode(udt_identity.0)), asset_infos: HashSet::new(), + extra: None, tip_block_number: None, }; let balance = mercury_client.get_balance(payload).unwrap(); diff --git a/integration/src/tests/get_balance.rs b/integration/src/tests/get_balance.rs index 6c5422634..990e9efcc 100644 --- a/integration/src/tests/get_balance.rs +++ b/integration/src/tests/get_balance.rs @@ -7,11 +7,16 @@ use crate::utils::address::{ generate_rand_secp_address_pk_pair, get_udt_hash_by_owner, new_identity_from_secp_address, }; use crate::utils::instruction::{ - fast_forward_epochs, issue_udt_1, issue_udt_with_cheque, prepare_secp_address_with_ckb_capacity, + fast_forward_epochs, issue_udt_1, issue_udt_with_cheque, + prepare_secp_address_with_ckb_capacity, send_transaction_to_ckb, }; use crate::utils::rpc_client::MercuryRpcClient; +use crate::utils::signer::sign_transaction; -use core_rpc_types::{AssetInfo, AssetType, GetBalancePayload, JsonItem}; +use core_rpc_types::{ + AssetInfo, AssetType, DaoClaimPayload, DaoDepositPayload, DaoWithdrawPayload, ExtraType, + GetBalancePayload, JsonItem, +}; use std::collections::HashSet; @@ -25,6 +30,7 @@ fn test_get_balance_of_genesis_built_in_address_1() { let payload = GetBalancePayload { item: JsonItem::Address(GENESIS_BUILT_IN_ADDRESS_1.to_string()), asset_infos, + extra: None, tip_block_number: None, }; let mercury_client = MercuryRpcClient::new(MERCURY_URI.to_string()); @@ -48,6 +54,7 @@ fn test_get_balance_of_udt_1_holder_address() { let payload = GetBalancePayload { item: JsonItem::Address(UDT_1_HOLDER_ACP_ADDRESS.get().unwrap().to_string()), asset_infos, + extra: None, tip_block_number: None, }; let mercury_client = MercuryRpcClient::new(MERCURY_URI.to_string()); @@ -93,6 +100,7 @@ fn test_get_balance_of_item_has_cheque() { let payload_receiver = GetBalancePayload { item: JsonItem::Identity(receiver_identity.encode()), asset_infos, + extra: None, tip_block_number: None, }; let receiver_balance = mercury_client @@ -108,6 +116,7 @@ fn test_get_balance_of_item_has_cheque() { let payload = GetBalancePayload { item: JsonItem::Identity(receiver_identity.encode()), asset_infos, + extra: None, tip_block_number: None, }; let to_balance = mercury_client.get_balance(payload).unwrap(); @@ -117,6 +126,7 @@ fn test_get_balance_of_item_has_cheque() { let payload = GetBalancePayload { item: JsonItem::Identity(receiver_identity.encode()), asset_infos: HashSet::new(), + extra: None, tip_block_number: None, }; let to_balance = mercury_client.get_balance(payload).unwrap(); @@ -127,6 +137,7 @@ fn test_get_balance_of_item_has_cheque() { let payload_sender = GetBalancePayload { item: JsonItem::Identity(sender_identity.encode()), asset_infos: HashSet::new(), + extra: None, tip_block_number: None, }; let sender_balance = mercury_client.get_balance(payload_sender.clone()).unwrap(); @@ -166,6 +177,7 @@ fn test_get_balance_of_item_has_cheque() { let payload_out_point = GetBalancePayload { item: JsonItem::OutPoint(out_point.to_owned()), asset_infos: HashSet::new(), + extra: None, tip_block_number: None, }; let balance = mercury_client.get_balance(payload_out_point).unwrap(); @@ -179,6 +191,7 @@ fn test_get_balance_of_item_has_cheque() { let payload_out_point = GetBalancePayload { item: JsonItem::Address(cheque_address.to_string()), asset_infos: HashSet::new(), + extra: None, tip_block_number: None, }; let balance = mercury_client.get_balance(payload_out_point).unwrap(); @@ -209,3 +222,98 @@ fn test_get_balance_of_item_has_cheque() { assert_eq!(receiver_balance.balances.len(), 1); assert_eq!(receiver_balance.balances[0].free, 100u128.into()); } + +inventory::submit!(IntegrationTest { + name: "test_dao_get_balance", + test_fn: test_dao_get_balance +}); +fn test_dao_get_balance() { + let (address, address_pk, _) = + prepare_secp_address_with_ckb_capacity(300_0000_0000).expect("prepare ckb"); + let pks = vec![address_pk]; + let mercury_client = MercuryRpcClient::new(MERCURY_URI.to_string()); + + // deposit + let payload = DaoDepositPayload { + from: vec![JsonItem::Address(address.to_string())], + to: None, + amount: 200_0000_0000.into(), + fee_rate: None, + }; + let tx = mercury_client + .build_dao_deposit_transaction(payload) + .unwrap(); + let tx = sign_transaction(tx, &pks).unwrap(); + let _tx_hash = send_transaction_to_ckb(tx).unwrap(); + + // get balance of dao + let mut asset_infos = HashSet::new(); + asset_infos.insert(AssetInfo::new_ckb()); + let balance_payload = GetBalancePayload { + item: JsonItem::Address(address.to_string()), + asset_infos, + extra: Some(ExtraType::Dao), + tip_block_number: None, + }; + let balance = mercury_client.get_balance(balance_payload.clone()).unwrap(); + assert_eq!(balance.balances.len(), 1); + assert_eq!(balance.balances[0].asset_info.asset_type, AssetType::CKB); + assert_eq!(balance.balances[0].occupied, 102_0000_0000u128.into()); + assert_eq!(balance.balances[0].free, 0u128.into()); + assert_eq!(balance.balances[0].frozen, 98_0000_0000u128.into()); + + // withdraw + let withdraw_payload = DaoWithdrawPayload { + from: vec![JsonItem::Address(address.to_string())], + fee_rate: None, + }; + let tx = mercury_client.build_dao_withdraw_transaction(withdraw_payload.clone()); + assert!(tx.is_err()); + + // claim + let claim_payload = DaoClaimPayload { + from: vec![JsonItem::Address(address.to_string())], + to: None, + fee_rate: None, + }; + let tx = mercury_client.build_dao_claim_transaction(claim_payload.clone()); + assert!(tx.is_err()); + + fast_forward_epochs(4).unwrap(); + + // withdraw + let tx = mercury_client + .build_dao_withdraw_transaction(withdraw_payload) + .unwrap(); + let tx = sign_transaction(tx, &pks).unwrap(); + let _tx_hash = send_transaction_to_ckb(tx).unwrap(); + + // get_balance + let balance = mercury_client.get_balance(balance_payload.clone()).unwrap(); + assert_eq!(balance.balances.len(), 1); + assert_eq!(balance.balances[0].asset_info.asset_type, AssetType::CKB); + assert_eq!(balance.balances[0].free, 0u128.into()); + assert_eq!(balance.balances[0].occupied, 102_0000_0000u128.into()); + assert!(balance.balances[0].frozen > 98_0000_0000u128.into()); + + fast_forward_epochs(176).unwrap(); + + // get_balance + let balance = mercury_client.get_balance(balance_payload.clone()).unwrap(); + assert_eq!(balance.balances.len(), 1); + assert_eq!(balance.balances[0].asset_info.asset_type, AssetType::CKB); + assert!(balance.balances[0].free > 200_0000_0000u128.into()); + assert_eq!(balance.balances[0].occupied, 0u128.into()); + assert_eq!(balance.balances[0].frozen, 0u128.into()); + + // claim + let tx = mercury_client + .build_dao_claim_transaction(claim_payload) + .unwrap(); + let tx = sign_transaction(tx, &pks).unwrap(); + let _tx_hash = send_transaction_to_ckb(tx).unwrap(); + + // get_balance + let balance = mercury_client.get_balance(balance_payload).unwrap(); + assert_eq!(balance.balances.len(), 0); +} diff --git a/protocol/Cargo.toml b/protocol/Cargo.toml index fdab32b1e..289885d9d 100644 --- a/protocol/Cargo.toml +++ b/protocol/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "protocol" -version = "0.4.3" +version = "0.4.4" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html