Skip to content

Commit 1982e9b

Browse files
authored
Merge branch 'feat/rs-platform-wallet-e2e-cases' into feat/rs-platform-wallet-e2e-cases-pa
2 parents 07a138a + d5fdc70 commit 1982e9b

187 files changed

Lines changed: 6133 additions & 14551 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Cargo.lock

Lines changed: 16 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,15 @@ members = [
4949
]
5050

5151
[workspace.dependencies]
52-
dashcore = { git = "https://github.com/dashpay/rust-dashcore", rev = "ea33cbc84179666c25515dfc817ce32210953037" }
53-
dash-network-seeds = { git = "https://github.com/dashpay/rust-dashcore", rev = "ea33cbc84179666c25515dfc817ce32210953037" }
54-
dash-spv = { git = "https://github.com/dashpay/rust-dashcore", rev = "ea33cbc84179666c25515dfc817ce32210953037" }
55-
dash-spv-ffi = { git = "https://github.com/dashpay/rust-dashcore", rev = "ea33cbc84179666c25515dfc817ce32210953037" }
56-
key-wallet = { git = "https://github.com/dashpay/rust-dashcore", rev = "ea33cbc84179666c25515dfc817ce32210953037" }
57-
key-wallet-ffi = { git = "https://github.com/dashpay/rust-dashcore", rev = "ea33cbc84179666c25515dfc817ce32210953037" }
58-
key-wallet-manager = { git = "https://github.com/dashpay/rust-dashcore", rev = "ea33cbc84179666c25515dfc817ce32210953037" }
59-
dashcore-rpc = { git = "https://github.com/dashpay/rust-dashcore", rev = "ea33cbc84179666c25515dfc817ce32210953037" }
52+
dashcore = { git = "https://github.com/dashpay/rust-dashcore", rev = "ca507a92967ab4ab60dd681de1f736f8cc1d129f" }
53+
dash-network-seeds = { git = "https://github.com/dashpay/rust-dashcore", rev = "ca507a92967ab4ab60dd681de1f736f8cc1d129f" }
54+
dash-spv = { git = "https://github.com/dashpay/rust-dashcore", rev = "ca507a92967ab4ab60dd681de1f736f8cc1d129f" }
55+
dash-spv-ffi = { git = "https://github.com/dashpay/rust-dashcore", rev = "ca507a92967ab4ab60dd681de1f736f8cc1d129f" }
56+
key-wallet = { git = "https://github.com/dashpay/rust-dashcore", rev = "ca507a92967ab4ab60dd681de1f736f8cc1d129f" }
57+
key-wallet-ffi = { git = "https://github.com/dashpay/rust-dashcore", rev = "ca507a92967ab4ab60dd681de1f736f8cc1d129f" }
58+
key-wallet-manager = { git = "https://github.com/dashpay/rust-dashcore", rev = "ca507a92967ab4ab60dd681de1f736f8cc1d129f" }
59+
dash-network = { git = "https://github.com/dashpay/rust-dashcore", rev = "ca507a92967ab4ab60dd681de1f736f8cc1d129f" }
60+
dashcore-rpc = { git = "https://github.com/dashpay/rust-dashcore", rev = "ca507a92967ab4ab60dd681de1f736f8cc1d129f" }
6061

6162
# Optimize heavy crypto crates even in dev/test builds so that
6263
# Halo 2 proof generation and verification run at near-release speed.

packages/rs-platform-wallet-ffi/Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ tokio = { version = "1", features = ["rt-multi-thread"] }
2727
# Core dependencies (for Network type)
2828
dashcore = { workspace = true }
2929
key-wallet = { workspace = true, features = ["bincode"] }
30+
dash-network = { workspace = true, features = ["ffi"] }
3031

3132
# Bincode used to serialize RootExtendedPubKey / ExtendedPubKey across
3233
# FFI for watch-only restore. Same version pinned elsewhere in workspace.
@@ -35,6 +36,11 @@ bincode = { version = "=2.0.1" }
3536
# Hex used for error diagnostics that include a wallet_id.
3637
hex = "0.4"
3738

39+
# anyhow surfaces from `KeyType::try_from` / `Purpose::try_from`
40+
# / `SecurityLevel::try_from` in dpp; we need the From impl in
41+
# `error.rs` so `unwrap_result_or_return!` can absorb it.
42+
anyhow = { version = "1.0.81" }
43+
3844
# Used by group-action queries to build the JSON response shape that
3945
# Swift decodes via Codable. See `tokens/group_queries.rs`.
4046
serde_json = "1.0"

packages/rs-platform-wallet-ffi/src/asset_lock/build.rs

Lines changed: 59 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
use crate::error::*;
44
use crate::handle::*;
55
use crate::runtime::runtime;
6+
use crate::{check_ptr, unwrap_option_or_return, unwrap_result_or_return};
67

78
/// Build an asset lock transaction.
89
///
@@ -21,54 +22,34 @@ pub unsafe extern "C" fn asset_lock_manager_build_transaction(
2122
out_tx_bytes: *mut *mut u8,
2223
out_tx_len: *mut usize,
2324
out_private_key: *mut [u8; 32],
24-
out_error: *mut PlatformWalletFFIError,
2525
) -> PlatformWalletFFIResult {
26-
if out_tx_bytes.is_null() || out_tx_len.is_null() || out_private_key.is_null() {
27-
return PlatformWalletFFIResult::ErrorNullPointer;
28-
}
26+
check_ptr!(out_tx_bytes);
27+
check_ptr!(out_tx_len);
28+
check_ptr!(out_private_key);
29+
30+
let option = parse_funding_type(funding_type);
31+
let funding = unwrap_option_or_return!(option);
32+
33+
let option = ASSET_LOCK_MANAGER_STORAGE.with_item(handle, |manager| {
34+
runtime().block_on(manager.build_asset_lock_transaction(
35+
amount_duffs,
36+
account_index,
37+
funding,
38+
identity_index,
39+
))
40+
});
41+
let result = unwrap_option_or_return!(option);
42+
let (tx, key) = unwrap_result_or_return!(result);
43+
44+
let serialized = dashcore::consensus::serialize(&tx);
45+
let len = serialized.len();
46+
let boxed = serialized.into_boxed_slice();
47+
48+
*out_tx_bytes = Box::into_raw(boxed) as *mut u8;
49+
*out_tx_len = len;
50+
*out_private_key = key.inner.secret_bytes();
2951

30-
let funding = match parse_funding_type(funding_type) {
31-
Some(f) => f,
32-
None => {
33-
if !out_error.is_null() {
34-
*out_error = PlatformWalletFFIError::new(
35-
PlatformWalletFFIResult::ErrorInvalidParameter,
36-
format!("Unknown funding type: {}", funding_type),
37-
);
38-
}
39-
return PlatformWalletFFIResult::ErrorInvalidParameter;
40-
}
41-
};
42-
43-
ASSET_LOCK_MANAGER_STORAGE
44-
.with_item(handle, |manager| {
45-
match runtime().block_on(manager.build_asset_lock_transaction(
46-
amount_duffs,
47-
account_index,
48-
funding,
49-
identity_index,
50-
)) {
51-
Ok((tx, key)) => {
52-
let serialized = dashcore::consensus::serialize(&tx);
53-
let len = serialized.len();
54-
let boxed = serialized.into_boxed_slice();
55-
*out_tx_bytes = Box::into_raw(boxed) as *mut u8;
56-
*out_tx_len = len;
57-
*out_private_key = key.inner.secret_bytes();
58-
PlatformWalletFFIResult::Success
59-
}
60-
Err(e) => {
61-
if !out_error.is_null() {
62-
*out_error = PlatformWalletFFIError::new(
63-
PlatformWalletFFIResult::ErrorWalletOperation,
64-
e.to_string(),
65-
);
66-
}
67-
PlatformWalletFFIResult::ErrorWalletOperation
68-
}
69-
}
70-
})
71-
.unwrap_or(PlatformWalletFFIResult::ErrorInvalidHandle)
52+
PlatformWalletFFIResult::ok()
7253
}
7354

7455
/// Build, broadcast, and wait for an asset lock proof.
@@ -91,74 +72,40 @@ pub unsafe extern "C" fn asset_lock_manager_create_funded_proof(
9172
out_proof_len: *mut usize,
9273
out_private_key: *mut [u8; 32],
9374
out_txid: *mut [u8; 32],
94-
out_error: *mut PlatformWalletFFIError,
9575
) -> PlatformWalletFFIResult {
96-
if out_proof_bytes.is_null()
97-
|| out_proof_len.is_null()
98-
|| out_private_key.is_null()
99-
|| out_txid.is_null()
100-
{
101-
return PlatformWalletFFIResult::ErrorNullPointer;
102-
}
76+
check_ptr!(out_proof_bytes);
77+
check_ptr!(out_proof_len);
78+
check_ptr!(out_private_key);
79+
check_ptr!(out_txid);
80+
81+
let funding = unwrap_option_or_return!(parse_funding_type(funding_type));
82+
83+
let option = ASSET_LOCK_MANAGER_STORAGE.with_item(handle, |manager| {
84+
runtime().block_on(manager.create_funded_asset_lock_proof(
85+
amount_duffs,
86+
account_index,
87+
funding,
88+
identity_index,
89+
))
90+
});
91+
let result = unwrap_option_or_return!(option);
92+
let (proof, key, out_point) = unwrap_result_or_return!(result);
93+
94+
let bytes = unwrap_result_or_return!(dpp::bincode::encode_to_vec(
95+
&proof,
96+
dpp::bincode::config::standard()
97+
));
98+
99+
let len = bytes.len();
100+
let boxed = bytes.into_boxed_slice();
101+
*out_proof_bytes = Box::into_raw(boxed) as *mut u8;
102+
*out_proof_len = len;
103+
*out_private_key = key.inner.secret_bytes();
104+
let mut txid_bytes = [0u8; 32];
105+
txid_bytes.copy_from_slice(&out_point.txid[..]);
106+
*out_txid = txid_bytes;
103107

104-
let funding = match parse_funding_type(funding_type) {
105-
Some(f) => f,
106-
None => {
107-
if !out_error.is_null() {
108-
*out_error = PlatformWalletFFIError::new(
109-
PlatformWalletFFIResult::ErrorInvalidParameter,
110-
format!("Unknown funding type: {}", funding_type),
111-
);
112-
}
113-
return PlatformWalletFFIResult::ErrorInvalidParameter;
114-
}
115-
};
116-
117-
ASSET_LOCK_MANAGER_STORAGE
118-
.with_item(handle, |manager| {
119-
match runtime().block_on(manager.create_funded_asset_lock_proof(
120-
amount_duffs,
121-
account_index,
122-
funding,
123-
identity_index,
124-
)) {
125-
Ok((proof, key, out_point)) => {
126-
// Serialize proof with bincode
127-
match dpp::bincode::encode_to_vec(&proof, dpp::bincode::config::standard()) {
128-
Ok(bytes) => {
129-
let len = bytes.len();
130-
let boxed = bytes.into_boxed_slice();
131-
*out_proof_bytes = Box::into_raw(boxed) as *mut u8;
132-
*out_proof_len = len;
133-
*out_private_key = key.inner.secret_bytes();
134-
let mut txid_bytes = [0u8; 32];
135-
txid_bytes.copy_from_slice(&out_point.txid[..]);
136-
*out_txid = txid_bytes;
137-
PlatformWalletFFIResult::Success
138-
}
139-
Err(e) => {
140-
if !out_error.is_null() {
141-
*out_error = PlatformWalletFFIError::new(
142-
PlatformWalletFFIResult::ErrorSerialization,
143-
format!("Failed to serialize proof: {}", e),
144-
);
145-
}
146-
PlatformWalletFFIResult::ErrorSerialization
147-
}
148-
}
149-
}
150-
Err(e) => {
151-
if !out_error.is_null() {
152-
*out_error = PlatformWalletFFIError::new(
153-
PlatformWalletFFIResult::ErrorWalletOperation,
154-
e.to_string(),
155-
);
156-
}
157-
PlatformWalletFFIResult::ErrorWalletOperation
158-
}
159-
}
160-
})
161-
.unwrap_or(PlatformWalletFFIResult::ErrorInvalidHandle)
108+
PlatformWalletFFIResult::ok()
162109
}
163110

164111
/// Free transaction bytes.

0 commit comments

Comments
 (0)