Skip to content

Commit 8adc810

Browse files
authored
Merge pull request #132 from driftluo/support-async-client
feat: add new macro to support async client
2 parents b2aafcc + ba035e3 commit 8adc810

28 files changed

+1138
-324
lines changed

Cargo.toml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
[package]
22
name = "ckb-sdk"
33
version = "3.5.0"
4-
authors = [ "Linfeng Qian <thewawar@gmail.com>", "Nervos Core Dev <dev@nervos.org>" ]
4+
authors = [
5+
"Linfeng Qian <thewawar@gmail.com>",
6+
"Nervos Core Dev <dev@nervos.org>",
7+
]
58
edition = "2018"
69
license = "MIT"
710
description = "Rust SDK for CKB"
@@ -17,7 +20,7 @@ anyhow = "1.0.63"
1720
bech32 = "0.8.1"
1821
derive-getters = "0.2.1"
1922
log = "0.4.6"
20-
reqwest = { version = "0.11", default-features = false, features = [ "json", "blocking" ] }
23+
reqwest = { version = "0.12", default-features = false, features = ["json"] }
2124
secp256k1 = { version = "0.29.0", features = ["recovery"] }
2225
tokio-util = { version = "0.7.7", features = ["codec"] }
2326
tokio = { version = "1" }
@@ -28,6 +31,7 @@ parking_lot = "0.12"
2831
lru = "0.7.1"
2932
dashmap = "5.4"
3033
dyn-clone = "1.0"
34+
async-trait = "0.1"
3135

3236
ckb-types = "0.119.0"
3337
ckb-dao-utils = "0.119.0"
@@ -47,7 +51,6 @@ ckb-mock-tx-types = { version = "0.119.0" }
4751
ckb-chain-spec = "0.119.0"
4852

4953
sparse-merkle-tree = "0.6.1"
50-
lazy_static = "1.3.0"
5154

5255
[features]
5356
default = ["default-tls"]
@@ -57,7 +60,7 @@ rustls-tls = ["reqwest/rustls-tls"]
5760
test = []
5861

5962
[dev-dependencies]
60-
clap = { version = "=4.4.18", features = [ "derive" ] } # TODO clap v4.5 requires rustc v1.74.0+
63+
clap = { version = "4.4.18", features = ["derive"] }
6164
httpmock = "0.6"
6265
async-global-executor = "2.3.1"
6366
hex = "0.4"

deny.toml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ ignore = [
7474
#{ id = "RUSTSEC-0000-0000", reason = "you can specify a reason the advisory is ignored" },
7575
#"a-crate-that-is-yanked@0.1.1", # you can also ignore yanked crate versions if you wish
7676
#{ crate = "a-crate-that-is-yanked@0.1.1", reason = "you can specify why you are ignoring the yanked crate"
77-
"RUSTSEC-2024-0370" # proc-macro-error's maintainer seems to be unreachable, ignore this
77+
"RUSTSEC-2024-0370", # proc-macro-error's maintainer seems to be unreachable, ignore this
78+
"RUSTSEC-2024-0384", # instant is no longer maintained, ignore this
7879
]
7980
# If this is true, then cargo deny will use the git executable to fetch advisory database.
8081
# If this is false, then it uses a built-in git library.
@@ -97,8 +98,8 @@ allow = [
9798
"ISC",
9899
"MIT",
99100
"Unicode-DFS-2016",
100-
"BSL-1.0", # xxhash-rust 0.8.10
101-
101+
"BSL-1.0", # xxhash-rust 0.8.10
102+
"Unicode-3.0",
102103
#"MIT",
103104
#"Apache-2.0",
104105
#"Apache-2.0 WITH LLVM-exception",

examples/script_unlocker_example.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,14 @@ use std::collections::HashMap;
1717
/// [CapacityDiff]: https://github.com/doitian/ckb-sdk-examples-capacity-diff
1818
struct CapacityDiffUnlocker {}
1919

20+
#[async_trait::async_trait]
2021
impl ScriptUnlocker for CapacityDiffUnlocker {
2122
// This works for any args
2223
fn match_args(&self, _args: &[u8]) -> bool {
2324
true
2425
}
2526

26-
fn unlock(
27+
async fn unlock_async(
2728
&self,
2829
tx: &TransactionView,
2930
script_group: &ScriptGroup,
@@ -45,12 +46,14 @@ impl ScriptUnlocker for CapacityDiffUnlocker {
4546

4647
let mut total = 0i64;
4748
for i in &script_group.input_indices {
48-
let cell = tx_dep_provider.get_cell(
49-
&tx.inputs()
50-
.get(*i)
51-
.ok_or_else(|| other_unlock_error("input index out of bound"))?
52-
.previous_output(),
53-
)?;
49+
let cell = tx_dep_provider
50+
.get_cell_async(
51+
&tx.inputs()
52+
.get(*i)
53+
.ok_or_else(|| other_unlock_error("input index out of bound"))?
54+
.previous_output(),
55+
)
56+
.await?;
5457
let capacity: u64 = cell.capacity().unpack();
5558
total -= capacity as i64;
5659
}
@@ -71,7 +74,7 @@ impl ScriptUnlocker for CapacityDiffUnlocker {
7174

7275
// This is called before balancer. It's responsible to fill witness for inputs added manually
7376
// by users.
74-
fn fill_placeholder_witness(
77+
async fn fill_placeholder_witness_async(
7578
&self,
7679
tx: &TransactionView,
7780
script_group: &ScriptGroup,

rust-toolchain

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.75.0
1+
1.81.0

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pub mod test_util;
1616
#[cfg(test)]
1717
mod tests;
1818

19-
pub use rpc::{CkbRpcClient, IndexerRpcClient, RpcError};
19+
pub use rpc::{CkbRpcAsyncClient, CkbRpcClient, IndexerRpcAsyncClient, IndexerRpcClient, RpcError};
2020
pub use types::{
2121
Address, AddressPayload, AddressType, CodeHashIndex, HumanCapacity, NetworkInfo, NetworkType,
2222
OldAddress, OldAddressFormat, ScriptGroup, ScriptGroupType, ScriptId, Since, SinceType,

0 commit comments

Comments
 (0)