forked from CityOfZion/neo-sharp
-
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.
IBlockchain dependency removed from some of the MessageHandlers
- Loading branch information
1 parent
49d6244
commit f4ec481
Showing
20 changed files
with
1,054 additions
and
582 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using NeoSharp.Core.Models; | ||
using NeoSharp.Core.Persistence; | ||
using NeoSharp.Core.Types; | ||
|
||
namespace NeoSharp.Core.Blockchain | ||
{ | ||
public class AssetModel : IAssetModel | ||
{ | ||
#region Private Fields | ||
private readonly IRepository _repository; | ||
#endregion | ||
|
||
#region Constructor | ||
public AssetModel(IRepository repository) | ||
{ | ||
this._repository = repository; | ||
} | ||
#endregion | ||
|
||
#region IAssetModel implementation | ||
|
||
/// <inheritdoc /> | ||
public Task<Asset> GetAsset(UInt256 hash) | ||
{ | ||
return this._repository.GetAsset(hash); | ||
} | ||
|
||
/// <inheritdoc /> | ||
public Task<IEnumerable<Asset>> GetAssets() | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
#endregion | ||
} | ||
} |
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,133 @@ | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using NeoSharp.Core.Models; | ||
using NeoSharp.Core.Persistence; | ||
using NeoSharp.Core.Types; | ||
using Org.BouncyCastle.Crypto.Digests; | ||
|
||
namespace NeoSharp.Core.Blockchain | ||
{ | ||
public class BlockModel : IBlockModel | ||
{ | ||
#region Private Fields | ||
private readonly IRepository _repository; | ||
private readonly ITransactionModel _transactionModel; | ||
#endregion | ||
|
||
#region Constructor | ||
public BlockModel(IRepository repository, ITransactionModel transactionModel) | ||
{ | ||
this._repository = repository; | ||
_transactionModel = transactionModel; | ||
} | ||
#endregion | ||
|
||
#region IBlocksModel implementation | ||
/// <inheritdoc /> | ||
public async Task<Block> GetBlock(uint height) | ||
{ | ||
var hash = await this.GetBlockHash(height); | ||
|
||
return hash == null ? null : await GetBlock(hash); | ||
} | ||
|
||
/// <inheritdoc /> | ||
public async Task<Block> GetBlock(UInt256 hash) | ||
{ | ||
var header = await this._repository.GetBlockHeader(hash); | ||
|
||
if (header == null || header.Type != HeaderType.Extended) return null; | ||
|
||
var transactions = new Transaction[header.TransactionCount]; | ||
|
||
for (int x = 0, m = header.TransactionCount; x < m; x++) | ||
{ | ||
transactions[x] = await this._transactionModel.GetTransaction(header.TransactionHashes[x]); | ||
} | ||
|
||
header.Hash = hash; | ||
|
||
return header.GetBlock(transactions); | ||
} | ||
|
||
/// <inheritdoc /> | ||
public async Task<IEnumerable<Block>> GetBlocks(IReadOnlyCollection<UInt256> blockHashes) | ||
{ | ||
var blocks = new List<Block>(); | ||
|
||
foreach (var hash in blockHashes) | ||
{ | ||
var block = await this.GetBlock(hash); | ||
|
||
if (block == null) continue; | ||
|
||
blocks.Add(block); | ||
} | ||
|
||
return blocks; | ||
} | ||
|
||
/// <inheritdoc /> | ||
public async Task<UInt256> GetBlockHash(uint height) | ||
{ | ||
return await this._repository.GetBlockHashFromHeight(height); | ||
} | ||
|
||
/// <inheritdoc /> | ||
public async Task<Block> GetNextBlock(UInt256 hash) | ||
{ | ||
var header = await this._repository.GetBlockHeader(hash); | ||
|
||
if (header != null) | ||
{ | ||
return await this.GetBlock(header.Index + 1); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
/// <inheritdoc /> | ||
public async Task<UInt256> GetNextBlockHash(UInt256 hash) | ||
{ | ||
var header = await this._repository.GetBlockHeader(hash); | ||
|
||
if (header != null) | ||
{ | ||
return await this._repository.GetBlockHashFromHeight(header.Index + 1); | ||
} | ||
|
||
return UInt256.Zero; | ||
} | ||
|
||
/// <inheritdoc /> | ||
public async Task<long> GetSysFeeAmount(uint height) | ||
{ | ||
return GetSysFeeAmount(await GetBlockHash(height)); | ||
} | ||
|
||
/// <inheritdoc /> | ||
public long GetSysFeeAmount(UInt256 hash) | ||
{ | ||
return 0; | ||
} | ||
|
||
/// <inheritdoc /> | ||
public async Task<BlockHeader> GetBlockHeader(uint height) | ||
{ | ||
var hash = await this._repository.GetBlockHashFromHeight(height); | ||
|
||
if (hash != null) return await this.GetBlockHeader(hash); | ||
return null; | ||
} | ||
|
||
/// <inheritdoc /> | ||
public async Task<BlockHeader> GetBlockHeader(UInt256 hash) | ||
{ | ||
var header = await this._repository.GetBlockHeader(hash); | ||
|
||
if (header != null) header.Hash = hash; | ||
return header; | ||
} | ||
#endregion | ||
} | ||
} |
Oops, something went wrong.