Skip to content
This repository was archived by the owner on Apr 9, 2024. It is now read-only.

Commit 214f6fb

Browse files
committed
new utils_types mod.
1 parent f153288 commit 214f6fb

File tree

4 files changed

+149
-142
lines changed

4 files changed

+149
-142
lines changed

core/rpc/core/src/impl.rs

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ mod build_tx;
33
mod operation;
44
mod query;
55
pub(crate) mod utils;
6+
pub(crate) mod utils_types;
67

78
use core_ckb_client::CkbRpc;
89
use core_rpc_types::{

core/rpc/core/src/impl/build_tx.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::r#impl::{address_to_script, utils};
1+
use crate::r#impl::{address_to_script, utils, utils_types};
22
use crate::{error::CoreError, InnerResult, MercuryRpcImpl};
33

44
use common::hash::blake2b_256_to_160;
@@ -773,7 +773,7 @@ impl<C: CkbRpc> MercuryRpcImpl<C> {
773773
fixed_fee: u64,
774774
) -> InnerResult<(TransactionView, Vec<SignatureAction>, usize)> {
775775
// init transfer components: build the outputs
776-
let mut transfer_components = utils::TransferComponents::new();
776+
let mut transfer_components = utils_types::TransferComponents::new();
777777
for to in &payload.to.to_infos {
778778
let capacity = to
779779
.amount
@@ -954,7 +954,7 @@ impl<C: CkbRpc> MercuryRpcImpl<C> {
954954
fixed_fee: u64,
955955
) -> InnerResult<(TransactionView, Vec<SignatureAction>, usize)> {
956956
// init transfer components: build acp inputs and outputs
957-
let mut transfer_components = utils::TransferComponents::new();
957+
let mut transfer_components = utils_types::TransferComponents::new();
958958
for to in &payload.to.to_infos {
959959
let item = Item::Identity(utils::address_to_identity(&to.address)?);
960960

@@ -1186,7 +1186,7 @@ impl<C: CkbRpc> MercuryRpcImpl<C> {
11861186
fixed_fee: u64,
11871187
) -> InnerResult<(TransactionView, Vec<SignatureAction>, usize)> {
11881188
// init transfer components: build acp inputs and outputs
1189-
let mut transfer_components = utils::TransferComponents::new();
1189+
let mut transfer_components = utils_types::TransferComponents::new();
11901190
for to in &payload.to.to_infos {
11911191
let receiver_address =
11921192
Address::from_str(&to.address).map_err(CoreError::InvalidRpcParams)?;
@@ -1480,7 +1480,7 @@ impl<C: CkbRpc> MercuryRpcImpl<C> {
14801480
fixed_fee: u64,
14811481
) -> InnerResult<(TransactionView, Vec<SignatureAction>, usize)> {
14821482
// init transfer components: build acp inputs and outputs
1483-
let mut transfer_components = utils::TransferComponents::new();
1483+
let mut transfer_components = utils_types::TransferComponents::new();
14841484
for to in &payload.to.to_infos {
14851485
let item = Item::Identity(utils::address_to_identity(&to.address)?);
14861486

@@ -1783,7 +1783,7 @@ impl<C: CkbRpc> MercuryRpcImpl<C> {
17831783
ctx: Context,
17841784
payload: TransferPayload,
17851785
fee: u64,
1786-
mut transfer_components: utils::TransferComponents,
1786+
mut transfer_components: utils_types::TransferComponents,
17871787
) -> InnerResult<(TransactionView, Vec<SignatureAction>, usize)> {
17881788
// balance capacity
17891789
let mut from_items = vec![];

core/rpc/core/src/impl/utils.rs

+1-136
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::r#impl::address_to_script;
1+
use crate::r#impl::{address_to_script, utils_types::*};
22
use crate::{error::CoreError, InnerResult, MercuryRpcImpl};
33

44
use common::hash::blake2b_160;
@@ -2979,138 +2979,3 @@ pub(crate) fn dedup_json_items(items: Vec<JsonItem>) -> Vec<JsonItem> {
29792979
items.dedup();
29802980
items
29812981
}
2982-
2983-
#[allow(clippy::upper_case_acronyms)]
2984-
pub enum AssetScriptType {
2985-
Secp256k1,
2986-
ACP,
2987-
ChequeSender(String),
2988-
ChequeReceiver(String),
2989-
Dao(Item),
2990-
}
2991-
2992-
#[derive(Debug, Default)]
2993-
pub struct TransferComponents {
2994-
pub inputs: Vec<DetailedCell>,
2995-
pub outputs: Vec<packed::CellOutput>,
2996-
pub outputs_data: Vec<packed::Bytes>,
2997-
pub header_deps: Vec<packed::Byte32>,
2998-
pub script_deps: HashSet<String>,
2999-
pub signature_actions: HashMap<String, SignatureAction>,
3000-
pub type_witness_args: HashMap<usize, (packed::BytesOpt, packed::BytesOpt)>,
3001-
pub fee_change_cell_index: Option<usize>,
3002-
pub dao_reward_capacity: u64,
3003-
pub dao_since_map: HashMap<usize, u64>,
3004-
pub header_dep_map: HashMap<packed::Byte32, usize>,
3005-
}
3006-
3007-
impl TransferComponents {
3008-
pub fn new() -> Self {
3009-
TransferComponents::default()
3010-
}
3011-
}
3012-
3013-
#[derive(Debug, Copy, Clone)]
3014-
pub enum PoolCkbCategory {
3015-
DaoClaim,
3016-
CellBase,
3017-
Acp,
3018-
NormalSecp,
3019-
}
3020-
3021-
#[derive(Debug, Copy, Clone)]
3022-
pub enum PoolUdtCategory {
3023-
ChequeInTime,
3024-
ChequeOutTime,
3025-
SecpUdt,
3026-
Acp,
3027-
}
3028-
3029-
pub struct CkbCellsCache {
3030-
pub items: Vec<Item>,
3031-
pub item_category_array: Vec<(usize, PoolCkbCategory)>,
3032-
pub array_index: usize,
3033-
pub cell_deque: VecDeque<(DetailedCell, AssetScriptType)>,
3034-
}
3035-
3036-
impl CkbCellsCache {
3037-
pub fn new(items: Vec<Item>) -> Self {
3038-
let mut item_category_array = vec![];
3039-
for (item_index, _) in items.iter().enumerate() {
3040-
for category_index in &[
3041-
PoolCkbCategory::DaoClaim,
3042-
PoolCkbCategory::CellBase,
3043-
PoolCkbCategory::Acp,
3044-
PoolCkbCategory::NormalSecp,
3045-
] {
3046-
item_category_array.push((item_index, category_index.to_owned()))
3047-
}
3048-
}
3049-
CkbCellsCache {
3050-
items,
3051-
item_category_array,
3052-
array_index: 0,
3053-
cell_deque: VecDeque::new(),
3054-
}
3055-
}
3056-
}
3057-
3058-
pub struct UdtCellsCache {
3059-
pub items: Vec<Item>,
3060-
pub asset_info: AssetInfo,
3061-
pub item_category_array: Vec<(usize, PoolUdtCategory)>,
3062-
pub array_index: usize,
3063-
pub cell_deque: VecDeque<(DetailedCell, AssetScriptType)>,
3064-
}
3065-
3066-
impl UdtCellsCache {
3067-
pub fn new(items: Vec<Item>, asset_info: AssetInfo, source: Source) -> Self {
3068-
let mut item_category_array = vec![];
3069-
match source {
3070-
Source::Claimable => {
3071-
for (item_index, _) in items.iter().enumerate() {
3072-
for category_index in &[PoolUdtCategory::ChequeInTime] {
3073-
item_category_array.push((item_index, category_index.to_owned()))
3074-
}
3075-
}
3076-
}
3077-
Source::Free => {
3078-
for (item_index, _) in items.iter().enumerate() {
3079-
for category_index in &[
3080-
PoolUdtCategory::ChequeOutTime,
3081-
PoolUdtCategory::SecpUdt,
3082-
PoolUdtCategory::Acp,
3083-
] {
3084-
item_category_array.push((item_index, category_index.to_owned()))
3085-
}
3086-
}
3087-
}
3088-
}
3089-
3090-
UdtCellsCache {
3091-
items,
3092-
asset_info,
3093-
item_category_array,
3094-
array_index: 0,
3095-
cell_deque: VecDeque::new(),
3096-
}
3097-
}
3098-
}
3099-
3100-
pub struct AcpCellsCache {
3101-
pub items: Vec<Item>,
3102-
pub asset_info: Option<AssetInfo>,
3103-
pub current_index: usize,
3104-
pub cell_deque: VecDeque<DetailedCell>,
3105-
}
3106-
3107-
impl AcpCellsCache {
3108-
pub fn new(items: Vec<Item>, asset_info: Option<AssetInfo>) -> Self {
3109-
AcpCellsCache {
3110-
items,
3111-
asset_info,
3112-
current_index: 0,
3113-
cell_deque: VecDeque::new(),
3114-
}
3115-
}
3116-
}

core/rpc/core/src/impl/utils_types.rs

+141
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
use common::DetailedCell;
2+
use core_rpc_types::{AssetInfo, Item, SignatureAction, Source};
3+
4+
use ckb_types::packed;
5+
6+
use std::collections::{HashMap, HashSet, VecDeque};
7+
8+
#[allow(clippy::upper_case_acronyms)]
9+
pub enum AssetScriptType {
10+
Secp256k1,
11+
ACP,
12+
ChequeSender(String),
13+
ChequeReceiver(String),
14+
Dao(Item),
15+
}
16+
17+
#[derive(Debug, Default)]
18+
pub struct TransferComponents {
19+
pub inputs: Vec<DetailedCell>,
20+
pub outputs: Vec<packed::CellOutput>,
21+
pub outputs_data: Vec<packed::Bytes>,
22+
pub header_deps: Vec<packed::Byte32>,
23+
pub script_deps: HashSet<String>,
24+
pub signature_actions: HashMap<String, SignatureAction>,
25+
pub type_witness_args: HashMap<usize, (packed::BytesOpt, packed::BytesOpt)>,
26+
pub fee_change_cell_index: Option<usize>,
27+
pub dao_reward_capacity: u64,
28+
pub dao_since_map: HashMap<usize, u64>,
29+
pub header_dep_map: HashMap<packed::Byte32, usize>,
30+
}
31+
32+
impl TransferComponents {
33+
pub fn new() -> Self {
34+
TransferComponents::default()
35+
}
36+
}
37+
38+
#[derive(Debug, Copy, Clone)]
39+
pub enum PoolCkbCategory {
40+
DaoClaim,
41+
CellBase,
42+
Acp,
43+
NormalSecp,
44+
}
45+
46+
#[derive(Debug, Copy, Clone)]
47+
pub enum PoolUdtCategory {
48+
ChequeInTime,
49+
ChequeOutTime,
50+
SecpUdt,
51+
Acp,
52+
}
53+
54+
pub struct CkbCellsCache {
55+
pub items: Vec<Item>,
56+
pub item_category_array: Vec<(usize, PoolCkbCategory)>,
57+
pub array_index: usize,
58+
pub cell_deque: VecDeque<(DetailedCell, AssetScriptType)>,
59+
}
60+
61+
impl CkbCellsCache {
62+
pub fn new(items: Vec<Item>) -> Self {
63+
let mut item_category_array = vec![];
64+
for (item_index, _) in items.iter().enumerate() {
65+
for category_index in &[
66+
PoolCkbCategory::DaoClaim,
67+
PoolCkbCategory::CellBase,
68+
PoolCkbCategory::Acp,
69+
PoolCkbCategory::NormalSecp,
70+
] {
71+
item_category_array.push((item_index, category_index.to_owned()))
72+
}
73+
}
74+
CkbCellsCache {
75+
items,
76+
item_category_array,
77+
array_index: 0,
78+
cell_deque: VecDeque::new(),
79+
}
80+
}
81+
}
82+
83+
pub struct UdtCellsCache {
84+
pub items: Vec<Item>,
85+
pub asset_info: AssetInfo,
86+
pub item_category_array: Vec<(usize, PoolUdtCategory)>,
87+
pub array_index: usize,
88+
pub cell_deque: VecDeque<(DetailedCell, AssetScriptType)>,
89+
}
90+
91+
impl UdtCellsCache {
92+
pub fn new(items: Vec<Item>, asset_info: AssetInfo, source: Source) -> Self {
93+
let mut item_category_array = vec![];
94+
match source {
95+
Source::Claimable => {
96+
for (item_index, _) in items.iter().enumerate() {
97+
for category_index in &[PoolUdtCategory::ChequeInTime] {
98+
item_category_array.push((item_index, category_index.to_owned()))
99+
}
100+
}
101+
}
102+
Source::Free => {
103+
for (item_index, _) in items.iter().enumerate() {
104+
for category_index in &[
105+
PoolUdtCategory::ChequeOutTime,
106+
PoolUdtCategory::SecpUdt,
107+
PoolUdtCategory::Acp,
108+
] {
109+
item_category_array.push((item_index, category_index.to_owned()))
110+
}
111+
}
112+
}
113+
}
114+
115+
UdtCellsCache {
116+
items,
117+
asset_info,
118+
item_category_array,
119+
array_index: 0,
120+
cell_deque: VecDeque::new(),
121+
}
122+
}
123+
}
124+
125+
pub struct AcpCellsCache {
126+
pub items: Vec<Item>,
127+
pub asset_info: Option<AssetInfo>,
128+
pub current_index: usize,
129+
pub cell_deque: VecDeque<DetailedCell>,
130+
}
131+
132+
impl AcpCellsCache {
133+
pub fn new(items: Vec<Item>, asset_info: Option<AssetInfo>) -> Self {
134+
AcpCellsCache {
135+
items,
136+
asset_info,
137+
current_index: 0,
138+
cell_deque: VecDeque::new(),
139+
}
140+
}
141+
}

0 commit comments

Comments
 (0)