Skip to content

Commit

Permalink
Merge pull request #73 from wenyuanhust/main
Browse files Browse the repository at this point in the history
refactor: change AT cell lock script from OmniLock to Secp256k1
  • Loading branch information
wenyuanhust committed Sep 18, 2023
2 parents f848355 + 6dbc308 commit 0b8622b
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 7 deletions.
24 changes: 18 additions & 6 deletions storage/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ static ROCKSDB_PATH: &str = "./free-space/smt";
async fn test_stake_functions() {
let mut path = PathBuf::from(ROCKSDB_PATH);
path.push("stake");
fs::remove_dir_all(path.clone()).unwrap();
if path.exists() {
fs::remove_dir_all(path.clone()).unwrap();
}

let smt_manager = SmtManager::new(path);
let staker = [5u8; 20].into();
Expand Down Expand Up @@ -74,7 +76,9 @@ async fn test_stake_functions() {
async fn test_delegate_smt() {
let mut path = PathBuf::from(ROCKSDB_PATH);
path.push("delegate1");
fs::remove_dir_all(path.clone()).unwrap();
if path.exists() {
fs::remove_dir_all(path.clone()).unwrap();
}

let smt_manager = SmtManager::new(path);
let stakers: Vec<Staker> = vec![
Expand Down Expand Up @@ -116,7 +120,9 @@ async fn test_delegate_smt() {
async fn test_delegate_smt_no_extra_data() {
let mut path = PathBuf::from(ROCKSDB_PATH);
path.push("delegate2");
fs::remove_dir_all(path.clone()).unwrap();
if path.exists() {
fs::remove_dir_all(path.clone()).unwrap();
}

let smt_manager = SmtManager::new(path);
let stakers: Vec<Staker> = vec![
Expand Down Expand Up @@ -163,7 +169,9 @@ async fn test_delegate_smt_no_extra_data() {
async fn test_delegate_functions() {
let mut path = PathBuf::from(ROCKSDB_PATH);
path.push("delegate");
fs::remove_dir_all(path.clone()).unwrap();
if path.exists() {
fs::remove_dir_all(path.clone()).unwrap();
}

let smt_manager = SmtManager::new(path);
let staker = [5u8; 20].into();
Expand Down Expand Up @@ -223,7 +231,9 @@ async fn test_delegate_functions() {
async fn test_reward_functions() {
let mut path = PathBuf::from(ROCKSDB_PATH);
path.push("reward");
fs::remove_dir_all(path.clone()).unwrap();
if path.exists() {
fs::remove_dir_all(path.clone()).unwrap();
}

let smt_manager = SmtManager::new(path);
let address = [5u8; 20].into();
Expand All @@ -244,7 +254,9 @@ async fn test_reward_functions() {
async fn test_proposal_functions() {
let mut path = PathBuf::from(ROCKSDB_PATH);
path.push("proposal");
fs::remove_dir_all(path.clone()).unwrap();
if path.exists() {
fs::remove_dir_all(path.clone()).unwrap();
}

let smt_manager = SmtManager::new(path);
let validator = [5u8; 20].into();
Expand Down
20 changes: 20 additions & 0 deletions tx-builder/src/ckb/helper/ckb/basic_scripts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,26 @@ impl Secp256k1 {
),
}
}

pub fn lock(args: Bytes) -> Script {
match **NETWORK_TYPE.load() {
NetworkType::Mainnet => script!(
&SECP2561_BLAKE160_MAINNET.code_hash,
SECP2561_BLAKE160_MAINNET.hash_type,
args
),
NetworkType::Testnet => script!(
&SECP2561_BLAKE160_TESTNET.code_hash,
SECP2561_BLAKE160_TESTNET.hash_type,
args
),
NetworkType::Devnet => script!(
&SECP2561_BLAKE160_DEVNET.code_hash,
SECP2561_BLAKE160_DEVNET.hash_type,
args
),
}
}
}

impl TypeId {
Expand Down
2 changes: 1 addition & 1 deletion tx-builder/src/ckb/reward.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ where
.build_exact_capacity(Capacity::bytes(outputs_data[1].len())?)?,
// AT cell
CellOutput::new_builder()
.lock(OmniEth::lock(&self.user))
.lock(Secp256k1::lock(Bytes::from(self.user.0.to_vec())))
.type_(Some(Xudt::type_(&self.type_ids.xudt_owner.pack())).pack())
.build_exact_capacity(Capacity::bytes(outputs_data[2].len())?)?,
];
Expand Down

0 comments on commit 0b8622b

Please sign in to comment.