From bbe77b09ee52a3d36afb07d743c17d177dc13d8d Mon Sep 17 00:00:00 2001
From: Dhruv Bhanushali <119250923+theDRB123@users.noreply.github.com>
Date: Mon, 17 Jun 2024 00:30:14 +0530
Subject: [PATCH 1/2] Added Database context and Postgres Types
---
CHANGELOG.md | 15 ++-
package.json | 2 +-
.../Blockcore.Indexer.Core.csproj | 3 +
src/Blockcore.Indexer.Core/Startup.cs | 10 +-
.../Storage/Postgres/PostgresDBContext.cs | 99 +++++++++++++++++++
.../Postgres/Types/AddressComputedTable.cs | 34 +++++++
.../Types/AddressHistoryComputedTable.cs | 23 +++++
.../Types/AddressUtxoComputedTable.cs | 17 ++++
.../Storage/Postgres/Types/Block.cs | 52 ++++++++++
.../Storage/Postgres/Types/Input.cs | 16 +++
.../Postgres/Types/MempoolTransaction.cs | 32 ++++++
.../Storage/Postgres/Types/Outpoint.cs | 14 +++
.../Storage/Postgres/Types/Output.cs | 16 +++
.../Storage/Postgres/Types/ReorgBlockTable.cs | 13 +++
.../Storage/Postgres/Types/RichlistTable.cs | 11 +++
.../Storage/Postgres/Types/Transaction.cs | 20 ++++
.../Storage/Postgres/Types/UnspentOutput.cs | 12 +++
src/Directory.Build.props | 2 +-
18 files changed, 387 insertions(+), 4 deletions(-)
create mode 100644 src/Blockcore.Indexer.Core/Storage/Postgres/PostgresDBContext.cs
create mode 100644 src/Blockcore.Indexer.Core/Storage/Postgres/Types/AddressComputedTable.cs
create mode 100644 src/Blockcore.Indexer.Core/Storage/Postgres/Types/AddressHistoryComputedTable.cs
create mode 100644 src/Blockcore.Indexer.Core/Storage/Postgres/Types/AddressUtxoComputedTable.cs
create mode 100644 src/Blockcore.Indexer.Core/Storage/Postgres/Types/Block.cs
create mode 100644 src/Blockcore.Indexer.Core/Storage/Postgres/Types/Input.cs
create mode 100644 src/Blockcore.Indexer.Core/Storage/Postgres/Types/MempoolTransaction.cs
create mode 100644 src/Blockcore.Indexer.Core/Storage/Postgres/Types/Outpoint.cs
create mode 100644 src/Blockcore.Indexer.Core/Storage/Postgres/Types/Output.cs
create mode 100644 src/Blockcore.Indexer.Core/Storage/Postgres/Types/ReorgBlockTable.cs
create mode 100644 src/Blockcore.Indexer.Core/Storage/Postgres/Types/RichlistTable.cs
create mode 100644 src/Blockcore.Indexer.Core/Storage/Postgres/Types/Transaction.cs
create mode 100644 src/Blockcore.Indexer.Core/Storage/Postgres/Types/UnspentOutput.cs
diff --git a/CHANGELOG.md b/CHANGELOG.md
index dc02524..7646863 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,10 +1,23 @@
+## 0.2.66 (2024-05-24)
+
+* Add mainnet key ([1ed7da0](https://github.com/block-core/blockcore-indexer/commit/1ed7da0))
+* bump version ([c2ed435](https://github.com/block-core/blockcore-indexer/commit/c2ed435))
+* update mainnet key ([c6a1054](https://github.com/block-core/blockcore-indexer/commit/c6a1054))
+
+
+
## 0.2.65 (2024-05-01)
* bump version ([c2e047e](https://github.com/block-core/blockcore-indexer/commit/c2e047e))
+* Fix typo ([d6a73b9](https://github.com/block-core/blockcore-indexer/commit/d6a73b9))
+
+
+
+## 0.2.64 (2024-04-26)
+
* bump version ([04665ca](https://github.com/block-core/blockcore-indexer/commit/04665ca))
* Changed base image to dotnet 8 (#211) ([37d0fb4](https://github.com/block-core/blockcore-indexer/commit/37d0fb4)), closes [#211](https://github.com/block-core/blockcore-indexer/issues/211)
* fix the default null ([2df38ab](https://github.com/block-core/blockcore-indexer/commit/2df38ab))
-* Fix typo ([d6a73b9](https://github.com/block-core/blockcore-indexer/commit/d6a73b9))
diff --git a/package.json b/package.json
index 04cdc66..c890313 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "blockcoreindexer",
- "version": "0.2.66",
+ "version": "0.2.67",
"license": "MIT",
"author": {
"name": "Blockcore",
diff --git a/src/Blockcore.Indexer.Core/Blockcore.Indexer.Core.csproj b/src/Blockcore.Indexer.Core/Blockcore.Indexer.Core.csproj
index 4f19570..889db51 100644
--- a/src/Blockcore.Indexer.Core/Blockcore.Indexer.Core.csproj
+++ b/src/Blockcore.Indexer.Core/Blockcore.Indexer.Core.csproj
@@ -2,14 +2,17 @@
+
+
+
diff --git a/src/Blockcore.Indexer.Core/Startup.cs b/src/Blockcore.Indexer.Core/Startup.cs
index 2e58db9..e32441a 100644
--- a/src/Blockcore.Indexer.Core/Startup.cs
+++ b/src/Blockcore.Indexer.Core/Startup.cs
@@ -20,6 +20,7 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc.ApplicationModels;
+using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
@@ -55,6 +56,8 @@ public static void AddIndexerServices(IServiceCollection services, IConfiguratio
return mongoClient.GetDatabase(dbName);
});
+ services.AddDbContext();
+
// services.AddSingleton();
services.AddSingleton();
services.AddSingleton();
@@ -150,7 +153,7 @@ public static void AddIndexerServices(IServiceCollection services, IConfiguratio
services.AddTransient();
}
- public static void Configure(IApplicationBuilder app, IWebHostEnvironment env)
+ public static void Configure(IApplicationBuilder app, IWebHostEnvironment env, PostgresDbContext db)
{
app.UseExceptionHandler("/error");
@@ -160,6 +163,11 @@ public static void Configure(IApplicationBuilder app, IWebHostEnvironment env)
app.UseResponseCompression();
//app.UseMvc();
+ db.Database.Migrate();
+
+ using (var client = new PostgresDbContext()){
+ client.Database.EnsureCreated();
+ }
app.UseDefaultFiles();
diff --git a/src/Blockcore.Indexer.Core/Storage/Postgres/PostgresDBContext.cs b/src/Blockcore.Indexer.Core/Storage/Postgres/PostgresDBContext.cs
new file mode 100644
index 0000000..a56454b
--- /dev/null
+++ b/src/Blockcore.Indexer.Core/Storage/Postgres/PostgresDBContext.cs
@@ -0,0 +1,99 @@
+using System.Globalization;
+using Blockcore.Indexer.Core.Storage.Postgres.Types;
+using Blockcore.NBitcoin.Protocol;
+using Microsoft.EntityFrameworkCore;
+using Microsoft.Extensions.Options;
+
+public class PostgresDbContext : DbContext
+{
+ public PostgresDbContext() : base()
+ {
+
+ }
+ protected override void OnConfiguring(DbContextOptionsBuilder options)
+ {
+ options.UseNpgsql("Host=127.0.0.1;Port=5432;Database=IndexerBenchmark;Username=postgres;Password=drb;");
+ }
+
+ public DbSet Blocks { get; set; }
+ public DbSet Transactions { get; set; }
+ public DbSet Inputs { get; set; }
+ public DbSet