Skip to content

Commit

Permalink
Merge pull request #519 from dashpay/fix/evonode-track-reward-v19
Browse files Browse the repository at this point in the history
Fix/evonode track reward v19
  • Loading branch information
pankcuf authored Nov 14, 2023
2 parents d49baf9 + 5aaec2b commit ce0089c
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 26 deletions.
6 changes: 5 additions & 1 deletion DashSync/shared/Models/Chain/DSChain.m
Original file line number Diff line number Diff line change
Expand Up @@ -3249,6 +3249,7 @@ - (BOOL)transactionHasLocalReferences:(DSTransaction *)transaction {
if ([self walletHavingProviderOwnerAuthenticationHash:providerRegistrationTransaction.ownerKeyHash foundAtIndex:nil]) return TRUE;
if ([self walletHavingProviderVotingAuthenticationHash:providerRegistrationTransaction.votingKeyHash foundAtIndex:nil]) return TRUE;
if ([self walletHavingProviderOperatorAuthenticationKey:providerRegistrationTransaction.operatorKey foundAtIndex:nil]) return TRUE;
if ([self walletHavingPlatformNodeAuthenticationHash:providerRegistrationTransaction.platformNodeID foundAtIndex:nil]) return TRUE;
if ([self walletContainingMasternodeHoldingAddressForProviderRegistrationTransaction:providerRegistrationTransaction foundAtIndex:nil]) return TRUE;
if ([self accountContainingAddress:providerRegistrationTransaction.payoutAddress]) return TRUE;
} else if ([transaction isKindOfClass:[DSProviderUpdateServiceTransaction class]]) {
Expand Down Expand Up @@ -3287,7 +3288,10 @@ - (BOOL)transactionHasLocalReferences:(DSTransaction *)transaction {
- (void)triggerUpdatesForLocalReferences:(DSTransaction *)transaction {
if ([transaction isKindOfClass:[DSProviderRegistrationTransaction class]]) {
DSProviderRegistrationTransaction *providerRegistrationTransaction = (DSProviderRegistrationTransaction *)transaction;
if ([self walletHavingProviderOwnerAuthenticationHash:providerRegistrationTransaction.ownerKeyHash foundAtIndex:nil] || [self walletHavingProviderVotingAuthenticationHash:providerRegistrationTransaction.votingKeyHash foundAtIndex:nil] || [self walletHavingProviderOperatorAuthenticationKey:providerRegistrationTransaction.operatorKey foundAtIndex:nil]) {
if ([self walletHavingProviderOwnerAuthenticationHash:providerRegistrationTransaction.ownerKeyHash foundAtIndex:nil] ||
[self walletHavingProviderVotingAuthenticationHash:providerRegistrationTransaction.votingKeyHash foundAtIndex:nil] ||
[self walletHavingProviderOperatorAuthenticationKey:providerRegistrationTransaction.operatorKey foundAtIndex:nil] ||
[self walletHavingPlatformNodeAuthenticationHash:providerRegistrationTransaction.platformNodeID foundAtIndex:nil]) {
[self.chainManager.masternodeManager localMasternodeFromProviderRegistrationTransaction:providerRegistrationTransaction save:TRUE];
}
} else if ([transaction isKindOfClass:[DSProviderUpdateServiceTransaction class]]) {
Expand Down
2 changes: 1 addition & 1 deletion DashSync/shared/Models/Network/DSPeer.m
Original file line number Diff line number Diff line change
Expand Up @@ -1265,7 +1265,7 @@ - (void)acceptTxMessage:(NSData *)message {
#endif
#else
#if DEBUG
DSLogPrivate(@"%@:%u got tx (%lu): %@", self.host, self.port, tx.type, uint256_obj(tx.txHash));
DSLogPrivate(@"%@:%u got tx (%hu): %@", self.host, self.port, tx.type, uint256_obj(tx.txHash));
#else
DSLog(@"%@:%u got tx (%lu): %@", self.host, self.port, tx.type, @"<REDACTED>");
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ - (instancetype)initWithMessage:(NSData *)message onChain:(DSChain *)chain {
off += 96;
if (length - off < 8) return nil;
self.creditPoolBalance = [message Int64AtOffset:off];
off += len.unsignedIntegerValue;
off += 8;
}
}
self.coinbaseTransactionVersion = version;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,6 @@ - (instancetype)initWithMessage:(NSData *)message onChain:(DSChain *)chain {
self.operatorKey = [message UInt384AtOffset:off];
off += 48;

if ([self usesBasicBLS]) {
if (length - off < 2) return nil;
self.operatorKeyVersion = [message UInt16AtOffset:off];
off += 2;
}

if (length - off < 20) return nil;
self.votingKeyHash = [message UInt160AtOffset:off];
off += 20;
Expand All @@ -90,12 +84,12 @@ - (instancetype)initWithMessage:(NSData *)message onChain:(DSChain *)chain {
off += 32;

if ([self usesBasicBLS] && [self usesHPMN]) {
if (length - off < 32) return nil;
if (length - off < 20) return nil;
self.platformNodeID = [message UInt160AtOffset:off];
off += 32;
off += 20;
if (length - off < 2) return nil;
self.platformP2PPort = CFSwapInt16HostToBig([message UInt16AtOffset:off]);
off += 2;
off += 2;
if (length - off < 2) return nil;
self.platformHTTPPort = CFSwapInt16HostToBig([message UInt16AtOffset:off]);
off += 2;
Expand Down Expand Up @@ -206,6 +200,7 @@ - (NSData *)basePayloadData {
[data appendUInt128:self.ipAddress]; //212
[data appendUInt16:CFSwapInt16BigToHost(self.port)]; //228
[data appendUInt160:self.ownerKeyHash]; //388
// TODO: check case with legacy/non-legacy
[data appendUInt384:self.operatorKey]; //772
[data appendUInt160:self.votingKeyHash]; //788
[data appendUInt16:self.operatorReward]; //804
Expand Down Expand Up @@ -334,7 +329,7 @@ - (NSUInteger)masternodeOutputIndex {
}

- (BOOL)usesBasicBLS {
return self.version == 2;
return self.providerRegistrationTransactionVersion == 2;
}

- (BOOL)usesHPMN {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ - (NSData *)basePayloadData {
[data appendUInt16:self.providerUpdateRegistrarTransactionVersion];
[data appendUInt256:self.providerRegistrationTransactionHash];
[data appendUInt16:self.providerMode];
// TODO: check case with legacy/non-legacy
[data appendUInt384:self.operatorKey];
[data appendUInt160:self.votingKeyHash];
[data appendVarInt:self.scriptPayout.length];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ - (instancetype)initWithMessage:(NSData *)message onChain:(DSChain *)chain {
self.providerUpdateServiceTransactionVersion = [message UInt16AtOffset:off];
off += 2;

if (self.version == 2 /*BLS Basic*/) {
if ([self usesBasicBLS]) {
if (length - off < 2) return nil;
self.providerType = [message UInt16AtOffset:off];
off += 2;
Expand All @@ -70,10 +70,10 @@ - (instancetype)initWithMessage:(NSData *)message onChain:(DSChain *)chain {
self.inputsHash = [message UInt256AtOffset:off];
off += 32;

if (self.version == 2 /*BLS Basic*/ && self.providerType == 1 /*High Performance*/) {
if (length - off < 32) return nil;
if ([self usesBasicBLS] && [self usesHPMN]) {
if (length - off < 20) return nil;
self.platformNodeID = [message UInt160AtOffset:off];
off += 32;
off += 20;
if (length - off < 2) return nil;
self.platformP2PPort = CFSwapInt16HostToBig([message UInt16AtOffset:off]);
off += 2;
Expand Down Expand Up @@ -166,7 +166,7 @@ - (NSString *_Nullable)payoutAddress {
- (NSData *)basePayloadData {
NSMutableData *data = [NSMutableData data];
[data appendUInt16:self.providerUpdateServiceTransactionVersion];
if (self.version == 2 /*BLS Basic*/) {
if ([self usesBasicBLS]) {
[data appendUInt16:self.providerType];
}
[data appendUInt256:self.providerRegistrationTransactionHash];
Expand All @@ -175,7 +175,7 @@ - (NSData *)basePayloadData {
[data appendVarInt:self.scriptPayout.length];
[data appendData:self.scriptPayout];
[data appendUInt256:self.inputsHash];
if (self.version == 2 /*BLS Basic*/ && self.providerType == 1 /*High Performance*/) {
if ([self usesBasicBLS] && [self usesHPMN]) {
[data appendUInt160:self.platformNodeID];
[data appendUInt16:CFSwapInt16BigToHost(self.platformP2PPort)];
[data appendUInt16:CFSwapInt16BigToHost(self.platformHTTPPort)];
Expand Down Expand Up @@ -231,4 +231,12 @@ - (void)hasSetInputsAndOutputs {
[self updateInputsHash];
}

- (BOOL)usesBasicBLS {
return self.providerUpdateServiceTransactionVersion == 2;
}

- (BOOL)usesHPMN {
return self.providerType == 1;
}

@end
9 changes: 2 additions & 7 deletions Example/DashSync/DSWalletInputPhraseViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -49,24 +49,19 @@ - (IBAction)generateRandomPassphrase:(id)sender {


- (void)textViewDidChange:(UITextView *)textView {
if ([[DSBIP39Mnemonic sharedInstance] phraseIsValid:textView.text] || [textView.text isValidDashExtendedPublicKeyOnChain:self.chain]) {
self.saveButton.enabled = TRUE;
} else {
self.saveButton.enabled = FALSE;
}
self.saveButton.enabled = [[DSBIP39Mnemonic sharedInstance] phraseIsValid:textView.text] || [textView.text isValidDashExtendedPublicKeyOnChain:self.chain];
}

- (IBAction)createWallet:(id)sender {
if ([[DSBIP39Mnemonic sharedInstance] phraseIsValid:self.inputSeedPhraseTextView.text]) {
NSTimeInterval creationDate = [self.inputSeedPhraseTextView.text isEqualToString:self.randomPassphrase] ? [NSDate timeIntervalSince1970] : 0;
DSWallet *wallet = [DSWallet standardWalletWithSeedPhrase:self.inputSeedPhraseTextView.text setCreationDate:creationDate forChain:self.chain storeSeedPhrase:YES isTransient:NO];
[self.chain registerWallet:wallet];
[self.navigationController popViewControllerAnimated:TRUE];
} else if ([self.inputSeedPhraseTextView.text isValidDashExtendedPublicKeyOnChain:self.chain]) {
DSDerivationPath *derivationPath = [DSDerivationPath derivationPathWithSerializedExtendedPublicKey:self.inputSeedPhraseTextView.text onChain:self.chain];
[self.chain registerStandaloneDerivationPath:derivationPath];
[self.navigationController popViewControllerAnimated:TRUE];
}
[self.navigationController popViewControllerAnimated:TRUE];
}

@end
7 changes: 7 additions & 0 deletions Example/Tests/DSProviderTransactionsTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -424,5 +424,12 @@ - (void)testCollectionOperations {

}

- (void)testProRegTransactionMalformed {
DSChain *testnet = [DSChain testnet];
NSData *message = [NSData dataFromHexString:@"03000100019ecbf18dffb20ab5c6499b4b3aac3baa681b394cc9ffdbfcf0d7e105b9546737000000006a473044022054ad48d685d295bc25bceabe295136902233b5a58eb66592ae846a0c03c13c2502206f5c9ae6e26d889a39b671466fd647cbe44457c5d8b6adc66d70360c20dccff1012103ba9f974f2630f464d49385eb0a2946b3e1ddc0181a7704764f0182c1ff6f9efafeffffff015e2fb72d000000001976a91437602dadad1764d71349c4d7731957b1ac94586b88ac00000000fd2a0102000100000008ab76de940cf703fbe15c5aa392856d0e8efa3e2b2818ba9d5aa63c8f89ef1b0100000000000000000000000000ffff7284acd7270fc3bbc92e1e7a6625440a08a32b3b0beeb301041f87ea31e0e46c5c74d3978bd4243229b9d003f56294459115e2abc01da6da1072459ce6ffba23d5d79f1852472dcb505b6c8e9794ddf93656d611dea979cc1e04175c79b500001976a914a8b6c41585b4c74bd23f9525726e6a9573743fa388ac6120d06b781953c80cd8a1966cb6074a57519a5bd518d5a98d763cd4ad973d98285b1b5b1214011a0c0a6515adaa8e6422700fbb2068bb01411f01752dfecb1661282dd5732f177f21a6a31b1c13b5d1a9646b4ee40f97695fd7715f8286d9e6d1f7e56359681b4dc3b2d09d3e59117af902d8d195ae46d907fe"];
DSTransaction *tx = [DSTransactionFactory transactionWithMessage:message onChain:testnet];
XCTAssert(tx, @"Malformed TX");
}


@end

0 comments on commit ce0089c

Please sign in to comment.