Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
sondreb committed Jul 6, 2022
2 parents 6caf0c2 + cc00145 commit 0a54cdf
Show file tree
Hide file tree
Showing 84 changed files with 1,386 additions and 684 deletions.
33 changes: 32 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,35 @@
## <small>0.2.33 (2022-05-10)</small>
## <small>0.2.37 (2022-07-05)</small>

* Added missing binding for block rewind (#154) ([aaa1358](https://github.com/block-core/blockcore-indexer/commit/aaa1358)), closes [#154](https://github.com/block-core/blockcore-indexer/issues/154)



## <small>0.2.36 (2022-07-04)</small>

* Changed smart contracts to be seperate token and contract (#153) ([312c206](https://github.com/block-core/blockcore-indexer/commit/312c206)), closes [#153](https://github.com/block-core/blockcore-indexer/issues/153)
* Updated version ([0acf070](https://github.com/block-core/blockcore-indexer/commit/0acf070))
* Updated version ([f62dc87](https://github.com/block-core/blockcore-indexer/commit/f62dc87))



## <small>0.2.35 (2022-06-24)</small>

* Added caching for stats endpoint (#150) ([719f891](https://github.com/block-core/blockcore-indexer/commit/719f891)), closes [#150](https://github.com/block-core/blockcore-indexer/issues/150)
* Return confirmation count on block header (#148) ([82f5660](https://github.com/block-core/blockcore-indexer/commit/82f5660)), closes [#148](https://github.com/block-core/blockcore-indexer/issues/148)
* Update Swashbuckle package (#152) ([7e65edf](https://github.com/block-core/blockcore-indexer/commit/7e65edf)), closes [#152](https://github.com/block-core/blockcore-indexer/issues/152)



## <small>0.2.34 (2022-05-28)</small>

* change background-image in index.html (#145) ([2c7557b](https://github.com/block-core/blockcore-indexer/commit/2c7557b)), closes [#145](https://github.com/block-core/blockcore-indexer/issues/145)
* Fixed typo to fit the Cirrus on release 1.1.44 (#146) ([501bee2](https://github.com/block-core/blockcore-indexer/commit/501bee2)), closes [#146](https://github.com/block-core/blockcore-indexer/issues/146)
* Update version and changelog ([4c4a597](https://github.com/block-core/blockcore-indexer/commit/4c4a597))
* Updated change log ([83f67f3](https://github.com/block-core/blockcore-indexer/commit/83f67f3))



## <small>0.2.33 (2022-05-04)</small>

* Add trx index to trx api (#139) ([f906d1e](https://github.com/block-core/blockcore-indexer/commit/f906d1e)), closes [#139](https://github.com/block-core/blockcore-indexer/issues/139)
* Added NFT and asstets enpoints (#142) ([37601f8](https://github.com/block-core/blockcore-indexer/commit/37601f8)), closes [#142](https://github.com/block-core/blockcore-indexer/issues/142)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "blockcoreindexer",
"version": "0.2.34",
"version": "0.2.37",
"license": "MIT",
"author": {
"name": "Blockcore",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ public class CirrusMongoDbMock : MongodbMock
public Mock<IMongoQueryable<CirrusContractTable>> CirrusContractTableQuariable;
public Mock<IMongoCollection<CirrusContractCodeTable>> CirrusContractCodeTableCollection;
public Mock<IMongoQueryable<CirrusContractCodeTable>> CirrusContractCodeTableQuariable;
public Mock<IMongoCollection<DaoContractComputedTable>> DaoContractComputedTableCollection;
public Mock<IMongoQueryable<DaoContractComputedTable>> DaoContractComputedTableQuariable;
public Mock<IMongoCollection<DaoContractTable>> DaoContractComputedTableCollection;
public Mock<IMongoQueryable<DaoContractTable>> DaoContractComputedTableQuariable;

private Mock<ICirrusMongoDb> cirrusDb;

Expand All @@ -25,15 +25,15 @@ public CirrusMongoDbMock()
CirrusContractTableCollection = new Mock<IMongoCollection<CirrusContractTable>>();
CirrusContractTableQuariable = new Mock<IMongoQueryable<CirrusContractTable>>();
CirrusContractCodeTableCollection = new Mock<IMongoCollection<CirrusContractCodeTable>>();
DaoContractComputedTableCollection = new Mock<IMongoCollection<DaoContractComputedTable>>();
DaoContractComputedTableCollection = new Mock<IMongoCollection<DaoContractTable>>();

cirrusDb = new Mock<ICirrusMongoDb>();

cirrusDb.Setup(_ => _.CirrusContractTable).Returns(CirrusContractTableCollection.Object);
cirrusDb.Setup(_ => _.CirrusContractCodeTable).Returns(CirrusContractCodeTableCollection.Object);
cirrusDb.Setup(_ => _.DaoContractComputedTable).Returns(DaoContractComputedTableCollection.Object);
cirrusDb.Setup(_ => _.DaoContractTable).Returns(DaoContractComputedTableCollection.Object);

cirrusDb.Setup(_ => _.DaoContractComputedTable.Database)
cirrusDb.Setup(_ => _.DaoContractTable.Database)
.Returns(MongoDatabaseObject);

DaoContractComputedTableCollection.Setup(_ => _.Settings)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace Blockcore.Indexer.Cirrus.Tests.Storage.Mongo;

public class ComputeSmartContractServiceTests
{
ComputeSmartContractService<DaoContractComputedTable> sut;
ComputeSmartContractServiceWithSplitDocuments<DaoContractTable,DaoContractProposalTable> sut;

CirrusMongoDbMock mongoDbMock;

Expand Down Expand Up @@ -60,17 +60,14 @@ public ComputeSmartContractServiceTests()
chainSetting.Object, networkSettings.Object);


sut = new ComputeSmartContractService<DaoContractComputedTable>(null, mongoDbMock.CirrusMongoDbObject,
new Mock<ISmartContractHandlersFactory<DaoContractComputedTable>>().Object, new Mock<ICryptoClientFactory>().Object, syncConnection,
Mock.Of<IMongoDatabase>());
sut = new ComputeSmartContractServiceWithSplitDocuments<DaoContractTable, DaoContractProposalTable>(null, mongoDbMock.CirrusMongoDbObject,
new Mock<ISmartContractHandlersFactory<DaoContractTable,DaoContractProposalTable>>().Object, new Mock<ICryptoClientFactory>().Object, syncConnection,
Mock.Of<IMongoDatabase>(), new Mock<ISmartContractTransactionsLookup<DaoContractTable>>().Object);
}

//[Fact]
public async Task WhenTheContractIsNotFountAnTheTrandactionIsNotFoundReturnsNull()
{
var result = await sut.ComputeSmartContractForAddressAsync(Guid.NewGuid().ToString());


Assert.Null(result);
await sut.ComputeSmartContractForAddressAsync(Guid.NewGuid().ToString());
}
}
38 changes: 26 additions & 12 deletions src/Blockcore.Indexer.Cirrus/CirrusStartup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Blockcore.Indexer.Cirrus.Storage.Mongo.SmartContracts.Dao;
using Blockcore.Indexer.Cirrus.Storage.Mongo.SmartContracts.NonFungibleToken;
using Blockcore.Indexer.Cirrus.Storage.Mongo.Types;
using Blockcore.Indexer.Cirrus.Sync.SyncTasks;
using Blockcore.Indexer.Core;
using Blockcore.Indexer.Core.Client;
using Blockcore.Indexer.Core.Crypto;
Expand Down Expand Up @@ -63,25 +64,38 @@ public void ConfigureServices(IServiceCollection services)
.AddApplicationPart(typeof(Startup).Assembly)
.AddControllersAsServices();

services.AddTransient<IComputeSmartContractService<NonFungibleTokenComputedTable>,NftComputationService>();
services.AddTransient(typeof(IComputeSmartContractService<>),typeof(ComputeSmartContractService<>));
services.AddTransient(typeof(ISmartContractHandlersFactory<>),typeof(SmartContractHandlersFactory<>));
services.AddTransient<IComputeSmartContractService<DaoContractTable>,ComputeSmartContractServiceWithSplitDocuments<DaoContractTable,DaoContractProposalTable>>();
services.AddTransient<IComputeSmartContractService<StandardTokenContractTable>,ComputeSmartContractServiceWithSplitDocuments<StandardTokenContractTable,StandardTokenHolderTable>>();
services.AddTransient<IComputeSmartContractService<NonFungibleTokenContractTable>,ComputeSmartContractServiceWithSplitDocuments<NonFungibleTokenContractTable,NonFungibleTokenTable>>();

ScanAssemblyAndRegisterTypeByNameAsTransient(services, typeof(ILogReader<DaoContractComputedTable>),
typeof(ILogReader<>).Assembly);
ScanAssemblyAndRegisterTypeByNameAsTransient(services, typeof(ILogReader<StandardTokenComputedTable>),
typeof(ILogReader<>).Assembly);
ScanAssemblyAndRegisterTypeByNameAsTransient(services, typeof(ILogReader<NonFungibleTokenComputedTable>),
typeof(ILogReader<>).Assembly);
services.AddTransient<ISmartContractTransactionsLookup<NonFungibleTokenContractTable>,NonFungibleTokenSmartContractTransactionsLookup>();
services.AddTransient(typeof(ISmartContractTransactionsLookup<>), typeof(SmartContractTransactionsLookup<>));



ScanAssemblyAndRegisterTypeByNameAsTransient(services, typeof(ILogReader<DaoContractTable,DaoContractProposalTable>),
typeof(ILogReader<DaoContractTable,DaoContractProposalTable>).Assembly);
ScanAssemblyAndRegisterTypeByNameAsTransient(services, typeof(ILogReader<StandardTokenContractTable,StandardTokenHolderTable>),
typeof(ILogReader<StandardTokenContractTable,StandardTokenHolderTable>).Assembly);
ScanAssemblyAndRegisterTypeByNameAsTransient(services, typeof(ILogReader<NonFungibleTokenContractTable,NonFungibleTokenTable>),
typeof(ILogReader<NonFungibleTokenContractTable,NonFungibleTokenTable>).Assembly);

services.AddTransient<ISmartContractHandlersFactory<DaoContractTable,DaoContractProposalTable>,SmartContractHandlersFactory<DaoContractTable,DaoContractProposalTable>>();
services.AddTransient<ISmartContractHandlersFactory<StandardTokenContractTable,StandardTokenHolderTable>,SmartContractHandlersFactory<StandardTokenContractTable,StandardTokenHolderTable>>();
services.AddTransient<ISmartContractHandlersFactory<NonFungibleTokenContractTable,NonFungibleTokenTable>,SmartContractHandlersFactory<NonFungibleTokenContractTable,NonFungibleTokenTable>>();

RegisterSmartContractBuilder(services); //No need to scan the assembly as there won't be that many

services.AddScoped<TaskRunner,SmartContractSyncRunner>();

services.AddTransient<IBlockRewindOperation, CirrusBlockRewindOperation>();
}

private static IServiceCollection RegisterSmartContractBuilder(IServiceCollection collection)
{
collection.AddTransient<ISmartContractBuilder<DaoContractComputedTable>, DaoSmartContractBuilder>();
collection.AddTransient<ISmartContractBuilder<StandardTokenComputedTable>, StandardTokenSmartContractBuilder>();
collection.AddTransient<ISmartContractBuilder<NonFungibleTokenComputedTable>, NonFungibleTokenSmartContractBuilder>();
collection.AddTransient<ISmartContractBuilder<DaoContractTable>, DaoSmartContractBuilder>();
collection.AddTransient<ISmartContractBuilder<StandardTokenContractTable>, StandardTokenSmartContractBuilder>();
collection.AddTransient<ISmartContractBuilder<NonFungibleTokenContractTable>, NonFungibleTokenSmartContractBuilder>();
return collection;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,7 @@ public class ContractReceiptResponse : ReceiptResponse
public ulong GasPrice { get; set; }
public ulong Amount { get; set; }
public ulong ContractBalance { get; set; }

public Dictionary<string, object> ContractData { get; set; }
}
}
35 changes: 19 additions & 16 deletions src/Blockcore.Indexer.Cirrus/Controllers/CirrusQueryController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ public class CirrusQueryController : Controller
{
private readonly IPagingHelper paging;
private readonly ICirrusStorage cirrusMongoData;
readonly IComputeSmartContractService<DaoContractComputedTable> daoContractService;
readonly IComputeSmartContractService<StandardTokenComputedTable> standardTokenService;
readonly IComputeSmartContractService<NonFungibleTokenComputedTable> nonFungibleTokenService;
readonly IComputeSmartContractService<DaoContractTable> daoContractService;
readonly IComputeSmartContractService<StandardTokenContractTable> standardTokenService;
readonly IComputeSmartContractService<NonFungibleTokenContractTable> nonFungibleTokenService;

/// <summary>
/// Initializes a new instance of the <see cref="QueryController"/> class.
/// </summary>
public CirrusQueryController(IPagingHelper paging,
IComputeSmartContractService<DaoContractComputedTable> daoContractAggregator, ICirrusStorage cirrusMongoData, IComputeSmartContractService<StandardTokenComputedTable> standardTokenService, IComputeSmartContractService<NonFungibleTokenComputedTable> nonFungibleTokenService)
IComputeSmartContractService<DaoContractTable> daoContractAggregator, ICirrusStorage cirrusMongoData, IComputeSmartContractService<StandardTokenContractTable> standardTokenService, IComputeSmartContractService<NonFungibleTokenContractTable> nonFungibleTokenService)
{
this.paging = paging;
daoContractService = daoContractAggregator;
Expand All @@ -52,10 +52,17 @@ public IActionResult GetContracts([MinLength(2)][MaxLength(100)] string contract
}

[HttpGet]
[Route("{address}/assets")]
public IActionResult GetAddressAssets([MinLength(30)][MaxLength(100)] string address, [Range(0, long.MaxValue)] int? offset = 0, [Range(1, 50)] int limit = 10)
[Route("collectables/{ownerAddress}")]
public IActionResult GetAddressAssets([MinLength(30)][MaxLength(100)] string ownerAddress, [Range(0, long.MaxValue)] int? offset = 0, [Range(1, 50)] int limit = 10)
{
return Ok(cirrusMongoData.GetAssetsForAddressAsync(address,offset,limit).Result);
return Ok(cirrusMongoData.GetNonFungibleTokensForAddressAsync(ownerAddress,offset,limit).Result);
}

[HttpGet]
[Route("tokens/{ownerAddress}")]
public IActionResult GettokensForAddress([MinLength(30)][MaxLength(100)] string ownerAddress, [Range(0, long.MaxValue)] int? offset = 0, [Range(1, 50)] int limit = 10)
{
return Ok(cirrusMongoData.GetStandardTokensForAddressAsync(ownerAddress,offset,limit).Result);
}

[HttpGet]
Expand Down Expand Up @@ -98,7 +105,7 @@ public IActionResult GetContractCode([MinLength(30)][MaxLength(100)] string addr
[SlowRequestsFilteerAttribute]
public async Task<IActionResult> GetDaoContractByAddress([MinLength(30)][MaxLength(100)] string address)
{
var contract = await daoContractService.ComputeSmartContractForAddressAsync(address);
var contract = await cirrusMongoData.GetDaoContractByAddressAsync(address);

if (contract is null)
{
Expand All @@ -113,7 +120,7 @@ public async Task<IActionResult> GetDaoContractByAddress([MinLength(30)][MaxLeng
[SlowRequestsFilteerAttribute]
public async Task<IActionResult> GetStandardTokenContractByAddress([MinLength(30)][MaxLength(100)] string address)
{
var contract = await standardTokenService.ComputeSmartContractForAddressAsync(address);
var contract = await cirrusMongoData.GetStandardTokenContractByAddressAsync(address);

if (contract is null)
{
Expand All @@ -128,15 +135,13 @@ public async Task<IActionResult> GetStandardTokenContractByAddress([MinLength(30
[SlowRequestsFilteerAttribute]
public async Task<IActionResult> GetStandardTokenContractByAddress([MinLength(30)][MaxLength(100)] string address, [MinLength(30)][MaxLength(100)] string filterAddress)
{
var contract = await standardTokenService.ComputeSmartContractForAddressAsync(address);
var contract = await cirrusMongoData.GetStandardTokenByIdAsync(address, filterAddress);

if (contract is null)
{
return NotFound();
}

contract.TokenHolders = contract.TokenHolders.Where(t => t.Address == filterAddress).ToList();

return Ok(contract);
}

Expand All @@ -145,7 +150,7 @@ public async Task<IActionResult> GetStandardTokenContractByAddress([MinLength(30
[SlowRequestsFilteerAttribute]
public async Task<IActionResult> GetNonFungibleTokenContractByAddress([MinLength(30)][MaxLength(100)] string address)
{
var contract = await nonFungibleTokenService.ComputeSmartContractForAddressAsync(address);
var contract = await cirrusMongoData.GetNonFungibleTokenContractByAddressAsync(address);

if (contract is null)
{
Expand All @@ -161,9 +166,7 @@ public async Task<IActionResult> GetNonFungibleTokenContractByAddress([MinLength
public async Task<IActionResult> GetNonFungibleTokenById([MinLength(30)][MaxLength(100)] string address,
[MinLength(1)][MaxLength(100)] string id)
{
var contract = await nonFungibleTokenService.ComputeSmartContractForAddressAsync(address);

var token = contract.Tokens.FirstOrDefault(_ => _.Id == id);
var token = await cirrusMongoData.GetNonFungibleTokenByIdAsync(address, id);

if (token is null)
{
Expand Down
16 changes: 16 additions & 0 deletions src/Blockcore.Indexer.Cirrus/Models/QueryDAOContract.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System.Collections.Generic;
using Blockcore.Indexer.Cirrus.Storage.Mongo.Types;

namespace Blockcore.Indexer.Cirrus.Models;

public class QueryDAOContract
{
public long CurrentAmount { get; set; }
public long MaxVotingDuration { get; set; }
public long MinVotingDuration { get; set; }
public long WhitelistedCount { get; set; }
public List<DaoContractDeposit> Deposits { get; set; }
public List<DaoContractProposalTable> Proposals { get; set; }
public List<string> ApprovedAddresses { get; set; }

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System.Collections.Generic;
using Blockcore.Indexer.Cirrus.Storage.Mongo.Types;

namespace Blockcore.Indexer.Cirrus.Models;

public class QueryNonFungibleTokenContract
{
public string Name { get; set; }
public string Symbol { get; set; }
public string Owner { get; set; }
public bool OwnerOnlyMinting { get; set; }
public string PendingOwner { get; set; }
public List<string> PreviousOwners { get; set; }
public List<NonFungibleTokenTable> Tokens { get; set; }
}
12 changes: 12 additions & 0 deletions src/Blockcore.Indexer.Cirrus/Models/QueryStandardToken.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace Blockcore.Indexer.Cirrus.Models;

public class QueryStandardToken
{
public string Name { get; set; }

public string Symbol { get; set; }

public long TotalSupply { get; set; }
public string Address { get; set; }
public long Amount { get; set; }
}
18 changes: 18 additions & 0 deletions src/Blockcore.Indexer.Cirrus/Models/QueryStandardTokenContract.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System.Collections.Generic;
using Blockcore.Indexer.Cirrus.Storage.Mongo.Types;

namespace Blockcore.Indexer.Cirrus.Models;

public class QueryStandardTokenContract
{
public string Name { get; set; }

public string Symbol { get; set; }

public long TotalSupply { get; set; }

public long Decimals { get; set; }
public long CreatedOnBlock { get; set; }
public string CreatorAddress { get; set; }
public List<StandardTokenHolderTable> tokens { get; set; }
}
11 changes: 10 additions & 1 deletion src/Blockcore.Indexer.Cirrus/Storage/ICirrusStorage.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using Blockcore.Indexer.Cirrus.Models;
using Blockcore.Indexer.Cirrus.Storage.Mongo.Types;
using Blockcore.Indexer.Core.Storage.Types;

namespace Blockcore.Indexer.Cirrus.Storage;
Expand All @@ -13,5 +15,12 @@ public interface ICirrusStorage
QueryResult<QueryContractGroup> GroupedContracts();
QueryResult<QueryContractList> ListContracts(string contractType, int? offset, int limit);

Task<QueryResult<QueryAddressAsset>> GetAssetsForAddressAsync(string address, int? offset, int limit);
Task<QueryDAOContract> GetDaoContractByAddressAsync(string contractAddress);
Task<QueryStandardTokenContract> GetStandardTokenContractByAddressAsync(string contractAddress);
Task<QueryNonFungibleTokenContract> GetNonFungibleTokenContractByAddressAsync(string contractAddress);
Task<NonFungibleTokenTable> GetNonFungibleTokenByIdAsync(string contractAddress, string tokenId);
Task<QueryStandardToken> GetStandardTokenByIdAsync(string contractAddress, string tokenId);
Task<QueryResult<QueryAddressAsset>> GetNonFungibleTokensForAddressAsync(string address, int? offset, int limit);
Task<QueryResult<QueryStandardToken>> GetStandardTokensForAddressAsync(string address, int? offset, int limit);
Task<List<string>> GetSmartContractsThatNeedsUpdatingAsync(params string[] supportedTypes);
}
Loading

0 comments on commit 0a54cdf

Please sign in to comment.