Skip to content
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
440 changes: 157 additions & 283 deletions Cargo.lock

Large diffs are not rendered by default.

23 changes: 9 additions & 14 deletions dash-spv-apple-bindings/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ build = "build.rs"
publish = true

[dependencies]
anyhow = { version = "1.0.75" }
bincode_derive = "=2.0.0-rc.3"

anyhow = { version = "1.0" }
byte = "0.2"
dash-spv-coinjoin = { workspace = true, features = [] }
dash-spv-keychain = { workspace = true }
Expand All @@ -26,13 +24,13 @@ drive = { git = "https://github.com/dashpay/platform", branch = "test/ferment",
drive-proof-verifier = { git = "https://github.com/dashpay/platform", branch = "test/ferment", package = "drive-proof-verifier", default-features = false, features = ["apple"] }
platform-value = { git = "https://github.com/dashpay/platform", branch = "test/ferment", package = "platform-value", features = ["apple"] }
platform-version = { git = "https://github.com/dashpay/platform", branch = "test/ferment", package = "platform-version", features = ["apple"] }
grovedb-version = "2.2.1"
grovedb-version = { git = "https://github.com/dashpay/grovedb", rev = "f89e03e4e0ac12aa2feea5c94b38c09f4909facc" }
versioned-feature-core = "1.0.0"

ferment = { git = "https://github.com/dashpay/ferment", package = "ferment" }
ferment-macro = { git = "https://github.com/dashpay/ferment", package = "ferment-macro" }
ferment = { version = "0.2", package = "ferment" }
ferment-macro = { version = "0.2", package = "ferment-macro" }

indexmap = { version = "2.0.2", features = ["serde"] }
indexmap = { version = "2.9.0", features = ["serde"] }
jsonschema = "0.29.0"
logging = { path = "../logging" }
tracing = "0.1.40"
Expand All @@ -42,20 +40,17 @@ serde_json = { version = "1.0", features = ["preserve_order"] }
tokio = { version = "1.36.0", features = ["macros", "rt-multi-thread"] }

[dev-dependencies]
libc = "0.2.146"
reqwest = { version = "0.12.5", features = ["blocking", "json"] }
dash-spv-masternode-processor = { workspace = true, features = ["default", "test-helpers"] }
serde = { version = "1.0.209", features = ["derive"] }

[build-dependencies]
cbindgen = "0.28.0"
#ferment-sys = { git = "https://github.com/dashpay/ferment", package = "ferment-sys", features = ["cbindgen_only"] }
ferment-sys = { git = "https://github.com/dashpay/ferment", package = "ferment-sys" }
ferment-sys = { version = "0.2", package = "ferment-sys" }
#ferment-sys = { git = "https://github.com/dashpay/ferment", branch = "feat/reorg", package = "ferment-sys", features = ["objc"] }
#ferment-sys = { path = "../../ferment/ferment-sys", features = ["objc"] }

[features]
default = ["state-transitions", "std"]
default = ["state-transitions", "std", "message_verification", "quorum_validation"]
bls-signatures = ["dpp/bls-signatures"]
blsful = ["dashcore/blsful"]
cbor = ["platform-value/cbor", "dpp/cbor", "dpp/ciborium"]
Expand All @@ -79,6 +74,7 @@ json-object = ["dpp/json-object"]
json-schema-validation = ["dpp/json-schema-validation"]
message-signing = ["dpp/message-signing"]
message_verification = ["dashcore/message_verification"]
quorum_validation = ["dashcore/quorum_validation"]
mocks = ["dash-sdk/mocks"]
mock-versions = ["platform-version/mock-versions"]
objc = ["ferment-sys/objc"]
Expand All @@ -99,5 +95,4 @@ name = "dash_spv_apple_bindings"
crate-type = ["staticlib", "cdylib"]

[package.metadata]
ios-deployment-target = "12.0" # Set to a common minimum target (e.g., 12.0)

ios-deployment-target = "14.0"
1 change: 0 additions & 1 deletion dash-spv-apple-bindings/build.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
extern crate cbindgen;
extern crate ferment_sys;

use ferment_sys::Ferment;
Expand Down
4 changes: 2 additions & 2 deletions dash-spv-apple-bindings/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ build_targets=(
)
export IPHONEOS_DEPLOYMENT_TARGET=$MIN_IOS
export MACOSX_DEPLOYMENT_TARGET=$MIN_MACOS
export RUSTC_LOG=rustc_codegen_ssa::back::link=info
#export RUSTC_LOG=rustc_codegen_ssa::back::link=info

if $OBJC; then
features="objc"
Expand All @@ -87,7 +87,7 @@ done

wait
mkdir -p target/{framework,include,lib/{ios,ios-simulator,macos}}
./verify_o_set.sh $MIN_IOS ../target
./verify_o_set.sh $MIN_IOS ../target/"$BUILD_TYPE"
./verify_a_lib.sh $MIN_IOS ../target/x86_64-apple-ios/"$BUILD_TYPE"/lib${LIB_NAME}.a
./verify_a_lib.sh $MIN_IOS ../target/aarch64-apple-ios/"$BUILD_TYPE"/lib${LIB_NAME}.a

Expand Down
46 changes: 1 addition & 45 deletions dash-spv-apple-bindings/cbindgen.toml
Original file line number Diff line number Diff line change
Expand Up @@ -83,55 +83,11 @@ prefix_with_name = true
"feature = mocks" = "DASH_SDK_MOCKS"
"feature = mock-versions" = "PLATFORM_VERSION_MOCK_VERSIONS"
"feature = platform-value" = "DPP_PLATFORM_VALUE"
"feature = quorum_validation" = "DASHCORE_QUORUM_VALIDATION"
"feature = state-transitions" = "DPP_STATE_TRANSITIONS"
"feature = state-transition-json-conversion" = "DPP_STATE_TRANSITION_JSON_CONVERSION"
"feature = state-transition-validation" = "DPP_STATE_TRANSITION_VALIDATION"
"feature = state-transition-signing" = "DPP_STATE_TRANSITION_SIGNING"
"feature = std" = "PLATFORM_VALUE_STD"
"feature = system_contracts" = "DPP_SYSTEM_CONTRACTS"
"feature = validation" = "DPP_VALIDATION"

#rename_variants = "None"
## must_use = "MUST_USE_ENUM"
#add_sentinel = false
#derive_helper_methods = false
#derive_const_casts = false
#derive_mut_casts = false
## cast_assert_name = "ASSERT"
#derive_tagged_enum_destructor = false
#derive_tagged_enum_copy_constructor = false
#enum_class = true
#private_default_tagged_enum_constructor = false


#// Here we write down crate names (!) where we want to retrieve C-bindings
#let includes = vec![
#"dash-spv-masternode-processor".to_string(),
#"rs-merk-verify-c-binding".to_string()
#];
#let config = cbindgen::Config {
#language: cbindgen::Language::C,
#parse: cbindgen::ParseConfig {
#parse_deps: true,
#include: Some(includes.clone()),
#extra_bindings: includes.clone(),
#expand: cbindgen::ParseExpandConfig {
#crates: includes.clone(),
#..Default::default()
#},
#..Default::default()
#},
#enumeration: cbindgen::EnumConfig {
#prefix_with_name: true,
#..Default::default()
#},
#braces: cbindgen::Braces::SameLine,
#line_length: 80,
#tab_width: 4,
#documentation_style: cbindgen::DocumentationStyle::C,
#include_guard: Some("dash_shared_core_h".to_string()),
#..Default::default()
#};
#cbindgen::generate_with_config(&crate_dir, config)
#.unwrap()
#.write_to_file("../target/dash_shared_core.h");
2 changes: 1 addition & 1 deletion dash-spv-apple-bindings/src/fermented.rs

Large diffs are not rendered by default.

40 changes: 1 addition & 39 deletions dash-spv-apple-bindings/src/ffi_core_provider.rs
Original file line number Diff line number Diff line change
@@ -1,30 +1,22 @@
use std::sync::Arc;
use dashcore::bls_sig_utils::BLSSignature;
#[cfg(test)]
use dashcore::secp256k1::hashes::hex::DisplayHex;
use dashcore::sml::masternode_list_entry::qualified_masternode_list_entry::QualifiedMasternodeListEntry;
use dash_spv_crypto::network::ChainType;
#[cfg(all(test, feature = "use_serde"))]
use dash_spv_masternode_processor::common::block::MBlock;
use dash_spv_masternode_processor::processing::core_provider::{CoreProvider, CoreProviderError};
use dash_spv_masternode_processor::processing::core_provider::CoreProvider;
#[cfg(test)]
use dash_spv_masternode_processor::processing::MasternodeProcessor;
#[cfg(test)]
use dash_spv_masternode_processor::tests::FFIContext;
use dash_spv_masternode_processor::models::sync_state::CacheState;

#[ferment_macro::opaque]
pub struct FFICoreProvider {
pub context: *const std::ffi::c_void,
// pub context: Arc<FFIThreadSafeContext>,
pub chain_type: ChainType,

pub get_block_height_by_hash: Arc<dyn Fn(*const std::os::raw::c_void, [u8; 32]) -> u32>,
pub get_block_hash_by_height: Arc<dyn Fn(*const std::os::raw::c_void, u32) -> Option<[u8; 32]>>,
pub get_cl_signature_by_block_hash: Arc<dyn Fn(*const std::os::raw::c_void, [u8; 32]) -> Result<BLSSignature, CoreProviderError>>,
pub update_address_usage_of_masternodes: Arc<dyn Fn(*const std::os::raw::c_void, Vec<QualifiedMasternodeListEntry>)>,
pub issue_with_masternode_list_from_peer: Arc<dyn Fn(*const std::os::raw::c_void, bool, *const std::os::raw::c_void)>,
pub notify_sync_state: Arc<dyn Fn(*const std::os::raw::c_void, CacheState)>,
}

unsafe impl Send for FFICoreProvider {}
Expand All @@ -43,10 +35,6 @@ impl CoreProvider for FFICoreProvider {
fn chain_type(&self) -> ChainType {
self.chain_type.clone()
}
fn lookup_cl_signature_by_block_hash(&self, block_hash: [u8; 32]) -> Result<BLSSignature, CoreProviderError> {
(self.get_cl_signature_by_block_hash)(self.context, block_hash)
}

fn lookup_block_hash_by_height(&self, block_height: u32) -> Option<[u8; 32]> {
(self.get_block_hash_by_height)(self.context, block_height)
}
Expand All @@ -58,43 +46,27 @@ impl CoreProvider for FFICoreProvider {
fn update_address_usage_of_masternodes(&self, masternodes: Vec<QualifiedMasternodeListEntry>) {
(self.update_address_usage_of_masternodes)(self.context, masternodes)
}

fn issue_with_masternode_list_from_peer(&self, is_dip24: bool, peer: *const std::os::raw::c_void) {
(self.issue_with_masternode_list_from_peer)(self.context, is_dip24, peer)
}
fn notify_sync_state(&self, state: CacheState) {
(self.notify_sync_state)(self.context, state)
}
}

#[ferment_macro::export]
impl FFICoreProvider {
pub fn new<
BHT: Fn(*const std::os::raw::c_void, [u8; 32]) -> u32 + Send + Sync + 'static,
BHH: Fn(*const std::os::raw::c_void, u32) -> Option<[u8; 32]> + Send + Sync + 'static,
CLSBH: Fn(*const std::os::raw::c_void, [u8; 32]) -> Result<BLSSignature, CoreProviderError> + Send + Sync + 'static,
UMU: Fn(*const std::os::raw::c_void, Vec<QualifiedMasternodeListEntry>) + Send + Sync + 'static,
IWMLFP: Fn(*const std::os::raw::c_void, bool, *const std::os::raw::c_void) + Send + Sync + 'static,
NSS: Fn(*const std::os::raw::c_void, CacheState) + Send + Sync + 'static,
>(
chain_type: ChainType,
get_block_height_by_hash: BHT,
get_block_hash_by_height: BHH,
get_cl_signature_by_block_hash: CLSBH,
update_address_usage_of_masternodes: UMU,
issue_with_masternode_list_from_peer: IWMLFP,
notify_sync_state: NSS,
context: *const std::os::raw::c_void,
) -> Self {
Self {
chain_type,
context,
get_block_height_by_hash: Arc::new(get_block_height_by_hash),
get_block_hash_by_height: Arc::new(get_block_hash_by_height),
get_cl_signature_by_block_hash: Arc::new(get_cl_signature_by_block_hash),
update_address_usage_of_masternodes: Arc::new(update_address_usage_of_masternodes),
issue_with_masternode_list_from_peer: Arc::new(issue_with_masternode_list_from_peer),
notify_sync_state: Arc::new(notify_sync_state),
}
}
}
Expand Down Expand Up @@ -143,17 +115,7 @@ impl FFICoreProvider {
result.ok()
})
},
get_cl_signature_by_block_hash: Arc::new(move |context, block_hash| unsafe {
let context = Arc::from_raw(context as *const FFIContext);
let result = context.cl_signature_by_block_hash(&block_hash)
.map(|sig| BLSSignature::from(sig))
.ok_or(CoreProviderError::NullResult(format!("No cl signature by block_hash {} ({})", block_hash.to_lower_hex_string(), block_hash.reversed().to_lower_hex_string())));
std::mem::forget(context);
result
}),
update_address_usage_of_masternodes: Arc::new(|context, modified_masternodes| {}),
issue_with_masternode_list_from_peer: Arc::new(|context, is_dip24, peer| {}),
notify_sync_state: Arc::new(|context, state| {}),
}
}
pub fn default_processor(context: Arc<FFIContext>, chain_type: ChainType) -> MasternodeProcessor {
Expand Down
28 changes: 4 additions & 24 deletions dash-spv-apple-bindings/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ pub extern crate dash_spv_coinjoin;
use std::fmt::{Debug, Formatter};
use std::sync::Arc;
use dashcore::{Network, QuorumHash};
use dashcore::bls_sig_utils::BLSSignature;
use dashcore::hashes::Hash;
use dashcore::sml::llmq_type::LLMQType;
use dashcore::sml::masternode_list_entry::qualified_masternode_list_entry::QualifiedMasternodeListEntry;
Expand All @@ -31,11 +30,11 @@ use dpp::prelude::CoreBlockHeight;
use dpp::errors::ProtocolError;
use drive_proof_verifier::error::ContextProviderError;
use dash_spv_crypto::network::{ChainType, IHaveChainSettings};
use dash_spv_masternode_processor::processing::core_provider::CoreProviderError;
use dash_spv_masternode_processor::processing::MasternodeProcessor;
use dash_spv_platform::PlatformSDK;
use platform_value::{BinaryData, Identifier};
use dash_spv_masternode_processor::models::sync_state::CacheState;
use dash_spv_crypto::crypto::byte_util::Reversed;
use dash_spv_masternode_processor::processing::processor::DiffConfig;
use dash_spv_platform::cache::PlatformCache;
use crate::ffi_core_provider::FFICoreProvider;

Expand All @@ -53,12 +52,6 @@ impl Debug for DashSPVCore {
}
// AnyOther by_value: Type(Dictionary(NonPrimitiveFermentable(SmartPointer(Arc($Ty(std :: sync :: Arc < dyn Fn (* const std :: os :: raw :: c_void , u32) -> Option < [u8 ; 32] > >, [Object(Type(Dictionary(LambdaFn($Ty(dyn Fn (* const std :: os :: raw :: c_void , u32) -> Option < [u8 ; 32] >, [])))))]))))))

#[ferment_macro::export]
#[derive(Clone)]
pub struct DiffConfig {
pub bytes: Vec<u8>,
pub height: u32,
}

#[ferment_macro::export]
impl DashSPVCore {
Expand All @@ -72,10 +65,7 @@ impl DashSPVCore {
// masternode
BHT: Fn(*const std::os::raw::c_void, [u8; 32]) -> u32 + Send + Sync + 'static,
BHH: Fn(*const std::os::raw::c_void, u32) -> Option<[u8; 32]> + Send + Sync + 'static,
CLSBH: Fn(*const std::os::raw::c_void, [u8; 32]) -> Result<BLSSignature, CoreProviderError> + Send + Sync + 'static,
UMU: Fn(*const std::os::raw::c_void, Vec<QualifiedMasternodeListEntry>) + Send + Sync + 'static,
IWMLFP: Fn(*const std::os::raw::c_void, bool, *const std::os::raw::c_void) + Send + Sync + 'static,
NSS: Fn(*const std::os::raw::c_void, CacheState) + Send + Sync + 'static,
>(
chain_type: ChainType,
diff_config: Option<DiffConfig>,
Expand All @@ -88,32 +78,22 @@ impl DashSPVCore {

get_block_height_by_hash: BHT,
get_block_hash_by_height: BHH,
get_cl_signature_by_block_hash: CLSBH,
update_address_usage_of_masternodes: UMU,
issue_with_masternode_list_from_peer: IWMLFP,
notify_sync_state: NSS,

context: *const std::os::raw::c_void) -> Self {
let provider = Arc::new(FFICoreProvider::new(
chain_type.clone(),
get_block_height_by_hash,
get_block_hash_by_height,
get_cl_signature_by_block_hash,
update_address_usage_of_masternodes,
issue_with_masternode_list_from_peer,
notify_sync_state,
context));
let network = Network::from(chain_type.clone());
let processor = if let Some(DiffConfig { bytes, height }) = diff_config {
MasternodeProcessor::from_bincode_list_diff(provider.clone(), network, &bytes, height)
} else {
MasternodeProcessor::new(provider.clone(), network)
};
let processor = MasternodeProcessor::from_diff_config(provider.clone(), network, diff_config);
let processor_arc = Arc::new(processor);
let processor_arc_clone = Arc::clone(&processor_arc);
let get_quorum_public_key = Arc::new(move |llmq_type: u32, llmq_hash: [u8; 32], core_chain_locked_height: u32| {
let llmq_type = LLMQType::from_u16(llmq_type as u16);
let llmq_hash = QuorumHash::from_byte_array(llmq_hash);
let llmq_hash = QuorumHash::from_byte_array(llmq_hash.reversed());
processor_arc_clone.engine.find_quorum_public_key(&llmq_type, &llmq_hash)
.map(|key| key.0)
.ok_or(ContextProviderError::InvalidQuorum(format!("Quorum not found: {}: {}", llmq_type, llmq_hash.to_string())))
Expand Down
45 changes: 0 additions & 45 deletions dash-spv-apple-bindings/src/tests/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,56 +4,12 @@ use dashcore::hashes::Hash;
use dashcore::hashes::hex::FromHex;
use dashcore::ProTxHash;
use dash_spv_crypto::network::ChainType;
use dash_spv_masternode_processor::logger::register_rust_logger;
use dash_spv_masternode_processor::block_store::MerkleBlock;
use dash_spv_masternode_processor::processing::processor::processing_error::ProcessingError;
use dash_spv_masternode_processor::test_helpers::load_message;
pub use dash_spv_masternode_processor::tests::FFIContext;
use crate::ffi_core_provider::FFICoreProvider;

extern crate libc;
extern crate reqwest;

#[cfg(all(feature = "test-helpers", feature = "use_serde"))]
pub fn get_block_from_insight_by_hash(hash: [u8; 32]) -> Option<MerkleBlock> {
use dashcore::secp256k1::hashes::hex::DisplayHex;
use dash_spv_crypto::crypto::byte_util::Reversed;
let path = format!("https://testnet-insight.dashevo.org/insight-api/block/{}", hash.reversed().to_lower_hex_string().as_str());
request_block(path)
}
#[cfg(all(feature = "test-helpers", feature = "use_serde"))]
pub fn get_block_from_insight_by_height(height: u32) -> Option<MerkleBlock> {
let path = format!("https://testnet-insight.dashevo.org/insight-api/block/{}", height);
request_block(path)
}

#[cfg(all(feature = "test-helpers", feature = "use_serde"))]
pub fn request_block(path: String) -> Option<MerkleBlock> {
println!("request_block: {}", path.as_str());
match reqwest::blocking::get(path.as_str()) {
Ok(response) => match response.json::<serde_json::Value>() {
Ok(json) => {
let block: dash_spv_masternode_processor::tests::serde_helper::Block = serde_json::from_value(json).unwrap();
let merkle_block = MerkleBlock::from(block);
println!("request_block: {}", path.as_str());
Some(merkle_block)
},
Err(err) => {
println!("{}", err);
None
},
},
Err(err) => {
println!("{}", err);
None
},
}
}

pub fn register_logger() {
unsafe { register_rust_logger(); }
}

pub fn get_file_as_byte_vec(filename: &str) -> Vec<u8> {
//println!("get_file_as_byte_vec: {}", filename);
if let (Ok(mut f), Ok(metadata)) = (fs::File::open(&filename), fs::metadata(&filename)) {
Expand Down Expand Up @@ -156,7 +112,6 @@ pub fn extract_protocol_version_from_filename(filename: &str) -> Option<u32> {
}

pub fn assert_diff_chain(chain: ChainType, diff_files: &[&'static str], qrinfo_files: &[&'static str], block_store: Option<Vec<MerkleBlock>>, allow_invalid_merkle_roots: bool) {
register_logger();
let context = Arc::new(FFIContext::chain_default(chain.clone(), false, block_store.unwrap_or_default()));
let mut processor = FFICoreProvider::default_processor(Arc::clone(&context), chain.clone());
diff_files.iter().for_each(|filename| {
Expand Down
Loading
Loading