|
1 | | -// Copyright (C) 2017-2025 Ixian |
| 1 | +// Copyright (C) 2017-2026 Ixian |
2 | 2 | // This file is part of Ixian Core - www.github.com/ixian-platform/Ixian-Core |
3 | 3 | // |
4 | 4 | // Ixian Core is free software: you can redistribute it and/or modify |
@@ -463,5 +463,46 @@ public IEnumerable<SignerPowSolution> GetSolutions(ulong fromBlockHeight, ulong |
463 | 463 | { |
464 | 464 | return GetSolutions(fromBlockHeight, toBlockHeight).OrderByDescending(x => x.difficulty).FirstOrDefault(); |
465 | 465 | } |
| 466 | + |
| 467 | + public (byte[] challenge, IxiNumber minDifficulty, ulong blockHeight) GetChallenge() |
| 468 | + { |
| 469 | + if (currentBlockHeight == 0) |
| 470 | + { |
| 471 | + return (null, 0, 0); |
| 472 | + } |
| 473 | + |
| 474 | + var lastSolution = solutions.Values.OrderByDescending(x => x.blockNum).FirstOrDefault(); |
| 475 | + if (lastSolution != null) |
| 476 | + { |
| 477 | + return (PrepareChallenge(lastSolution.blockNum, IxianHandler.getBlockHash(lastSolution.blockNum), lastSolution.keyPair, Array.Empty<byte>()), solvingDifficulty, lastSolution.blockNum); |
| 478 | + } |
| 479 | + return (null, 0, 0); |
| 480 | + } |
| 481 | + |
| 482 | + public IxiNumber ProcessExternalSolution(ulong blockHeight, byte[] nonce) |
| 483 | + { |
| 484 | + if (nonce == null || nonce.Length <= 1) |
| 485 | + { |
| 486 | + return 0; |
| 487 | + } |
| 488 | + |
| 489 | + if (!solutions.TryGetValue(blockHeight, out var solution)) |
| 490 | + { |
| 491 | + return 0; |
| 492 | + } |
| 493 | + |
| 494 | + byte[] challengeWithNonce = PrepareChallenge(blockHeight, IxianHandler.getBlockHash(blockHeight), solution.keyPair, nonce); |
| 495 | + byte[] hash = CryptoManager.lib.sha3_512sq(challengeWithNonce); |
| 496 | + var status = ProcessSolution(hash, challengeWithNonce, nonce.Length, solvingDifficulty, solution.blockNum, solution.keyPair); |
| 497 | + |
| 498 | + if (status.solution != null |
| 499 | + && blockHeight > lastFoundBlockHeight) |
| 500 | + { |
| 501 | + lastFoundBlockHeight = blockHeight; |
| 502 | + } |
| 503 | + |
| 504 | + return status.difficulty; |
| 505 | + } |
| 506 | + |
466 | 507 | } |
467 | 508 | } |
0 commit comments