This repository has been archived by the owner on Oct 28, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #77 from horizontalsystems/peer_group_refactoring
Peer group refactoring
- Loading branch information
Showing
20 changed files
with
793 additions
and
136 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
class BlockHelper { | ||
private let storage: ISpvStorage | ||
private let network: INetwork | ||
|
||
init(storage: ISpvStorage, network: INetwork) { | ||
self.storage = storage | ||
self.network = network | ||
} | ||
|
||
} | ||
|
||
extension BlockHelper: IBlockHelper { | ||
|
||
var lastBlockHeader: BlockHeader { | ||
return storage.lastBlockHeader ?? network.checkpointBlock | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
class BlockValidator { | ||
|
||
func validate(blockHeaders: [BlockHeader], from blockHeader: BlockHeader) throws { | ||
guard let firstBlockHeader = blockHeaders.first else { | ||
throw ValidationError.invalidChain | ||
} | ||
|
||
guard firstBlockHeader.hashHex == blockHeader.hashHex else { | ||
throw ValidationError.forkDetected | ||
} | ||
|
||
var previousHeader = blockHeader | ||
|
||
for blockHeader in blockHeaders.dropFirst() { | ||
guard blockHeader.parentHash == previousHeader.hashHex else { | ||
throw ValidationError.invalidChain | ||
} | ||
previousHeader = blockHeader | ||
} | ||
} | ||
|
||
} | ||
|
||
extension BlockValidator { | ||
|
||
enum ValidationError: Error { | ||
case forkDetected | ||
case invalidChain | ||
case invalidProofOfWork | ||
} | ||
|
||
} |
Oops, something went wrong.