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
11 changes: 10 additions & 1 deletion DashSync/shared/DSDashSharedCore.m
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,17 @@ - (instancetype)initOnChain:(DSChain *)chain {
break;
}
Vec_ *address_list = [NSArray ffi_to_vec:addresses];
dash_spv_apple_bindings_DiffConfig *diff_config = NULL;
if ([chain isMainnet]) {
NSString *bundlePath = [[NSBundle bundleForClass:self.class] pathForResource:@"DashSync" ofType:@"bundle"];
NSBundle *bundle = [NSBundle bundleWithPath:bundlePath];
NSString *filePath = [bundle pathForResource:@"mn_list_diff_0_2227096" ofType:@"bin"];
NSData *data = [NSData dataWithContentsOfFile:filePath];

diff_config = dash_spv_apple_bindings_DiffConfig_ctor(bytes_ctor(data), 2227096);
}

self.core = dash_spv_apple_bindings_DashSPVCore_with_callbacks(chain.chainType, address_list, get_data_contract, get_platform_activation_height, callback_signer, callback_can_sign, 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);
self.core = dash_spv_apple_bindings_DashSPVCore_with_callbacks(chain.chainType, diff_config, address_list, get_data_contract, get_platform_activation_height, callback_signer, callback_can_sign, 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);
return self;
}

Expand Down
2 changes: 2 additions & 0 deletions DashSync/shared/DashSync.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@
#import "DSProviderUpdateRegistrarTransaction.h"
#import "DSProviderUpdateRevocationTransaction.h"
#import "DSProviderUpdateServiceTransaction.h"
#import "DSAssetLockTransaction.h"
#import "DSAssetUnlockTransaction.h"

#import "DSPaymentProtocol.h"
#import "DSPaymentRequest.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,21 @@
//

#import <Foundation/Foundation.h>
#import "dash_spv_apple_bindings.h"
#import "DSKeyManager.h"

NS_ASSUME_NONNULL_BEGIN

@interface NSError (dash_spv_platform_error_Error)
+ (NSError *)ffi_from_platform_error:(dash_spv_platform_error_Error *)ffi_ref;
@interface NSError (DPlatformError)
+ (NSError *)ffi_from_platform_error:(DPlatformError *)ffi_ref;
@end


@interface NSError (dash_spv_crypto_keys_KeyError)
@interface NSError (DKeyError)
+ (NSError *)ffi_from_key_error:(DKeyError *)ffi_ref;
@end

@interface NSError (dash_spv_masternode_processor_processing_core_provider_CoreProviderError)
+ (NSError *)ffi_from_core_provider_error:(dash_spv_masternode_processor_processing_core_provider_CoreProviderError *)ffi_ref;
@interface NSError (DCoreProviderError)
+ (NSError *)ffi_from_core_provider_error:(DCoreProviderError *)ffi_ref;
@end

@interface NSError (DProcessingError)
Expand Down
114 changes: 57 additions & 57 deletions DashSync/shared/Libraries/AdvancedOperations/Others/NSError+Platform.m

Large diffs are not rendered by default.

Binary file not shown.
4 changes: 2 additions & 2 deletions DashSync/shared/Models/Chain/DSChain+Params.m
Original file line number Diff line number Diff line change
Expand Up @@ -315,8 +315,8 @@ - (BOOL)allowMinDifficultyBlocks {
}

- (uint64_t)baseReward {
if (dash_spv_crypto_network_chain_type_ChainType_is_mainnet(self.chainType)) return 5 * DUFFS;
return 50 * DUFFS;
if (dash_spv_crypto_network_chain_type_ChainType_is_mainnet(self.chainType)) return 5 * DUFFS_OBJC;
return 50 * (unsigned long long) DUFFS_OBJC;
}
- (uint32_t)coinType {
return dash_spv_crypto_network_chain_type_ChainType_coin_type(self.chainType);
Expand Down
13 changes: 9 additions & 4 deletions DashSync/shared/Models/Chain/DSChain+Transaction.m
Original file line number Diff line number Diff line change
Expand Up @@ -314,22 +314,27 @@ - (void)triggerUpdatesForLocalReferences:(DSTransaction *)transaction {
UInt160 creditBurnPublicKeyHash = tx.creditBurnPublicKeyHash;
uint32_t index;
DSWallet *wallet = [self walletHavingIdentityAssetLockRegistrationHash:creditBurnPublicKeyHash foundAtIndex:&index];
UInt256 identityId = tx.creditBurnIdentityIdentifier;
if (wallet) {
DSIdentity *identity = [wallet identityForUniqueId:tx.creditBurnIdentityIdentifier];
DSIdentity *identity = [wallet identityForUniqueId:identityId];
if (!identity) {
identity = [[DSIdentity alloc] initAtIndex:index withAssetLockTransaction:tx inWallet:wallet];
[identity registerInWalletForAssetLockTransaction:tx];
}
} else {
wallet = [self walletHavingIdentityAssetLockTopupHash:creditBurnPublicKeyHash foundAtIndex:&index];
if (wallet) {
DSIdentity *identity = [wallet identityForUniqueId:tx.creditBurnIdentityIdentifier];
// [identity r]
DSIdentity *identity = [wallet identityForUniqueId:identityId];
if (identity) {
[identity registerInWalletForAssetLockTopupTransaction:tx];
} else {
NSAssert(NO, @"Topup unknown identity %@", uint256_hex(identityId));
}

} else {
wallet = [self walletHavingIdentityAssetLockInvitationHash:creditBurnPublicKeyHash foundAtIndex:&index];
if (wallet) {
DSInvitation *invitation = [wallet invitationForUniqueId:tx.creditBurnIdentityIdentifier];
DSInvitation *invitation = [wallet invitationForUniqueId:identityId];
if (!invitation) {
invitation = [[DSInvitation alloc] initAtIndex:index withAssetLockTransaction:tx inWallet:wallet];
[invitation registerInWalletForAssetLockTransaction:tx];
Expand Down
1 change: 1 addition & 0 deletions DashSync/shared/Models/Chain/DSChain.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ typedef NS_ENUM(uint16_t, DSChainSyncPhase)
/*! @brief Returns a known block with a given distance from the chain tip. A null result would mean that the given distance exceeded the number of blocks kept locally. */
- (DSMerkleBlock *_Nullable)blockFromChainTip:(NSUInteger)blocksAgo;

- (UInt256)chainTipHash;
- (uint32_t)chainTipHeight;

// MARK: Chain Sync
Expand Down
11 changes: 7 additions & 4 deletions DashSync/shared/Models/Chain/DSChain.m
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ - (instancetype)initAsDevnetWithIdentifier:(dash_spv_crypto_network_chain_type_D
checkpoints:(NSArray<DSCheckpoint *> *)checkpoints {
//for devnet the genesis checkpoint is really the second block
if (!(self = [self init])) return nil;
self.chainType = dash_spv_crypto_network_chain_type_ChainType_DevNet_ctor(devnetType);
self.chainType = DChainTypeDevnet(devnetType);
if (!checkpoints || ![checkpoints count]) {
DSCheckpoint *genesisCheckpoint = [DSCheckpoint genesisDevnetCheckpoint];
DSCheckpoint *secondCheckpoint = [self createDevNetGenesisBlockCheckpointForParentCheckpoint:genesisCheckpoint withIdentifier:devnetType onProtocolVersion:protocolVersion];
Expand Down Expand Up @@ -246,7 +246,7 @@ + (DSChain *)mainnet {
static dispatch_once_t mainnetToken = 0;
__block BOOL inSetUp = FALSE;
dispatch_once(&mainnetToken, ^{
_mainnet = [[DSChain alloc] initWithType:dash_spv_crypto_network_chain_type_ChainType_MainNet_ctor() checkpoints:[DSChain createCheckpointsArrayFromCheckpoints:mainnet_checkpoint_array count:(sizeof(mainnet_checkpoint_array) / sizeof(*mainnet_checkpoint_array))]];
_mainnet = [[DSChain alloc] initWithType:DChainTypeMainnet() checkpoints:[DSChain createCheckpointsArrayFromCheckpoints:mainnet_checkpoint_array count:(sizeof(mainnet_checkpoint_array) / sizeof(*mainnet_checkpoint_array))]];
inSetUp = TRUE;
});
if (inSetUp) {
Expand All @@ -270,7 +270,7 @@ + (DSChain *)testnet {
static dispatch_once_t testnetToken = 0;
__block BOOL inSetUp = FALSE;
dispatch_once(&testnetToken, ^{
_testnet = [[DSChain alloc] initWithType:dash_spv_crypto_network_chain_type_ChainType_TestNet_ctor() checkpoints:[DSChain createCheckpointsArrayFromCheckpoints:testnet_checkpoint_array count:(sizeof(testnet_checkpoint_array) / sizeof(*testnet_checkpoint_array))]];
_testnet = [[DSChain alloc] initWithType:DChainTypeTestnet() checkpoints:[DSChain createCheckpointsArrayFromCheckpoints:testnet_checkpoint_array count:(sizeof(testnet_checkpoint_array) / sizeof(*testnet_checkpoint_array))]];
inSetUp = TRUE;
});
if (inSetUp) {
Expand Down Expand Up @@ -557,6 +557,9 @@ - (NSTimeInterval)startSyncFromTime {
- (NSString *)chainTip {
return [NSData dataWithUInt256:self.lastTerminalBlock.blockHash].shortHexString;
}
- (UInt256)chainTipHash {
return self.lastTerminalBlock.blockHash;
}
- (uint32_t)chainTipHeight {
return self.lastTerminalBlock.height;
}
Expand Down Expand Up @@ -1072,7 +1075,7 @@ - (BOOL)addBlock:(DSBlock *)block receivedAsHeader:(BOOL)isHeaderOnly fromPeer:(

NSValue *blockHash = uint256_obj(block.blockHash), *prevBlock = uint256_obj(block.prevBlock);
DSBlock *prev = nil;
DSLog(@"[%@] + block (asHeader: %u) %@ prev: %@", self.name, isHeaderOnly, uint256_hex(block.blockHash), uint256_hex(block.prevBlock));
//DSLog(@"[%@] + block (asHeader: %u) %@ prev: %@", self.name, isHeaderOnly, uint256_hex(block.blockHash), uint256_hex(block.prevBlock));

DSBlockPosition blockPosition = DSBlockPosition_Orphan;
DSChainSyncPhase phase = self.chainManager.syncPhase;
Expand Down
6 changes: 3 additions & 3 deletions DashSync/shared/Models/CoinJoin/DSCoinJoinManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ - (void)initMasternodeGroup {
}

- (DCoinJoinClientOptions *)createOptions {
DCoinJoinClientOptions *options = dash_spv_coinjoin_models_coinjoin_client_options_CoinJoinClientOptions_ctor(true, DUFFS / 8, 6, 1, COINJOIN_RANDOM_ROUNDS, DEFAULT_COINJOIN_DENOMS_GOAL, DEFAULT_COINJOIN_DENOMS_HARDCAP, false, self.chain.chainType, false);
DCoinJoinClientOptions *options = dash_spv_coinjoin_models_coinjoin_client_options_CoinJoinClientOptions_ctor(true, DUFFS_OBJC / 8, 6, 1, COINJOIN_RANDOM_ROUNDS, DEFAULT_COINJOIN_DENOMS_GOAL, DEFAULT_COINJOIN_DENOMS_HARDCAP, false, self.chain.chainType, false);
return options;
}

Expand Down Expand Up @@ -586,7 +586,7 @@ - (uint32_t)countInputsWithAmount:(uint64_t)inputAmount {
}
found = !dash_spv_coinjoin_coinjoin_CoinJoin_is_denominated_amount(value);
} else if (coinType == dash_spv_coinjoin_models_coin_control_CoinType_OnlyMasternodeCollateral) {
found = value == 1000 * DUFFS;
found = value == 1000 * DUFFS_OBJC;
} else if (coinType == dash_spv_coinjoin_models_coin_control_CoinType_OnlyCoinJoinCollateral) {
found = dash_spv_coinjoin_coinjoin_CoinJoin_is_collateral_amount(value);
} else {
Expand Down Expand Up @@ -626,7 +626,7 @@ - (uint32_t)countInputsWithAmount:(uint64_t)inputAmount {
[vCoins addObject:[[DSInputCoin alloc] initWithTx:coin index:i]];

// Checks the sum amount of all UTXO's.
if (minimumSumAmount != MAX_MONEY) {
if (minimumSumAmount != MAX_MONEY_OBJC) {
total += value;

if (total >= minimumSumAmount) {
Expand Down
2 changes: 2 additions & 0 deletions DashSync/shared/Models/CoinJoin/DSCoinJoinWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ NS_ASSUME_NONNULL_BEGIN
#define DCoinJoinTransactionType dash_spv_coinjoin_models_coinjoin_tx_type_CoinJoinTransactionType
#define DCoinJoinTransactionTypeIndex(ptr) dash_spv_coinjoin_models_coinjoin_tx_type_CoinJoinTransactionType_index(ptr)
#define DCoinJoinClientOptions dash_spv_coinjoin_models_coinjoin_client_options_CoinJoinClientOptions
#define DCoinJoinClientOptionsCtor(enable, amount, sessions, rounds, random_rounds, denoms_goal, denoms_hardcap, multi_session, chain_type, denom_only) dash_spv_coinjoin_models_coinjoin_client_options_CoinJoinClientOptions_ctor(enable, amount, sessions, rounds, random_rounds, denoms_goal, denoms_hardcap, multi_session, chain_type, denom_only)
#define DCoinJoinClientOptionsDtor(ptr) dash_spv_coinjoin_models_coinjoin_client_options_CoinJoinClientOptions_destroy(ptr)
#define DInputCoin dash_spv_coinjoin_coin_selection_input_coin_InputCoin
#define DInputCoinCtor(outpoint, out, value) dash_spv_coinjoin_coin_selection_input_coin_InputCoin_ctor(outpoint, out, value)
#define DInputCoinDtor(ptr) dash_spv_coinjoin_coin_selection_input_coin_InputCoin_destroy(ptr)
Expand Down
8 changes: 4 additions & 4 deletions DashSync/shared/Models/CoinJoin/DSCoinJoinWrapper.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

#import "DSCoinJoinManager.h"
#import "DSWallet.h"
#import "DSTransaction+CoinJoin.h"
#import "DSTransaction+FFI.h"
#import "DSAccount.h"
#import "DSChain+Params.h"
#import "DSChain+Transaction.h"
Expand Down Expand Up @@ -393,8 +393,8 @@ bool isMineInput(const void *context, DOutPoint *outpoint) {
onlySafe:onlySafe
coinControl:cc
minimumAmount:1
maximumAmount:MAX_MONEY
minimumSumAmount:MAX_MONEY
maximumAmount:MAX_MONEY_OBJC
minimumSumAmount:MAX_MONEY_OBJC
maximumCount:0];
DCoinControlDtor(coinControl);
NSUInteger count = coins.count;
Expand Down Expand Up @@ -435,7 +435,7 @@ bool isMineInput(const void *context, DOutPoint *outpoint) {
DTransaction* signTransaction(const void *context, DTransaction *transaction, bool anyoneCanPay) {
@synchronized (context) {
DSCoinJoinWrapper *wrapper = AS_OBJC(context);
DSTransaction *tx = [[DSTransaction alloc] initWithTransaction:transaction onChain:wrapper.chain];
DSTransaction *tx = [DSTransaction ffi_from:transaction onChain:wrapper.chain];
DTransactionDtor(transaction);
BOOL isSigned = [wrapper.chain.wallets.firstObject.accounts.firstObject signTransaction:tx anyoneCanPay:anyoneCanPay];
if (isSigned) {
Expand Down
4 changes: 2 additions & 2 deletions DashSync/shared/Models/CoinJoin/DSInputCoin.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
//

#import "DSInputCoin.h"
#import "DSTransactionOutput+FFI.h"

@implementation DSInputCoin

Expand All @@ -33,8 +34,7 @@ - (instancetype)initWithTx:(DSTransaction *)tx index:(int32_t)i {
- (DInputCoin *)ffi_malloc:(DChainType *)type {
// TODO: check outpoint hash reverse or not
DOutPoint *outpoint = DOutPointCtorU(self.outpointHash, self.outpointIndex);
DTxOut *tx_out = DTxOutCtor(self.output.amount, DScriptBufCtor(bytes_ctor(self.output.outScript)));
return DInputCoinCtor(outpoint, tx_out, self.effectiveValue);
return DInputCoinCtor(outpoint, [self.output ffi_malloc], self.effectiveValue);
}

+ (void)ffi_free:(DInputCoin *)inputCoin {
Expand Down
13 changes: 7 additions & 6 deletions DashSync/shared/Models/CoinJoin/Utils/DSMasternodeGroup.m
Original file line number Diff line number Diff line change
Expand Up @@ -448,14 +448,15 @@ - (BOOL)connectTo:(DSPeer *)peer {
DSLog(@"[%@] CoinJoin: session is not connected to a masternode, sessionId: %@", self.chain.name, uint256_hex(sessionId));
return NO;
}

DSChainManager *chainManager = self.chain.chainManager;
DSLog(@"[%@] CoinJoin: masternode[connecting] %@: %@; %@", self.chain.name, peer.location, uint256_hex(proTxHash), uint256_hex(sessionId));

[peer setChainDelegate:self.chain.chainManager
peerDelegate:self transactionDelegate:self.chain.chainManager.transactionManager
governanceDelegate:self.chain.chainManager.governanceSyncManager
sporkDelegate:self.chain.chainManager.sporkManager
masternodeDelegate:self.chain.chainManager.masternodeManager
[peer setChainDelegate:chainManager
peerDelegate:self
transactionDelegate:(id<DSPeerTransactionDelegate>) chainManager.transactionManager
governanceDelegate:(id<DSPeerGovernanceDelegate>) chainManager.governanceSyncManager
sporkDelegate:(id<DSPeerSporkDelegate>) chainManager.sporkManager
masternodeDelegate:chainManager.masternodeManager
queue:self.networkingQueue];
peer.earliestKeyTime = self.chain.earliestWalletCreationTime;;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ NS_ASSUME_NONNULL_BEGIN

- (DMaybeOpaqueKey *_Nullable)privateKeyAtIndexPath:(NSIndexPath *)indexPath;

- (UInt256)keyIdAtIndex:(uint32_t)index;
@end

NS_ASSUME_NONNULL_END
Original file line number Diff line number Diff line change
Expand Up @@ -313,4 +313,9 @@ - (void)storeNewAddressInContext:(NSString *)address
}];
}

- (UInt256)keyIdAtIndex:(uint32_t)index {
NSData *data = [self publicKeyDataAtIndexPath:[NSIndexPath indexPathWithIndex:index]];
return [data SHA256];
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#import "DSInstantSendLockEntity+CoreDataClass.h"
#import "DSInstantSendTransactionLock.h"
#import "DSTransactionEntity+CoreDataClass.h"
#import "DSTransactionHashEntity+CoreDataClass.m"
#import "DSTransactionHashEntity+CoreDataClass.h"
#import "DSTxInputEntity+CoreDataClass.h"
#import "NSData+Dash.h"
#import "NSManagedObject+Sugar.h"
Expand Down Expand Up @@ -50,13 +50,13 @@ - (DSInstantSendTransactionLock *)instantSendTransactionLockForChain:(DSChain *)
[inputOutpoints addObject:dsutxo_data(input.outpoint)];
}
return [[DSInstantSendTransactionLock alloc] initWithTransactionHash:self.transaction.transactionHash.txHash
withInputOutpoints:inputOutpoints
version:self.version
signature:self.signature
cycleHash:self.cycleHash
signatureVerified:TRUE
quorumVerified:TRUE
onChain:chain];
withInputOutpoints:inputOutpoints
version:self.version
signature:self.signature
cycleHash:self.cycleHash
signatureVerified:TRUE
quorumVerified:TRUE
onChain:chain];
}

@end
5 changes: 4 additions & 1 deletion DashSync/shared/Models/Identity/DSIdentity.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,11 +203,14 @@ NSString * DSIdentityQueryStepsDescription(DSIdentityQueryStep step);
*/
- (BOOL)unregisterLocally;

/*! @brief Register the blockchain identity to its wallet from a credit funding registration transaction. This should only be done once on the creation of the blockchain identity.
/*! @brief Register the blockchain identity to its wallet from a asset lock transaction. This should only be done once on the creation of the blockchain identity.
@param transaction The asset lock transaction used to initially fund the blockchain identity.
*/
- (void)registerInWalletForAssetLockTransaction:(DSAssetLockTransaction *)transaction;


- (void)registerInWalletForAssetLockTopupTransaction:(DSAssetLockTransaction *)transaction;

// MARK: - Keys

/*! @brief Register the blockchain identity to its wallet from a credit funding registration transaction. This should only be done once on the creation of the blockchain identity.
Expand Down
5 changes: 3 additions & 2 deletions DashSync/shared/Models/Identity/DSIdentity.m
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#import "DSFriendRequestEntity+CoreDataClass.h"
#import "DSMerkleBlock.h"
#import "DSOptionsManager.h"
#import "DSTransactionOutput+FFI.h"
#import "DSTransactionHashEntity+CoreDataClass.h"
#import "DSWallet+Identity.h"
#import "NSData+Encryption.h"
Expand Down Expand Up @@ -1317,7 +1318,7 @@ - (DAssetLockProof *)createInstantProof:(DInstantLock *)isLock {
DTxOut **tx_outputs = malloc(sizeof(DTxOut *) * outputsCount);
for (int i = 0; i < outputs.count; i++) {
DSTransactionOutput *o = outputs[i];
tx_outputs[i] = DTxOutCtor(o.amount, DScriptBufCtor(o.outScript ? bytes_ctor(o.outScript) : bytes_ctor([NSData data])));
tx_outputs[i] = [o ffi_malloc];
}
uint8_t asset_lock_payload_version = self.registrationAssetLockTransaction.specialTransactionVersion;

Expand All @@ -1326,7 +1327,7 @@ - (DAssetLockProof *)createInstantProof:(DInstantLock *)isLock {
DTxOut **credit_outputs = malloc(sizeof(DTxOut *) * creditOutputsCount);
for (int i = 0; i < creditOutputsCount; i++) {
DSTransactionOutput *o = creditOutputs[i];
credit_outputs[i] = DTxOutCtor(o.amount, DScriptBufCtor(o.outScript ? bytes_ctor(o.outScript) : bytes_ctor([NSData data])));
credit_outputs[i] = [o ffi_malloc];
}

DTxInputs *input_vec = DTxInputsCtor(inputsCount, tx_inputs);
Expand Down
Loading
Loading