Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release v0.1.0 #2

Merged
merged 2 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ jobs:

- name: Install Capsule
env:
CAPSULE_VERSION: v0.10.1
CAPSULE_VERSION: v0.10.3
run: |
sudo curl -OL https://github.com/nervosnetwork/capsule/releases/download/${CAPSULE_VERSION}/capsule_${CAPSULE_VERSION}_x86_64-linux.tar.gz && sudo tar xf capsule_${CAPSULE_VERSION}_x86_64-linux.tar.gz && echo `pwd`/capsule_${CAPSULE_VERSION}_x86_64-linux >> $GITHUB_PATH

- name: Build contracts
run: make build-release
run: make build

- name: Test contracts
run: make test-release
run: make test
120 changes: 21 additions & 99 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion capsule.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version = "0.10.1"
version = "0.10.3"
deployment = "deployment.toml"

[[contracts]]
Expand Down
2 changes: 1 addition & 1 deletion contracts/dex-lock/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ version = "0.1.0"
edition = "2021"

[dependencies]
ckb-std = "0.15.0"
ckb-std = "0.14.0"
9 changes: 6 additions & 3 deletions contracts/dex-lock/src/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::{
};
use ckb_std::{
ckb_constants::Source,
ckb_types::prelude::Entity,
high_level::{load_cell_capacity, load_cell_lock},
};

Expand All @@ -19,11 +20,13 @@ pub fn main() -> Result<(), Error> {
// to the seller's lock script
let dex_index = position_dex_lock_in_inputs()?;
let output_lock = load_cell_lock(dex_index, Source::Output)?;
if args.owner_lock != output_lock {
if args.owner_lock.as_slice() != output_lock.as_slice() {
return Err(Error::DexOwnerLockNotMatch);
}
let output_capacity = load_cell_capacity(dex_index, Source::Output)?;
if args.total_value > output_capacity.into() {

let dex_input_capacity = load_cell_capacity(dex_index, Source::Input)? as u128;
let output_capacity = load_cell_capacity(dex_index, Source::Output)? as u128;
if (args.total_value + dex_input_capacity) > output_capacity {
return Err(Error::DexTotalValueNotMatch);
}

Expand Down
7 changes: 4 additions & 3 deletions contracts/dex-lock/src/helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ impl DexArgs {
}
let owner_size = u32::from_le_bytes(parse_array::<4>(&data[0..4])?) as usize;
let required_size = owner_size + 17;
if data.len() < (required_size + 17) {
if data.len() < required_size {
return Err(Error::LockArgsInvalid);
}

Expand Down Expand Up @@ -72,10 +72,11 @@ impl DexArgs {
pub fn position_dex_lock_in_inputs() -> Result<usize, Error> {
let current_lock = load_script()?;
QueryIter::new(load_cell_lock, Source::Input)
.position(|lock| lock == current_lock)
.position(|lock| lock.as_slice() == current_lock.as_slice())
.ok_or(Error::IndexOutOfBound)
}

pub fn inputs_contain_owner_cell(args: &DexArgs) -> bool {
QueryIter::new(load_cell_lock, Source::Input).any(|lock| lock == args.owner_lock)
QueryIter::new(load_cell_lock, Source::Input)
.any(|lock| lock.as_slice() == args.owner_lock.as_slice())
}
7 changes: 2 additions & 5 deletions tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ version = "0.1.0"
edition = "2021"

[dependencies]
ckb-testtool = "0.10.1"
rand_core = "0.6.3"
ckb-testtool = "0.10"
hex = "0.4"
blake2b-rs = "0.2"
rand = "0.8.5"
openssl = "0.10.38"
rand = "0.8.5"
Loading
Loading