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

Feat/asset unlock #578

Merged
merged 2 commits into from
Nov 6, 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
2 changes: 1 addition & 1 deletion DashSync/shared/DashSync.xcdatamodeld/.xccurrentversion
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
<plist version="1.0">
<dict>
<key>_XCCurrentVersionName</key>
<string>DashSync 20.xcdatamodel</string>
<string>DashSync 21.xcdatamodel</string>
</dict>
</plist>
529 changes: 529 additions & 0 deletions DashSync/shared/DashSync.xcdatamodeld/DashSync 21.xcdatamodel/contents

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//
// Created by Vladimir Pirogov
// Copyright © 2024 Dash Core Group. All rights reserved.
//
// Licensed under the MIT License (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://opensource.org/licenses/MIT
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

#import "DSSpecialTransactionEntity+CoreDataClass.h"
#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

@interface DSAssetLockTransactionEntity : DSSpecialTransactionEntity
@end

@interface DSAssetLockTransactionEntity (CoreDataGeneratedAccessors)

- (void)insertObject:(DSTxOutputEntity *)value inCreditOutputsAtIndex:(NSUInteger)idx;
- (void)removeObjectFromCreditOutputsAtIndex:(NSUInteger)idx;
- (void)insertCreditOutputs:(NSArray<DSTxOutputEntity *> *)value atIndexes:(NSIndexSet *)indexes;
- (void)removeCreditOutputsAtIndexes:(NSIndexSet *)indexes;
- (void)replaceObjectInCreditOutputsAtIndex:(NSUInteger)idx withObject:(DSTxOutputEntity *)value;
- (void)replaceCreditOutputsAtIndexes:(NSIndexSet *)indexes withOutputs:(NSArray<DSTxOutputEntity *> *)values;
- (void)addCreditOutputsObject:(DSTxOutputEntity *)value;
- (void)removeCreditOutputsObject:(DSTxOutputEntity *)value;
- (void)addCreditOutputs:(NSOrderedSet<DSTxOutputEntity *> *)values;
- (void)removeCreditOutputs:(NSOrderedSet<DSTxOutputEntity *> *)values;

@end

NS_ASSUME_NONNULL_END

#import "DSAssetLockTransactionEntity+CoreDataProperties.h"
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
//
// Created by Vladimir Pirogov
// Copyright © 2024 Dash Core Group. All rights reserved.
//
// Licensed under the MIT License (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://opensource.org/licenses/MIT
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

#import "DSAddressEntity+CoreDataClass.h"
#import "DSAssetLockTransaction.h"
#import "DSAssetLockTransactionEntity+CoreDataClass.h"
#import "DSChain+Protected.h"
#import "DSChainEntity+CoreDataClass.h"
#import "DSKeyManager.h"
#import "DSTransactionFactory.h"
#import "DSTransactionOutput.h"
#import "DSTxOutputEntity+CoreDataClass.h"
#import "NSData+Dash.h"
#import "NSManagedObject+Sugar.h"
#import "NSString+Dash.h"

@implementation DSAssetLockTransactionEntity

- (instancetype)setAttributesFromTransaction:(DSTransaction *)transaction {
[self.managedObjectContext performBlockAndWait:^{
[super setAttributesFromTransaction:transaction];
DSAssetLockTransaction *tx = (DSAssetLockTransaction *)transaction;
self.specialTransactionVersion = tx.specialTransactionVersion;
NSMutableOrderedSet *creditOutputs = [self mutableOrderedSetValueForKey:@"creditOutputs"];
while (creditOutputs.count < tx.creditOutputs.count) {
[creditOutputs addObject:[DSTxOutputEntity managedObjectInBlockedContext:self.managedObjectContext]];
}
while (creditOutputs.count > tx.creditOutputs.count) {

[self removeObjectFromCreditOutputsAtIndex:creditOutputs.count - 1];
}
NSUInteger idx = 0;
for (DSTxOutputEntity *e in creditOutputs) {
[e setAttributesFromTransaction:tx outputIndex:idx++ forTransactionEntity:self];
}
}];

return self;
}

- (DSTransaction *)transactionForChain:(DSChain *)chain {
DSAssetLockTransaction *tx = (DSAssetLockTransaction *)[super transactionForChain:chain];
tx.type = DSTransactionType_AssetLock;
[self.managedObjectContext performBlockAndWait:^{
tx.specialTransactionVersion = self.specialTransactionVersion;
for (DSTxOutputEntity *e in self.creditOutputs) {
NSString *address = e.address;
if (!address && e.script) {
address = [DSKeyManager addressWithScriptPubKey:e.script forChain:tx.chain];
}
DSTransactionOutput *transactionOutput = [DSTransactionOutput transactionOutputWithAmount:e.value address:address outScript:e.script onChain:tx.chain];
[tx.creditOutputs addObject:transactionOutput];
}
}];

return tx;
}

- (Class)transactionClass {
return [DSAssetLockTransactionEntity class];
}

@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//
// Created by Vladimir Pirogov
// Copyright © 2024 Dash Core Group. All rights reserved.
//
// Licensed under the MIT License (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://opensource.org/licenses/MIT
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

#import "DSAssetLockTransactionEntity+CoreDataClass.h"


NS_ASSUME_NONNULL_BEGIN

@interface DSAssetLockTransactionEntity (CoreDataProperties)

+ (NSFetchRequest<DSAssetLockTransactionEntity *> *)fetchRequest;

@property (nonatomic, retain) NSOrderedSet<DSTxOutputEntity *> *creditOutputs;

@end

NS_ASSUME_NONNULL_END
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//
// Created by Vladimir Pirogov
// Copyright © 2024 Dash Core Group. All rights reserved.
//
// Licensed under the MIT License (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://opensource.org/licenses/MIT
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

#import "DSAssetLockTransactionEntity+CoreDataProperties.h"

@implementation DSAssetLockTransactionEntity (CoreDataProperties)

+ (NSFetchRequest<DSAssetLockTransactionEntity *> *)fetchRequest {
return [NSFetchRequest fetchRequestWithEntityName:@"DSAssetLockTransactionEntity"];
}

@dynamic creditOutputs;

@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//
// Created by Vladimir Pirogov
// Copyright © 2024 Dash Core Group. All rights reserved.
//
// Licensed under the MIT License (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://opensource.org/licenses/MIT
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

#import "DSSpecialTransactionEntity+CoreDataClass.h"
#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

@interface DSAssetUnlockTransactionEntity : DSSpecialTransactionEntity

@end

NS_ASSUME_NONNULL_END

#import "DSAssetUnlockTransactionEntity+CoreDataProperties.h"
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
//
// Created by Vladimir Pirogov
// Copyright © 2024 Dash Core Group. All rights reserved.
//
// Licensed under the MIT License (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://opensource.org/licenses/MIT
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

#import "DSAddressEntity+CoreDataClass.h"
#import "DSAssetUnlockTransaction.h"
#import "DSAssetUnlockTransactionEntity+CoreDataClass.h"
#import "DSChain+Protected.h"
#import "DSChainEntity+CoreDataClass.h"
#import "DSTransaction.h"
#import "DSTransactionFactory.h"
#import "NSData+Dash.h"
#import "NSManagedObject+Sugar.h"

@implementation DSAssetUnlockTransactionEntity

- (instancetype)setAttributesFromTransaction:(DSTransaction *)transaction {
[self.managedObjectContext performBlockAndWait:^{
[super setAttributesFromTransaction:transaction];
DSAssetUnlockTransaction *tx = (DSAssetUnlockTransaction *)transaction;
self.specialTransactionVersion = tx.specialTransactionVersion;
self.index = tx.index;
self.fee = tx.fee;
self.requestedHeight = tx.requestedHeight;
self.quorumHash = uint256_data(tx.quorumHash);
self.quorumSignature = uint768_data(tx.quorumSignature);
}];

return self;
}

- (DSTransaction *)transactionForChain:(DSChain *)chain {
DSAssetUnlockTransaction *tx = (DSAssetUnlockTransaction *)[super transactionForChain:chain];
tx.type = DSTransactionType_AssetUnlock;
[self.managedObjectContext performBlockAndWait:^{
tx.specialTransactionVersion = self.specialTransactionVersion;
tx.index = self.index;
tx.fee = self.fee;
tx.requestedHeight = self.requestedHeight;
tx.quorumHash = self.quorumHash.UInt256;
tx.quorumSignature = self.quorumSignature.UInt768;
}];

return tx;
}

- (Class)transactionClass {
return [DSAssetUnlockTransaction class];
}

@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//
// Created by Vladimir Pirogov
// Copyright © 2024 Dash Core Group. All rights reserved.
//
// Licensed under the MIT License (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://opensource.org/licenses/MIT
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

#import "DSAssetUnlockTransactionEntity+CoreDataClass.h"


NS_ASSUME_NONNULL_BEGIN

@interface DSAssetUnlockTransactionEntity (CoreDataProperties)

+ (NSFetchRequest<DSAssetUnlockTransactionEntity *> *)fetchRequest;

@property (nonatomic, assign) uint64_t index;
@property (nonatomic, assign) uint32_t fee;
@property (nonatomic, assign) uint32_t requestedHeight;
@property (nullable, nonatomic, retain) NSData *quorumHash;
@property (nullable, nonatomic, retain) NSData *quorumSignature;

@end

NS_ASSUME_NONNULL_END
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//
// Created by Vladimir Pirogov
// Copyright © 2024 Dash Core Group. All rights reserved.
//
// Licensed under the MIT License (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://opensource.org/licenses/MIT
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

#import "DSAssetUnlockTransactionEntity+CoreDataProperties.h"

@implementation DSAssetUnlockTransactionEntity (CoreDataProperties)

+ (NSFetchRequest<DSAssetUnlockTransactionEntity *> *)fetchRequest {
return [NSFetchRequest fetchRequestWithEntityName:@"DSAssetUnlockTransactionEntity"];
}

@dynamic index;
@dynamic fee;
@dynamic requestedHeight;
@dynamic quorumHash;
@dynamic quorumSignature;

@end
8 changes: 4 additions & 4 deletions DashSync/shared/Models/Masternode/DSMasternodeListService.m
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ - (void)removeFromRetrievalQueue:(NSData *)masternodeBlockHashData {
double count = self.retrievalQueue.count;
@synchronized (self.chain.chainManager.syncState) {
self.chain.chainManager.syncState.masternodeListSyncInfo.retrievalQueueCount = count;
self.chain.chainManager.syncState.masternodeListSyncInfo.retrievalQueueMaxAmount = self.retrievalQueueMaxAmount;
self.chain.chainManager.syncState.masternodeListSyncInfo.retrievalQueueMaxAmount = (uint32_t) self.retrievalQueueMaxAmount;
DSLog(@"[%@] Masternode list queue updated: %f/%lu", self.chain.name, count, self.retrievalQueueMaxAmount);
[self.chain.chainManager notifySyncStateChanged];
}
Expand All @@ -275,7 +275,7 @@ - (void)cleanListsRetrievalQueue {
[self.retrievalQueue removeAllObjects];
@synchronized (self.chain.chainManager.syncState) {
self.chain.chainManager.syncState.masternodeListSyncInfo.retrievalQueueCount = 0;
self.chain.chainManager.syncState.masternodeListSyncInfo.retrievalQueueMaxAmount = self.retrievalQueueMaxAmount;
self.chain.chainManager.syncState.masternodeListSyncInfo.retrievalQueueMaxAmount = (uint32_t) self.retrievalQueueMaxAmount;
DSLog(@"[%@] Masternode list queue cleaned up: 0/%lu", self.chain.name, self.retrievalQueueMaxAmount);
[self.chain.chainManager notifySyncStateChanged];
}
Expand All @@ -302,8 +302,8 @@ - (void)updateMasternodeRetrievalQueue {
return [self.store heightForBlockHash:obj1.UInt256] < [self.store heightForBlockHash:obj2.UInt256] ? NSOrderedAscending : NSOrderedDescending;
}];
@synchronized (self.chain.chainManager.syncState) {
self.chain.chainManager.syncState.masternodeListSyncInfo.retrievalQueueCount = currentCount;
self.chain.chainManager.syncState.masternodeListSyncInfo.retrievalQueueMaxAmount = self.retrievalQueueMaxAmount;
self.chain.chainManager.syncState.masternodeListSyncInfo.retrievalQueueCount = (uint32_t) currentCount;
self.chain.chainManager.syncState.masternodeListSyncInfo.retrievalQueueMaxAmount = (uint32_t) self.retrievalQueueMaxAmount;
DSLog(@"[%@] Masternode list queue updated: %lu/%lu", self.chain.name, currentCount, self.retrievalQueueMaxAmount);
[self.chain.chainManager notifySyncStateChanged];
}
Expand Down
2 changes: 1 addition & 1 deletion DashSync/shared/Models/Notifications/DSSyncState.m
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ - (id)copyWithZone:(NSZone *)zone {
return copy;
}
- (NSString *)description {
return [NSString stringWithFormat:@"%u/%u/%u/%u",
return [NSString stringWithFormat:@"%u/%u/%f/%u",
self.retrievalQueueCount,
self.retrievalQueueMaxAmount,
self.storedCount,
Expand Down
Loading
Loading