Skip to content

Commit

Permalink
动态地址支持动态金额功能
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhangYiQiu committed Sep 1, 2024
1 parent 0e43dca commit 7888822
Show file tree
Hide file tree
Showing 10 changed files with 320 additions and 9 deletions.
92 changes: 92 additions & 0 deletions .github/workflows/dotnet-publish-prerelease.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
name: .NET

on:
push:
tags:
- pre-v*

jobs:
build:
name: Build And Publish
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./src
steps:
- uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 6.0.x
- name: Publish for Linux-x64
run: dotnet publish -c Release -r linux-x64 --self-contained -p:PublishTrimmed=true -p:PublishSingleFile=true -p:PublishReadyToRun=true -o app/linux-x64
- name: Publish for Windows-x64
run: dotnet publish -c Release -r win-x64 --self-contained -p:PublishTrimmed=true -p:PublishSingleFile=true -p:PublishReadyToRun=true -o app/win-x64
- name: Upload artifacts
uses: actions/upload-artifact@v3
with:
name: app
if-no-files-found: error
path: ${{ github.workspace }}/src/app

create_release:
name: Create Release
needs: build
runs-on: ubuntu-latest
steps:
- name: Download artifact
uses: actions/download-artifact@v3
with:
name: app
path: app

- name: Zip artifact
run: |
cd app
mv linux-x64/appsettings.Example.json linux-x64/appsettings.json
zip -r linux-x64.zip linux-x64/*
mv win-x64/appsettings.Example.json win-x64/appsettings.json
zip -r win-x64.zip win-x64/*
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: Release ${{ github.ref }}
draft: false
prerelease: true

- name: Upload Release Asset for Linux-x64
id: upload_linux
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: app/linux-x64.zip
asset_name: linux-x64.zip
asset_content_type: application/zip

- name: Upload Release Asset for Windows-x64
id: upload_win
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: app/win-x64.zip
asset_name: win-x64.zip
asset_content_type: application/zip

cleanup:
name: Cleanup
needs: create_release
runs-on: ubuntu-latest
steps:
- name: Remove artifacts
uses: geekyeggo/delete-artifact@v2
with:
name: "*"
92 changes: 92 additions & 0 deletions .github/workflows/dotnet-publish-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
name: .NET

on:
push:
tags:
- v*

jobs:
build:
name: Build And Publish
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./src
steps:
- uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 6.0.x
- name: Publish for Linux-x64
run: dotnet publish -c Release -r linux-x64 --self-contained -p:PublishTrimmed=true -p:PublishSingleFile=true -p:PublishReadyToRun=true -o app/linux-x64
- name: Publish for Windows-x64
run: dotnet publish -c Release -r win-x64 --self-contained -p:PublishTrimmed=true -p:PublishSingleFile=true -p:PublishReadyToRun=true -o app/win-x64
- name: Upload artifacts
uses: actions/upload-artifact@v3
with:
name: app
if-no-files-found: error
path: ${{ github.workspace }}/src/app

create_release:
name: Create Release
needs: build
runs-on: ubuntu-latest
steps:
- name: Download artifact
uses: actions/download-artifact@v3
with:
name: app
path: app

- name: Zip artifact
run: |
cd app
mv linux-x64/appsettings.Example.json linux-x64/appsettings.json
zip -r linux-x64.zip linux-x64/*
mv win-x64/appsettings.Example.json win-x64/appsettings.json
zip -r win-x64.zip win-x64/*
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: Release ${{ github.ref }}
draft: false
prerelease: false

- name: Upload Release Asset for Linux-x64
id: upload_linux
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: app/linux-x64.zip
asset_name: linux-x64.zip
asset_content_type: application/zip

- name: Upload Release Asset for Windows-x64
id: upload_win
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: app/win-x64.zip
asset_name: win-x64.zip
asset_content_type: application/zip

cleanup:
name: Cleanup
needs: create_release
runs-on: ubuntu-latest
steps:
- name: Remove artifacts
uses: geekyeggo/delete-artifact@v2
with:
name: "*"
9 changes: 9 additions & 0 deletions src/TokenPay.sln
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
..\README.md = ..\README.md
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "github_workflows", "github_workflows", "{E016FFE1-38C6-4EB3-91AD-610E78DFBFB7}"
ProjectSection(SolutionItems) = preProject
..\.github\workflows\dotnet-publish-prerelease.yml = ..\.github\workflows\dotnet-publish-prerelease.yml
..\.github\workflows\dotnet-publish-release.yml = ..\.github\workflows\dotnet-publish-release.yml
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -30,6 +36,9 @@ Global
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{E016FFE1-38C6-4EB3-91AD-610E78DFBFB7} = {D54245C4-8D70-442B-91C0-0053856152B0}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {55E2491A-F1DF-4F80-A121-D11734BCBFAF}
EndGlobalSection
Expand Down
29 changes: 27 additions & 2 deletions src/TokenPay/BgServices/OrderCheckEVMBaseService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ public class OrderCheckEVMBaseService : BaseScheduledService
private readonly List<EVMChain> _chains;
private readonly IServiceProvider _serviceProvider;
private readonly FlurlClient client;

private bool UseDynamicAddress => _configuration.GetValue("UseDynamicAddress", true);
private bool UseDynamicAddressAmountMove => _configuration.GetValue("DynamicAddressConfig:AmountMove", false);
public OrderCheckEVMBaseService(ILogger<OrderCheckEVMBaseService> logger,
IConfiguration configuration,
IHostEnvironment env,
Expand Down Expand Up @@ -115,16 +116,40 @@ protected override async Task ExecuteAsync()
var order = orders.Where(x => x.Amount == RealAmount && x.ToAddress.ToLower() == item.To.ToLower() && x.CreateTime < item.DateTime)
.OrderByDescending(x => x.CreateTime)//优先付最后一单
.FirstOrDefault();
recheck:
if (order != null)
{
order.FromAddress = item.From;
order.BlockTransactionId = item.Hash;
order.Status = OrderStatus.Paid;
order.PayTime = DateTime.Now;
order.PayTime = item.DateTime;
order.PayAmount = RealAmount;
await _repository.UpdateAsync(order);
orders.Remove(order);
await SendAdminMessage(order);
}
else
{
if (UseDynamicAddress && UseDynamicAddressAmountMove)
{
//允许非准确金额支付
var Move = _configuration.GetSection($"DynamicAddressConfig:{chain.BaseCoin}").Get<decimal[]>() ?? [];
if (Move.Length == 2)
{
var Down = Move[0]; //上浮金额
var Up = Move[1]; //下浮金额
order = orders.Where(x => x.Amount >= RealAmount - Down && x.Amount <= RealAmount + Up)
.Where(x => x.ToAddress == item.To && x.CreateTime < item.DateTime)
.OrderByDescending(x => x.CreateTime)//优先付最后一单
.FirstOrDefault();
if (order != null)
{
order.IsDynamicAmount = true;
goto recheck;
}
}
}
}
}
}
}
Expand Down
29 changes: 27 additions & 2 deletions src/TokenPay/BgServices/OrderCheckEVMERC20Service.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ public class OrderCheckEVMERC20Service : BaseScheduledService
private readonly Channel<TokenOrders> _channel;
private readonly IServiceProvider _serviceProvider;
private readonly FlurlClient client;

private bool UseDynamicAddress => _configuration.GetValue("UseDynamicAddress", true);
private bool UseDynamicAddressAmountMove => _configuration.GetValue("DynamicAddressConfig:AmountMove", false);
public OrderCheckEVMERC20Service(ILogger<OrderCheckEVMERC20Service> logger,
IConfiguration configuration,
IHostEnvironment env,
Expand Down Expand Up @@ -134,16 +135,40 @@ private async Task ERC20(IBaseRepository<TokenOrders> _repository, string Curren
var order = orders.Where(x => x.Amount == item.RealAmount && x.ToAddress.ToLower() == item.To.ToLower() && x.CreateTime < item.DateTime)
.OrderByDescending(x => x.CreateTime)//优先付最后一单
.FirstOrDefault();
recheck:
if (order != null)
{
order.FromAddress = item.From;
order.BlockTransactionId = item.Hash;
order.Status = OrderStatus.Paid;
order.PayTime = DateTime.Now;
order.PayTime = item.DateTime;
order.PayAmount = item.RealAmount;
await _repository.UpdateAsync(order);
orders.Remove(order);
await SendAdminMessage(order);
}
else
{
if (UseDynamicAddress && UseDynamicAddressAmountMove)
{
//允许非准确金额支付
var Move = _configuration.GetSection($"DynamicAddressConfig:{erc20.Name}").Get<decimal[]>() ?? [];
if (Move.Length == 2)
{
var Down = Move[0]; //上浮金额
var Up = Move[1]; //下浮金额
order = orders.Where(x => x.Amount >= item.RealAmount - Down && x.Amount <= item.RealAmount + Up)
.Where(x => x.ToAddress == item.To && x.CreateTime < item.DateTime)
.OrderByDescending(x => x.CreateTime)//优先付最后一单
.FirstOrDefault();
if (order != null)
{
order.IsDynamicAmount = true;
goto recheck;
}
}
}
}
}
}
}
Expand Down
29 changes: 27 additions & 2 deletions src/TokenPay/BgServices/OrderCheckTRC20Service.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ public class OrderCheckTRC20Service : BaseScheduledService
private readonly IHostEnvironment _env;
private readonly Channel<TokenOrders> _channel;
private readonly IServiceProvider _serviceProvider;

private bool UseDynamicAddress => _configuration.GetValue("UseDynamicAddress", true);
private bool UseDynamicAddressAmountMove => _configuration.GetValue("DynamicAddressConfig:AmountMove", false);
public OrderCheckTRC20Service(ILogger<OrderCheckTRC20Service> logger,
IConfiguration configuration,
IHostEnvironment env,
Expand Down Expand Up @@ -109,16 +110,40 @@ protected override async Task ExecuteAsync()
var order = orders.Where(x => x.Amount == item.Amount && x.ToAddress == item.To && x.CreateTime < item.BlockTimestamp.ToDateTime())
.OrderByDescending(x => x.CreateTime)//优先付最后一单
.FirstOrDefault();
recheck:
if (order != null)
{
order.FromAddress = item.From;
order.BlockTransactionId = item.TransactionId;
order.Status = OrderStatus.Paid;
order.PayTime = DateTime.Now;
order.PayTime = item.BlockTimestamp.ToDateTime();
order.PayAmount = item.Amount;
await _repository.UpdateAsync(order);
orders.Remove(order);
await SendAdminMessage(order);
}
else
{
if (UseDynamicAddress && UseDynamicAddressAmountMove)
{
//允许非准确金额支付
var Move = _configuration.GetSection("DynamicAddressConfig:USDT").Get<decimal[]>() ?? [];
if (Move.Length == 2)
{
var Down = Move[0]; //上浮金额
var Up = Move[1]; //下浮金额
order = orders.Where(x => x.Amount >= item.Amount - Down && x.Amount <= item.Amount + Up)
.Where(x => x.ToAddress == item.To && x.CreateTime < item.BlockTimestamp.ToDateTime())
.OrderByDescending(x => x.CreateTime)//优先付最后一单
.FirstOrDefault();
if (order != null)
{
order.IsDynamicAmount = true;
goto recheck;
}
}
}
}
}
}
}
Expand Down
Loading

0 comments on commit 7888822

Please sign in to comment.