Skip to content

Commit 7888822

Browse files
committed
动态地址支持动态金额功能
1 parent 0e43dca commit 7888822

10 files changed

+320
-9
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
name: .NET
2+
3+
on:
4+
push:
5+
tags:
6+
- pre-v*
7+
8+
jobs:
9+
build:
10+
name: Build And Publish
11+
runs-on: ubuntu-latest
12+
defaults:
13+
run:
14+
working-directory: ./src
15+
steps:
16+
- uses: actions/checkout@v4
17+
- name: Setup .NET
18+
uses: actions/setup-dotnet@v4
19+
with:
20+
dotnet-version: 6.0.x
21+
- name: Publish for Linux-x64
22+
run: dotnet publish -c Release -r linux-x64 --self-contained -p:PublishTrimmed=true -p:PublishSingleFile=true -p:PublishReadyToRun=true -o app/linux-x64
23+
- name: Publish for Windows-x64
24+
run: dotnet publish -c Release -r win-x64 --self-contained -p:PublishTrimmed=true -p:PublishSingleFile=true -p:PublishReadyToRun=true -o app/win-x64
25+
- name: Upload artifacts
26+
uses: actions/upload-artifact@v3
27+
with:
28+
name: app
29+
if-no-files-found: error
30+
path: ${{ github.workspace }}/src/app
31+
32+
create_release:
33+
name: Create Release
34+
needs: build
35+
runs-on: ubuntu-latest
36+
steps:
37+
- name: Download artifact
38+
uses: actions/download-artifact@v3
39+
with:
40+
name: app
41+
path: app
42+
43+
- name: Zip artifact
44+
run: |
45+
cd app
46+
mv linux-x64/appsettings.Example.json linux-x64/appsettings.json
47+
zip -r linux-x64.zip linux-x64/*
48+
mv win-x64/appsettings.Example.json win-x64/appsettings.json
49+
zip -r win-x64.zip win-x64/*
50+
51+
- name: Create Release
52+
id: create_release
53+
uses: actions/create-release@v1
54+
env:
55+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
56+
with:
57+
tag_name: ${{ github.ref }}
58+
release_name: Release ${{ github.ref }}
59+
draft: false
60+
prerelease: true
61+
62+
- name: Upload Release Asset for Linux-x64
63+
id: upload_linux
64+
uses: actions/upload-release-asset@v1
65+
env:
66+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
67+
with:
68+
upload_url: ${{ steps.create_release.outputs.upload_url }}
69+
asset_path: app/linux-x64.zip
70+
asset_name: linux-x64.zip
71+
asset_content_type: application/zip
72+
73+
- name: Upload Release Asset for Windows-x64
74+
id: upload_win
75+
uses: actions/upload-release-asset@v1
76+
env:
77+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
78+
with:
79+
upload_url: ${{ steps.create_release.outputs.upload_url }}
80+
asset_path: app/win-x64.zip
81+
asset_name: win-x64.zip
82+
asset_content_type: application/zip
83+
84+
cleanup:
85+
name: Cleanup
86+
needs: create_release
87+
runs-on: ubuntu-latest
88+
steps:
89+
- name: Remove artifacts
90+
uses: geekyeggo/delete-artifact@v2
91+
with:
92+
name: "*"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
name: .NET
2+
3+
on:
4+
push:
5+
tags:
6+
- v*
7+
8+
jobs:
9+
build:
10+
name: Build And Publish
11+
runs-on: ubuntu-latest
12+
defaults:
13+
run:
14+
working-directory: ./src
15+
steps:
16+
- uses: actions/checkout@v4
17+
- name: Setup .NET
18+
uses: actions/setup-dotnet@v4
19+
with:
20+
dotnet-version: 6.0.x
21+
- name: Publish for Linux-x64
22+
run: dotnet publish -c Release -r linux-x64 --self-contained -p:PublishTrimmed=true -p:PublishSingleFile=true -p:PublishReadyToRun=true -o app/linux-x64
23+
- name: Publish for Windows-x64
24+
run: dotnet publish -c Release -r win-x64 --self-contained -p:PublishTrimmed=true -p:PublishSingleFile=true -p:PublishReadyToRun=true -o app/win-x64
25+
- name: Upload artifacts
26+
uses: actions/upload-artifact@v3
27+
with:
28+
name: app
29+
if-no-files-found: error
30+
path: ${{ github.workspace }}/src/app
31+
32+
create_release:
33+
name: Create Release
34+
needs: build
35+
runs-on: ubuntu-latest
36+
steps:
37+
- name: Download artifact
38+
uses: actions/download-artifact@v3
39+
with:
40+
name: app
41+
path: app
42+
43+
- name: Zip artifact
44+
run: |
45+
cd app
46+
mv linux-x64/appsettings.Example.json linux-x64/appsettings.json
47+
zip -r linux-x64.zip linux-x64/*
48+
mv win-x64/appsettings.Example.json win-x64/appsettings.json
49+
zip -r win-x64.zip win-x64/*
50+
51+
- name: Create Release
52+
id: create_release
53+
uses: actions/create-release@v1
54+
env:
55+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
56+
with:
57+
tag_name: ${{ github.ref }}
58+
release_name: Release ${{ github.ref }}
59+
draft: false
60+
prerelease: false
61+
62+
- name: Upload Release Asset for Linux-x64
63+
id: upload_linux
64+
uses: actions/upload-release-asset@v1
65+
env:
66+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
67+
with:
68+
upload_url: ${{ steps.create_release.outputs.upload_url }}
69+
asset_path: app/linux-x64.zip
70+
asset_name: linux-x64.zip
71+
asset_content_type: application/zip
72+
73+
- name: Upload Release Asset for Windows-x64
74+
id: upload_win
75+
uses: actions/upload-release-asset@v1
76+
env:
77+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
78+
with:
79+
upload_url: ${{ steps.create_release.outputs.upload_url }}
80+
asset_path: app/win-x64.zip
81+
asset_name: win-x64.zip
82+
asset_content_type: application/zip
83+
84+
cleanup:
85+
name: Cleanup
86+
needs: create_release
87+
runs-on: ubuntu-latest
88+
steps:
89+
- name: Remove artifacts
90+
uses: geekyeggo/delete-artifact@v2
91+
with:
92+
name: "*"

src/TokenPay.sln

+9
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
1616
..\README.md = ..\README.md
1717
EndProjectSection
1818
EndProject
19+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "github_workflows", "github_workflows", "{E016FFE1-38C6-4EB3-91AD-610E78DFBFB7}"
20+
ProjectSection(SolutionItems) = preProject
21+
..\.github\workflows\dotnet-publish-prerelease.yml = ..\.github\workflows\dotnet-publish-prerelease.yml
22+
..\.github\workflows\dotnet-publish-release.yml = ..\.github\workflows\dotnet-publish-release.yml
23+
EndProjectSection
24+
EndProject
1925
Global
2026
GlobalSection(SolutionConfigurationPlatforms) = preSolution
2127
Debug|Any CPU = Debug|Any CPU
@@ -30,6 +36,9 @@ Global
3036
GlobalSection(SolutionProperties) = preSolution
3137
HideSolutionNode = FALSE
3238
EndGlobalSection
39+
GlobalSection(NestedProjects) = preSolution
40+
{E016FFE1-38C6-4EB3-91AD-610E78DFBFB7} = {D54245C4-8D70-442B-91C0-0053856152B0}
41+
EndGlobalSection
3342
GlobalSection(ExtensibilityGlobals) = postSolution
3443
SolutionGuid = {55E2491A-F1DF-4F80-A121-D11734BCBFAF}
3544
EndGlobalSection

src/TokenPay/BgServices/OrderCheckEVMBaseService.cs

+27-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ public class OrderCheckEVMBaseService : BaseScheduledService
1818
private readonly List<EVMChain> _chains;
1919
private readonly IServiceProvider _serviceProvider;
2020
private readonly FlurlClient client;
21-
21+
private bool UseDynamicAddress => _configuration.GetValue("UseDynamicAddress", true);
22+
private bool UseDynamicAddressAmountMove => _configuration.GetValue("DynamicAddressConfig:AmountMove", false);
2223
public OrderCheckEVMBaseService(ILogger<OrderCheckEVMBaseService> logger,
2324
IConfiguration configuration,
2425
IHostEnvironment env,
@@ -115,16 +116,40 @@ protected override async Task ExecuteAsync()
115116
var order = orders.Where(x => x.Amount == RealAmount && x.ToAddress.ToLower() == item.To.ToLower() && x.CreateTime < item.DateTime)
116117
.OrderByDescending(x => x.CreateTime)//优先付最后一单
117118
.FirstOrDefault();
119+
recheck:
118120
if (order != null)
119121
{
120122
order.FromAddress = item.From;
121123
order.BlockTransactionId = item.Hash;
122124
order.Status = OrderStatus.Paid;
123-
order.PayTime = DateTime.Now;
125+
order.PayTime = item.DateTime;
126+
order.PayAmount = RealAmount;
124127
await _repository.UpdateAsync(order);
125128
orders.Remove(order);
126129
await SendAdminMessage(order);
127130
}
131+
else
132+
{
133+
if (UseDynamicAddress && UseDynamicAddressAmountMove)
134+
{
135+
//允许非准确金额支付
136+
var Move = _configuration.GetSection($"DynamicAddressConfig:{chain.BaseCoin}").Get<decimal[]>() ?? [];
137+
if (Move.Length == 2)
138+
{
139+
var Down = Move[0]; //上浮金额
140+
var Up = Move[1]; //下浮金额
141+
order = orders.Where(x => x.Amount >= RealAmount - Down && x.Amount <= RealAmount + Up)
142+
.Where(x => x.ToAddress == item.To && x.CreateTime < item.DateTime)
143+
.OrderByDescending(x => x.CreateTime)//优先付最后一单
144+
.FirstOrDefault();
145+
if (order != null)
146+
{
147+
order.IsDynamicAmount = true;
148+
goto recheck;
149+
}
150+
}
151+
}
152+
}
128153
}
129154
}
130155
}

src/TokenPay/BgServices/OrderCheckEVMERC20Service.cs

+27-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ public class OrderCheckEVMERC20Service : BaseScheduledService
1919
private readonly Channel<TokenOrders> _channel;
2020
private readonly IServiceProvider _serviceProvider;
2121
private readonly FlurlClient client;
22-
22+
private bool UseDynamicAddress => _configuration.GetValue("UseDynamicAddress", true);
23+
private bool UseDynamicAddressAmountMove => _configuration.GetValue("DynamicAddressConfig:AmountMove", false);
2324
public OrderCheckEVMERC20Service(ILogger<OrderCheckEVMERC20Service> logger,
2425
IConfiguration configuration,
2526
IHostEnvironment env,
@@ -134,16 +135,40 @@ private async Task ERC20(IBaseRepository<TokenOrders> _repository, string Curren
134135
var order = orders.Where(x => x.Amount == item.RealAmount && x.ToAddress.ToLower() == item.To.ToLower() && x.CreateTime < item.DateTime)
135136
.OrderByDescending(x => x.CreateTime)//优先付最后一单
136137
.FirstOrDefault();
138+
recheck:
137139
if (order != null)
138140
{
139141
order.FromAddress = item.From;
140142
order.BlockTransactionId = item.Hash;
141143
order.Status = OrderStatus.Paid;
142-
order.PayTime = DateTime.Now;
144+
order.PayTime = item.DateTime;
145+
order.PayAmount = item.RealAmount;
143146
await _repository.UpdateAsync(order);
144147
orders.Remove(order);
145148
await SendAdminMessage(order);
146149
}
150+
else
151+
{
152+
if (UseDynamicAddress && UseDynamicAddressAmountMove)
153+
{
154+
//允许非准确金额支付
155+
var Move = _configuration.GetSection($"DynamicAddressConfig:{erc20.Name}").Get<decimal[]>() ?? [];
156+
if (Move.Length == 2)
157+
{
158+
var Down = Move[0]; //上浮金额
159+
var Up = Move[1]; //下浮金额
160+
order = orders.Where(x => x.Amount >= item.RealAmount - Down && x.Amount <= item.RealAmount + Up)
161+
.Where(x => x.ToAddress == item.To && x.CreateTime < item.DateTime)
162+
.OrderByDescending(x => x.CreateTime)//优先付最后一单
163+
.FirstOrDefault();
164+
if (order != null)
165+
{
166+
order.IsDynamicAmount = true;
167+
goto recheck;
168+
}
169+
}
170+
}
171+
}
147172
}
148173
}
149174
}

src/TokenPay/BgServices/OrderCheckTRC20Service.cs

+27-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ public class OrderCheckTRC20Service : BaseScheduledService
1616
private readonly IHostEnvironment _env;
1717
private readonly Channel<TokenOrders> _channel;
1818
private readonly IServiceProvider _serviceProvider;
19-
19+
private bool UseDynamicAddress => _configuration.GetValue("UseDynamicAddress", true);
20+
private bool UseDynamicAddressAmountMove => _configuration.GetValue("DynamicAddressConfig:AmountMove", false);
2021
public OrderCheckTRC20Service(ILogger<OrderCheckTRC20Service> logger,
2122
IConfiguration configuration,
2223
IHostEnvironment env,
@@ -109,16 +110,40 @@ protected override async Task ExecuteAsync()
109110
var order = orders.Where(x => x.Amount == item.Amount && x.ToAddress == item.To && x.CreateTime < item.BlockTimestamp.ToDateTime())
110111
.OrderByDescending(x => x.CreateTime)//优先付最后一单
111112
.FirstOrDefault();
113+
recheck:
112114
if (order != null)
113115
{
114116
order.FromAddress = item.From;
115117
order.BlockTransactionId = item.TransactionId;
116118
order.Status = OrderStatus.Paid;
117-
order.PayTime = DateTime.Now;
119+
order.PayTime = item.BlockTimestamp.ToDateTime();
120+
order.PayAmount = item.Amount;
118121
await _repository.UpdateAsync(order);
119122
orders.Remove(order);
120123
await SendAdminMessage(order);
121124
}
125+
else
126+
{
127+
if (UseDynamicAddress && UseDynamicAddressAmountMove)
128+
{
129+
//允许非准确金额支付
130+
var Move = _configuration.GetSection("DynamicAddressConfig:USDT").Get<decimal[]>() ?? [];
131+
if (Move.Length == 2)
132+
{
133+
var Down = Move[0]; //上浮金额
134+
var Up = Move[1]; //下浮金额
135+
order = orders.Where(x => x.Amount >= item.Amount - Down && x.Amount <= item.Amount + Up)
136+
.Where(x => x.ToAddress == item.To && x.CreateTime < item.BlockTimestamp.ToDateTime())
137+
.OrderByDescending(x => x.CreateTime)//优先付最后一单
138+
.FirstOrDefault();
139+
if (order != null)
140+
{
141+
order.IsDynamicAmount = true;
142+
goto recheck;
143+
}
144+
}
145+
}
146+
}
122147
}
123148
}
124149
}

0 commit comments

Comments
 (0)