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

Commit cd9bd89

Browse files
committed
add types for building transfer tx.
1 parent cf803e4 commit cd9bd89

File tree

1 file changed

+151
-23
lines changed

1 file changed

+151
-23
lines changed

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

+151-23
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use ckb_types::{bytes::Bytes, packed, prelude::*, H160, H256};
2828
use num_bigint::{BigInt, BigUint};
2929
use num_traits::Zero;
3030

31-
use std::collections::{HashMap, HashSet};
31+
use std::collections::{HashMap, HashSet, VecDeque};
3232
use std::convert::TryInto;
3333
use std::str::FromStr;
3434

@@ -656,19 +656,21 @@ impl<C: CkbRpc> MercuryRpcImpl<C> {
656656
AssetScriptType::ChequeSender(ref s) => {
657657
script_set.insert(CHEQUE.to_string());
658658
s.clone()
659-
} // AssetScriptType::Dao => {
660-
// script_set.insert(DAO.to_string());
661-
// script_set.insert(SECP256K1.to_string());
662-
// Address::new(
663-
// self.network_type,
664-
// AddressPayload::from_pubkey_hash(
665-
// self.network_type,
666-
// H160::from_slice(&cell.cell_output.lock().args().raw_data()[0..20])
667-
// .unwrap(),
668-
// ),
669-
// )
670-
// .to_string()
671-
// }
659+
}
660+
AssetScriptType::Dao(_) => {
661+
// script_set.insert(DAO.to_string());
662+
// script_set.insert(SECP256K1.to_string());
663+
// Address::new(
664+
// self.network_type,
665+
// AddressPayload::from_pubkey_hash(
666+
// self.network_type,
667+
// H160::from_slice(&cell.cell_output.lock().args().raw_data()[0..20])
668+
// .unwrap(),
669+
// ),
670+
// )
671+
// .to_string()
672+
unreachable!()
673+
}
672674
};
673675

674676
pool_cells.push(cell.clone());
@@ -1767,15 +1769,6 @@ pub fn build_cheque_args(receiver_address: Address, sender_address: Address) ->
17671769
ret.pack()
17681770
}
17691771

1770-
#[allow(clippy::upper_case_acronyms)]
1771-
pub enum AssetScriptType {
1772-
Secp256k1,
1773-
ACP,
1774-
ChequeSender(String),
1775-
ChequeReceiver(String),
1776-
// Dao,
1777-
}
1778-
17791772
pub fn address_to_identity(address: &str) -> InnerResult<Identity> {
17801773
let address = Address::from_str(address).map_err(CoreError::CommonError)?;
17811774
let script = address_to_script(address.payload());
@@ -1817,3 +1810,138 @@ pub(crate) fn dedup_json_items(items: Vec<JsonItem>) -> Vec<JsonItem> {
18171810
items.dedup();
18181811
items
18191812
}
1813+
1814+
#[allow(clippy::upper_case_acronyms)]
1815+
pub enum AssetScriptType {
1816+
Secp256k1,
1817+
ACP,
1818+
ChequeSender(String),
1819+
ChequeReceiver(String),
1820+
Dao(Item),
1821+
}
1822+
1823+
#[derive(Debug, Default)]
1824+
pub struct TransferComponents {
1825+
pub inputs: Vec<DetailedCell>,
1826+
pub outputs: Vec<packed::CellOutput>,
1827+
pub outputs_data: Vec<packed::Bytes>,
1828+
pub header_deps: Vec<packed::Byte32>,
1829+
pub script_deps: HashSet<String>,
1830+
pub signature_actions: HashMap<String, SignatureAction>,
1831+
pub type_witness_args: HashMap<usize, (packed::BytesOpt, packed::BytesOpt)>,
1832+
pub fee_change_cell_index: Option<usize>,
1833+
pub dao_reward_capacity: u64,
1834+
pub dao_since_map: HashMap<usize, u64>,
1835+
pub header_dep_map: HashMap<packed::Byte32, usize>,
1836+
}
1837+
1838+
impl TransferComponents {
1839+
pub fn new() -> Self {
1840+
TransferComponents::default()
1841+
}
1842+
}
1843+
1844+
#[derive(Debug, Copy, Clone)]
1845+
pub enum PoolCkbCategory {
1846+
DaoClaim,
1847+
CellBase,
1848+
Acp,
1849+
NormalSecp,
1850+
}
1851+
1852+
#[derive(Debug, Copy, Clone)]
1853+
pub enum PoolUdtCategory {
1854+
ChequeInTime,
1855+
ChequeOutTime,
1856+
SecpUdt,
1857+
Acp,
1858+
}
1859+
1860+
pub struct CkbCellsCache {
1861+
pub items: Vec<Item>,
1862+
pub item_category_array: Vec<(usize, PoolCkbCategory)>,
1863+
pub array_index: usize,
1864+
pub cell_deque: VecDeque<(DetailedCell, AssetScriptType)>,
1865+
}
1866+
1867+
impl CkbCellsCache {
1868+
pub fn new(items: Vec<Item>) -> Self {
1869+
let mut item_category_array = vec![];
1870+
for (item_index, _) in items.iter().enumerate() {
1871+
for category_index in &[
1872+
PoolCkbCategory::DaoClaim,
1873+
PoolCkbCategory::CellBase,
1874+
PoolCkbCategory::Acp,
1875+
PoolCkbCategory::NormalSecp,
1876+
] {
1877+
item_category_array.push((item_index, category_index.to_owned()))
1878+
}
1879+
}
1880+
CkbCellsCache {
1881+
items,
1882+
item_category_array,
1883+
array_index: 0,
1884+
cell_deque: VecDeque::new(),
1885+
}
1886+
}
1887+
}
1888+
1889+
pub struct UdtCellsCache {
1890+
pub items: Vec<Item>,
1891+
pub asset_info: AssetInfo,
1892+
pub item_category_array: Vec<(usize, PoolUdtCategory)>,
1893+
pub array_index: usize,
1894+
pub cell_deque: VecDeque<(DetailedCell, AssetScriptType)>,
1895+
}
1896+
1897+
impl UdtCellsCache {
1898+
pub fn new(items: Vec<Item>, asset_info: AssetInfo, source: Source) -> Self {
1899+
let mut item_category_array = vec![];
1900+
match source {
1901+
Source::Claimable => {
1902+
for (item_index, _) in items.iter().enumerate() {
1903+
for category_index in &[PoolUdtCategory::ChequeInTime] {
1904+
item_category_array.push((item_index, category_index.to_owned()))
1905+
}
1906+
}
1907+
}
1908+
Source::Free => {
1909+
for (item_index, _) in items.iter().enumerate() {
1910+
for category_index in &[
1911+
PoolUdtCategory::ChequeOutTime,
1912+
PoolUdtCategory::SecpUdt,
1913+
PoolUdtCategory::Acp,
1914+
] {
1915+
item_category_array.push((item_index, category_index.to_owned()))
1916+
}
1917+
}
1918+
}
1919+
}
1920+
1921+
UdtCellsCache {
1922+
items,
1923+
asset_info,
1924+
item_category_array,
1925+
array_index: 0,
1926+
cell_deque: VecDeque::new(),
1927+
}
1928+
}
1929+
}
1930+
1931+
pub struct AcpCellsCache {
1932+
pub items: Vec<Item>,
1933+
pub asset_info: Option<AssetInfo>,
1934+
pub current_index: usize,
1935+
pub cell_deque: VecDeque<DetailedCell>,
1936+
}
1937+
1938+
impl AcpCellsCache {
1939+
pub fn new(items: Vec<Item>, asset_info: Option<AssetInfo>) -> Self {
1940+
AcpCellsCache {
1941+
items,
1942+
asset_info,
1943+
current_index: 0,
1944+
cell_deque: VecDeque::new(),
1945+
}
1946+
}
1947+
}

0 commit comments

Comments
 (0)