-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor LastBlockDownloader to LastBlockSource and implement singlet…
…on pattern
- Loading branch information
1 parent
cb4bfe6
commit 6b2259d
Showing
7 changed files
with
73 additions
and
19 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
src/DownloaderV2/Builders/DocumentBuilder/AbstractDocument.cs
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 @@ | ||
using Newtonsoft.Json.Linq; | ||
using DownloaderV2.Models.Covalent; | ||
|
||
namespace DownloaderV2.Builders.DocumentBuilder; | ||
|
||
public abstract class AbstractDocument(long savedLastBlock, long sourceLastBlock) | ||
{ | ||
public abstract string UrlSet { get; } | ||
public abstract string GetUrl { get; } | ||
public long SavedLastBlock { get; set; } = savedLastBlock; | ||
public long SourceLastBlock { get; set; } = sourceLastBlock; | ||
|
||
public abstract Task<InputData> FetchDataAsync(); | ||
|
||
protected abstract JToken? SendRequest(string url); | ||
|
||
protected abstract InputData DeserializeResponse(JToken responseData); | ||
} |
10 changes: 0 additions & 10 deletions
10
src/DownloaderV2/Builders/LastBlockBuilder/LastBlockDownloader.cs
This file was deleted.
Oops, something went wrong.
24 changes: 24 additions & 0 deletions
24
src/DownloaderV2/Builders/LastBlockBuilder/LastBlockSource.cs
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,24 @@ | ||
using DownloaderV2.Builders.LastBlockBuilder.SourcePage; | ||
|
||
namespace DownloaderV2.Builders.LastBlockBuilder; | ||
|
||
public class LastBlockSource | ||
{ | ||
private static LastBlockSource? _instance; | ||
private static readonly object Lock = new object(); | ||
private Task<Dictionary<long, long>>? _lastBlockDictionary; | ||
private readonly GetSourcePage _getLastBlock; | ||
|
||
private LastBlockSource(GetSourcePage getLastBlock) => _getLastBlock = getLastBlock; | ||
|
||
public static LastBlockSource GetInstance(GetSourcePage getLastBlock) | ||
{ | ||
lock (Lock) | ||
{ | ||
_instance ??= new LastBlockSource(getLastBlock); | ||
} | ||
return _instance; | ||
} | ||
|
||
public Task<Dictionary<long, long>> LastBlockDictionary => _lastBlockDictionary ??= _getLastBlock.FetchDataAsync(); | ||
} |
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