Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
guru
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DeStream-public
guru
Commits
ff1bde4e
Commit
ff1bde4e
authored
Dec 23, 2018
by
Clint.Network
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Create Lottery Service and Deposit Modal
parent
f2eebcb7
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
219 additions
and
21 deletions
+219
-21
HomeController.cs
Stratis.Guru/Controllers/HomeController.cs
+35
-0
IMongoContext.cs
Stratis.Guru/DependencyInjection/IMongoContext.cs
+7
-0
LotteryDraw.cs
Stratis.Guru/Models/LotteryDraw.cs
+13
-0
LotteryService.cs
Stratis.Guru/Services/LotteryService.cs
+60
-0
Startup.cs
Stratis.Guru/Startup.cs
+17
-1
Stratis.Guru.csproj
Stratis.Guru/Stratis.Guru.csproj
+10
-7
Lottery.cshtml
Stratis.Guru/Views/Home/Lottery.cshtml
+66
-7
_Layout.cshtml
Stratis.Guru/Views/Shared/_Layout.cshtml
+2
-2
_ViewImports.cshtml
Stratis.Guru/Views/_ViewImports.cshtml
+1
-0
libman.json
Stratis.Guru/libman.json
+8
-4
No files found.
Stratis.Guru/Controllers/HomeController.cs
View file @
ff1bde4e
...
...
@@ -15,6 +15,7 @@ using Microsoft.Extensions.Caching.Memory;
using
NBitcoin
;
using
Newtonsoft.Json
;
using
Newtonsoft.Json.Linq
;
using
PaulMiami.AspNetCore.Mvc.Recaptcha
;
using
QRCoder
;
using
Stratis.Guru.Models
;
using
Stratis.Guru.Modules
;
...
...
@@ -69,9 +70,43 @@ namespace Stratis.Guru.Controllers
[
Route
(
"lottery"
)]
public
IActionResult
Lottery
()
{
ViewBag
.
NextDraw
=
long
.
Parse
(
_memoryCache
.
Get
(
"NextDraw"
).
ToString
());
return
View
();
}
[
ValidateRecaptcha
]
[
HttpPost
]
[
Route
(
"lottery/participate"
)]
public
IActionResult
Participate
()
{
if
(
ModelState
.
IsValid
)
{
return
RedirectToAction
(
"Participate"
,
new
{
id
=
"5c1ef60f09f5754c34ba3010"
});
}
ViewBag
.
NextDraw
=
long
.
Parse
(
_memoryCache
.
Get
(
"NextDraw"
).
ToString
());
ViewBag
.
Participate
=
true
;
return
View
(
"Lottery"
);
}
[
HttpGet
]
[
Route
(
"lottery/participate/{id}"
)]
public
IActionResult
Participate
(
string
id
)
{
ViewBag
.
NextDraw
=
long
.
Parse
(
_memoryCache
.
Get
(
"NextDraw"
).
ToString
());
ViewBag
.
Participate
=
true
;
return
View
(
"Lottery"
);
}
[
HttpPost
]
[
Route
(
"lottery/check-payment/{address}"
)]
public
IActionResult
CheckPayment
(
string
address
)
{
var
pubkey
=
ExtPubKey
.
Parse
(
"xpub6Bfq1wKQ64UUzW2HzQ6aZmoxkMYVq6DNifiTU1A1d9UEe16qSGnyqSAbFr42XAMXSXi3kcMXQJseXcgyTGQeDpBvHYt5m1HCH74Q52C4kkZ"
);
var
newAddress
=
pubkey
.
Derive
(
0
).
Derive
(
0
).
PubKey
.
GetAddress
(
Network
.
StratisMain
);
Console
.
WriteLine
(
newAddress
);
return
Json
(
true
);
}
[
Route
(
"about"
)]
public
IActionResult
About
()
{
...
...
Stratis.Guru/DependencyInjection/IMongoContext.cs
0 → 100644
View file @
ff1bde4e
namespace
Stratis.Guru.DependencyInjection
{
public
interface
IMongoContext
{
}
}
\ No newline at end of file
Stratis.Guru/Models/LotteryDraw.cs
0 → 100644
View file @
ff1bde4e
using
MongoDB.Bson
;
using
MongoDB.Bson.Serialization.Attributes
;
namespace
Stratis.Guru.Models
{
public
class
LotteryDraw
{
[
BsonId
]
public
ObjectId
Id
{
get
;
set
;
}
public
long
DrawDate
{
get
;
set
;
}
public
bool
Passed
{
get
;
set
;
}
}
}
\ No newline at end of file
Stratis.Guru/Services/LotteryService.cs
0 → 100644
View file @
ff1bde4e
using
System
;
using
System.Threading
;
using
System.Threading.Tasks
;
using
Microsoft.Extensions.Caching.Memory
;
using
Microsoft.Extensions.Hosting
;
using
MongoDB.Bson
;
using
MongoDB.Driver
;
using
Stratis.Guru.Models
;
namespace
Stratis.Guru.Services
{
public
class
LotteryService
:
IHostedService
,
IDisposable
{
private
readonly
IMemoryCache
_memoryCache
;
private
DateTime
_nextDraw
;
public
LotteryService
(
IMemoryCache
memoryCache
)
{
_memoryCache
=
memoryCache
;
}
public
async
Task
StartAsync
(
CancellationToken
cancellationToken
)
{
await
CalculateNextDrawAsync
();
}
private
async
Task
CalculateNextDrawAsync
()
{
DateTime
today
=
DateTime
.
Today
;
int
daysUntilFriday
=
((
int
)
DayOfWeek
.
Friday
-
(
int
)
today
.
DayOfWeek
+
7
)
%
7
;
_nextDraw
=
today
.
AddDays
(
daysUntilFriday
);
var
nextDrawTimestamp
=
((
DateTimeOffset
)
_nextDraw
).
ToUnixTimeSeconds
();
#
region
use
DI
var
client
=
new
MongoClient
(
"mongodb://localhost:27017"
);
var
database
=
client
.
GetDatabase
(
"stratis-guru"
);
var
collection
=
database
.
GetCollection
<
LotteryDraw
>(
"draws"
);
if
(!
collection
.
Find
(
x
=>
x
.
DrawDate
.
Equals
(
nextDrawTimestamp
)).
Any
())
{
await
collection
.
InsertOneAsync
(
new
LotteryDraw
()
{
DrawDate
=
nextDrawTimestamp
,
Passed
=
false
});
}
#
endregion
_memoryCache
.
Set
(
"NextDraw"
,
nextDrawTimestamp
);
}
public
Task
StopAsync
(
CancellationToken
cancellationToken
)
{
return
Task
.
CompletedTask
;
}
public
void
Dispose
()
{
}
}
}
\ No newline at end of file
Stratis.Guru/Startup.cs
View file @
ff1bde4e
...
...
@@ -10,9 +10,11 @@ using Microsoft.AspNetCore.Hosting;
using
Microsoft.AspNetCore.HttpsPolicy
;
using
Microsoft.AspNetCore.Localization
;
using
Microsoft.AspNetCore.Mvc
;
using
Microsoft.EntityFrameworkCore
;
using
Microsoft.Extensions.Configuration
;
using
Microsoft.Extensions.DependencyInjection
;
using
Microsoft.Extensions.FileProviders
;
using
PaulMiami.AspNetCore.Mvc.Recaptcha
;
using
Stratis.Guru.Hubs
;
using
Stratis.Guru.Models
;
using
Stratis.Guru.Modules
;
...
...
@@ -41,6 +43,12 @@ namespace Stratis.Guru
options
.
CheckConsentNeeded
=
context
=>
true
;
options
.
MinimumSameSitePolicy
=
None
;
});
services
.
AddSession
(
options
=>
{
options
.
Cookie
.
IsEssential
=
true
;
});
services
.
Configure
<
NakoApiSettings
>(
Configuration
.
GetSection
(
"NakoApi"
));
services
.
Configure
<
FixerApiSettings
>(
Configuration
.
GetSection
(
"FixerApi"
));
...
...
@@ -51,11 +59,18 @@ namespace Stratis.Guru
services
.
AddHostedService
<
UpdateInfosService
>();
services
.
AddHostedService
<
FixerService
>();
services
.
AddHostedService
<
LotteryService
>();
services
.
AddHostedService
<
VanityService
>();
services
.
AddLocalization
();
services
.
AddMvc
();
services
.
AddRecaptcha
(
new
RecaptchaOptions
{
SiteKey
=
"6LfmOIQUAAAAAIEsH2nG6kEiL-bpLhvm0ibhHnol"
,
//Configuration["Recaptcha:SiteKey"],
SecretKey
=
"6LfmOIQUAAAAAO06PpD8MmndjrjfBr7x-fgnDt2G"
//Configuration["Recaptcha:SecretKey"]
});
services
.
AddSignalR
();
}
...
...
@@ -70,9 +85,10 @@ namespace Stratis.Guru
{
app
.
UseExceptionHandler
(
"/Home/Error"
);
//app.UseHsts();
app
.
UseHttpsRedirection
();
}
//app.UseHttpsRedirect
ion();
app
.
UseSess
ion
();
app
.
UseStaticFiles
();
app
.
UseCookiePolicy
();
...
...
Stratis.Guru/Stratis.Guru.csproj
View file @
ff1bde4e
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.
1
</TargetFramework>
<TargetFramework>netcoreapp2.
2
</TargetFramework>
</PropertyGroup>
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.0" />
<DotNetCliToolReference Include="BundlerMinifier.Core" Version="2.6.362" />
<PackageReference Include="Microsoft.AspNetCore.SignalR" Version="1.1.0" />
<PackageReference Include="Microsoft.Web.LibraryManager.Build" Version="1.0.113" />
<PackageReference Include="Microsoft.AspNetCore.App"/>
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.1.2" PrivateAssets="All"/>
<PackageReference Include="Microsoft.AspNetCore.SignalR" Version="1.0.4"/>
<PackageReference Include="NStratis" Version="4.0.0.60"/>
<PackageReference Include="QRCoder" Version="1.3.3"/>
<PackageReference Include="RestSharp" Version="106.5.4"/>
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" />
<PackageReference Include="mongocsharpdriver" Version="2.7.2" />
<PackageReference Include="NStratis" Version="4.0.0.60" />
<PackageReference Include="PaulMiami.AspNetCore.Mvc.Recaptcha" Version="1.2.1" />
<PackageReference Include="QRCoder" Version="1.3.3" />
<PackageReference Include="RestSharp" Version="106.5.4" />
</ItemGroup>
</Project>
Stratis.Guru/Views/Home/Lottery.cshtml
View file @
ff1bde4e
...
...
@@ -5,24 +5,76 @@
@section Style
{
<style>
body
{
.shadow-inset
{
background-image: url(/images/Slider_Landing-1920x650.webp.jpg);
}
.modal-content
{
border-radius: 3px;
}
</style>
}
<div class="modal fade" id="participate-modal" tabindex="-1" role="dialog">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<form method="post" asp-controller="Home" asp-action="Participate">
<div class="modal-header">
<h5 class="modal-title"><i class="fa fa-ticket"></i> Buy a Lottery Ticket</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<p>The <strong>Stratis.Guru</strong> lottery is drawn every week at 8 PM, you can easily participate, get a ticket and play some $STRAT.</p>
<br />
<center>
<recaptcha/>
</center>
</div>
<div class="modal-footer">
<button type="submit" class="btn btn-info btn-lg btn-block">Get a Ticket</button>
</div>
</form>
</div>
</div>
</div>
<div class="modal fade" id="deposit-modal" tabindex="-1" role="dialog">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title"><i class="fa fa-ticket"></i> Buy a Lottery Ticket</h5>
<a asp-controller="Home" asp-action="Lottery" type="button" class="close">
<span aria-hidden="true">×</span>
</a>
</div>
<div class="modal-body text-center py-4">
<h2 class="text-dark mb-1">Send Some $STRAT</h2>
<p>Your participation will be considered after 1 confirmation.</p>
<img class="my-4" src="@Url.Action("Qr", "Home", new {value="SfXZxGJWnq3aP8hDmGKWJxJbtbEXYtba86"})" style="width: 250px;" />
<h4>Send to this address: <code>SfXZxGJWnq3aP8hDmGKWJxJbtbEXYtba86</code></h4>
</div>
<div class="modal-footer">
<a asp-controller="Home" asp-action="CheckPayment" data-ajax-method="POST" asp-route-address="SfXZxGJWnq3aP8hDmGKWJxJbtbEXYtba86" data-ajax-success="alert('yeah');" data-ajax-failure="alert('failure');" data-ajax="true" class="btn btn-info btn-lg btn-block"><i class="fa fa-check-circle"></i> Check Payment</a>
</div>
</div>
</div>
</div>
<div class="shadow-inset"></div>
<section class="welcome-area pb-4" id="welcome-1">
<div class="header-token">
<div class="container">
<div class="row">
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 align-self-center text-center">
<h1 class="m-0">The Next <strong>Stratis</strong> Lottery Draw in:</h1>
<h1 class="align-middle">
<h1 class="m-0">The Next <strong>Stratis
.Guru
</strong> Lottery Draw in:</h1>
<h1 class="
mb-3
align-middle">
<span class="align-middle display-1 font-weight-bold" id="amount">
<span id="clock"></span>
</span>
</h1>
<a asp-controller="BlockExplorer" asp-action="Index" class="btn-secondary-box"><i class="fa fa-ticket"></i> Buy a lottery ticket</a>
<h2 class="mb-5">Actual Jackpot: @(257.89.ToString("C"))</h2>
<button data-toggle="modal" data-target="#participate-modal" class="btn-secondary-box"><i class="fa fa-ticket"></i> Buy a lottery ticket</button>
<button data-toggle="modal" data-target="#players-modal" class="btn-secondary-box"><i class="fa fa-user-o"></i> See Players</button>
</div>
</div>
</div>
...
...
@@ -30,11 +82,18 @@
</section>
@section Scripts
{
<script src="/npm/jquery-countdown/dist/jquery.countdown.min.js"></script>
<recaptcha-script/>
<script src="~/lib/jquery-countdown/dist/jquery.countdown.min.js"></script>
<script src="~/lib/jquery-ajax-unobtrusive/dist/jquery.unobtrusive-ajax.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('#clock').countdown('2020/10/10', function(event) {
$(this).html(event.strftime('%Hh %Mm %Ss'));
@if(ViewBag.Participate == true)
{
<text>$("#deposit-modal").modal({backdrop: 'static', keyboard: false});</text>
}
$('#clock').countdown('@((DateTimeOffset.FromUnixTimeSeconds((long)ViewBag.NextDraw)).ToString("yyyy/MM/dd HH:mm:ss"))', function(event) {
$(this).html(event.strftime('%D days %Hh %Mm %Ss'));
});
})
</script>
...
...
Stratis.Guru/Views/Shared/_Layout.cshtml
View file @
ff1bde4e
...
...
@@ -41,10 +41,10 @@
</a>
<ul
class=
"nav"
>
<li
class=
"@(Context.Request.Path.Equals(Url.Action("
Index
",
"
Home
"))
?
"
active
"
:
"")"
><a
asp-action=
"Index"
asp-controller=
"Home"
><i
class=
"fa fa-home"
></i>
HOME
</a></li>
@*
<li
class=
"@(Context.Request.Path.Equals(Url.Action("
Lottery
",
"
Home
"))
?
"
active
"
:
"")"
><a
asp-action=
"Lottery"
asp-controller=
"Home"
><i
class=
"fa fa-trophy"
></i>
LOTTERY
</a></li>
*@
<li
class=
"@(Context.Request.Path.Equals(Url.Action("
Lottery
",
"
Home
"))
?
"
active
"
:
"")"
><a
asp-action=
"Lottery"
asp-controller=
"Home"
><i
class=
"fa fa-trophy"
></i>
LOTTERY
</a></li>
<li
class=
"@(Context.Request.Path.Equals(Url.Action("
Index
",
"
BlockExplorer
"))
?
"
active
"
:
"")"
><a
asp-action=
"Index"
asp-controller=
"BlockExplorer"
><i
class=
"fa fa-cube"
></i>
BLOCK EXPLORER
</a></li>
<li
class=
"@(Context.Request.Path.Equals(Url.Action("
Vanity
",
"
Home
"))
?
"
active
"
:
"")"
><a
asp-action=
"Vanity"
asp-controller=
"Home"
><i
class=
"fa fa-at"
></i>
VANITY
</a></li>
<li
class=
"@(Context.Request.Path.Equals(Url.Action("
Generator
",
"
Home
"))
?
"
active
"
:
"")"
><a
asp-action=
"Generator"
asp-controller=
"Home"
><i
class=
"fa fa-qrcode"
></i>
ADDRESS
GENERATOR
</a></li>
<li
class=
"@(Context.Request.Path.Equals(Url.Action("
Generator
",
"
Home
"))
?
"
active
"
:
"")"
><a
asp-action=
"Generator"
asp-controller=
"Home"
><i
class=
"fa fa-qrcode"
></i>
GENERATOR
</a></li>
<li
class=
"@(Context.Request.Path.Equals(Url.Action("
Documentation
",
"
Home
"))
?
"
active
"
:
"")"
><a
asp-action=
"Documentation"
asp-controller=
"Home"
><i
class=
"fa fa-book"
></i>
API
</a></li>
<li
class=
"@(Context.Request.Path.Equals(Url.Action("
About
",
"
Home
"))
?
"
active
"
:
"")"
><a
asp-action=
"About"
asp-controller=
"Home"
><i
class=
"fa fa-info-circle"
></i>
ABOUT
</a></li>
</ul>
...
...
Stratis.Guru/Views/_ViewImports.cshtml
View file @
ff1bde4e
...
...
@@ -2,3 +2,4 @@
@using Stratis.Guru.Models
@using System.Globalization
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@addTagHelper *, PaulMiami.AspNetCore.Mvc.Recaptcha
\ No newline at end of file
Stratis.Guru/libman.json
View file @
ff1bde4e
...
...
@@ -6,10 +6,6 @@
"library"
:
"bootstrap@4.1.3"
,
"destination"
:
"wwwroot
\\
lib
\\
bootstrap"
},
{
"library"
:
"jquery-countdown@2.2.0"
,
"destination"
:
"wwwroot
\\
lib
\\
jquery-countdown"
},
{
"library"
:
"nprogress@0.2.0"
,
"destination"
:
"wwwroot
\\
lib
\\
nprogress"
...
...
@@ -17,6 +13,14 @@
{
"library"
:
"@aspnet/signalr@1.1.0"
,
"destination"
:
"wwwroot
\\
lib
\\
@aspnet/signalr"
},
{
"library"
:
"jquery-countdown@2.2.0"
,
"destination"
:
"wwwroot
\\
lib
\\
jquery-countdown"
},
{
"library"
:
"jquery-ajax-unobtrusive@3.2.6"
,
"destination"
:
"wwwroot
\\
lib
\\
jquery-ajax-unobtrusive"
}
]
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment