Skip to content

Commit

Permalink
不能同时使用TRX动态地址和ETH动态地址的bug修复、增加ETH系其他链的支持
Browse files Browse the repository at this point in the history
  • Loading branch information
Light committed Mar 3, 2023
1 parent 92b84cc commit 67cc11f
Show file tree
Hide file tree
Showing 32 changed files with 854 additions and 716 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -363,3 +363,5 @@ MigrationBackup/
FodyWeavers.xsd
/src/publish.sh
/src/archive.sh
/src/TokenPay/EVMChains.json
/src/TokenPay/EVMChains.Development.json
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

## TokenPay - `区块链`支付解决方案

>一款开源的,支持以动态收款地址或静态收款地址收取`TRX``USDT-TRC20``ETH``USDT-ERC20``USDC-ERC20`等区块链代币的支付解决方案!
>一款开源的,支持以动态收款地址或静态收款地址收取波场的`TRX``USDT-TRC20`以及`ETH系原生币`以及`ETH系ERC20代币`的支付解决方案! 理论上支持`所有ETH系的区块链`,常见的ETH系的区块链有:`以太坊(ETH)``币安智能链(BSC)``Polygon`等等。

## AD -- 免费领取国际信用卡
Expand All @@ -21,7 +21,7 @@
## 项目简介
- `TokenPay`是一个由`C#语言`编写的私有化部署的`区块链`支付解决方案。
- 本项目不依赖任何外部资源,无需另外部署`数据库`,采用轻量化的`sqlite`,也无需`redis`
- 任意项目都可以对接,轻松实现`TRX``USDT-TRC20``ETH``USDT-ERC20``USDC-ERC20`收款!😊 😊 😊
- 任意项目都可以对接,轻松实现`TRX``USDT-TRC20`以及`ETH系原生币`以及`ETH系ERC20代币`,理论支持`所有ETH系的区块链`收款!😊 😊 😊
- `TokenPay` 遵守 [GPLv3](https://www.gnu.org/licenses/gpl-3.0.html) 开源协议!

## 项目特点
Expand Down Expand Up @@ -57,7 +57,7 @@ TokenPay

## 设计实现
`TokenPay`的实现方式与其他项目原理类似,都是通过`TronGrid``EtherScan`等提供的api,
轮询订单未过期的钱包地址的`TRX``ETH``USDT``USDC`入账事件,将入账金额,与数据库的订单金额进行对比,若一致,则视为订单完成
轮询订单未过期的钱包地址的`TRX``ETH``USDT``USDC`等入账事件,将入账金额,与数据库的订单金额进行对比,若一致,则视为订单完成
```
简单的原理:
0.服务器定时同步交易所最新汇率
Expand All @@ -70,7 +70,7 @@ TokenPay
## 打赏
如果该项目对您有所帮助,希望可以请我喝一杯咖啡☕️
```
USDT-TRC20打赏地址: TQWM6cuy6YesssqqzSucoUkS1A11kAAAAA
USDT-TRC20打赏地址: TKGTx4pCKiKQbk8evXHTborfZn754TGViP
```
<img src="Wiki/imgs/usdt_thanks.jpg" width = "400" alt="usdt扫码打赏"/>

Expand Down
6 changes: 3 additions & 3 deletions README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

## TokenPay - `Blockchain` Payment Solution

>An open source, payment solution that supports receiving `TRX`, `USDT-TRC20`, `ETH`, `USDT-ERC20`, `USDC-ERC20` and other blockchain tokens with dynamic payout addresses or static payout addresses!
>An open source payment solution that supports receiving `TRX`, `USDT-TRC20` and `ETH native coins` as well as `ETH ERC20 tokens` with dynamic or static payout addresses! Theoretically supports `all ETH-system blockchains`, common ETH-system blockchains are: `Ether (ETH)`, `Binance Smart Chain (BSC)`, `Polygon`, etc.
## AD -- Receive free international credit card
>Receive free VISA and Mastercard, recharge USDT and you can use it as you like
Expand All @@ -19,7 +19,7 @@ Come and get your international bank card that can be used for USDT!
## Project Description
- `TokenPay` is a privately deployed `blockchain` payment solution written in `C# language`.
- The project does not depend on any external resources, no need to deploy a separate `database`, uses lightweight `sqlite`, and does not require `redis`.
- Any project can be docked and easily implement `TRX`, `USDT-TRC20`, `ETH`, `USDT-ERC20`, `USDC-ERC20` collections! 😊 😊 😊 😊
- Any project can be docked to easily implement `TRX`, `USDT-TRC20` and `ETH-system native coins` as well as `ETH-system ERC20 tokens`, theoretically supporting `all ETH-system blockchain` collections! 😊 😊 😊 😊
- `TokenPay` is licensed under the terms of the [GPLv3](https://www.gnu.org/licenses/gpl-3.0.html) license.

## Project Features
Expand Down Expand Up @@ -68,7 +68,7 @@ Simple principle.
## Donate
If this project has helped you, I hope you can buy me a cup of coffee☕️
```
USDT-TRC20: TQWM6cuy6YesssqqzSucoUkS1A11kAAAAA
USDT-TRC20: TKGTx4pCKiKQbk8evXHTborfZn754TGViP
```
<img src="Wiki/imgs/usdt_thanks_en.jpg" width = "400" alt="usdt扫码打赏"/>

Expand Down
6 changes: 4 additions & 2 deletions Wiki/BT_RUN.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@

### 1. 下载release对应平台的包,解压到指定目录
### 2. 重命名`appsettings.Example.json``appsettings.json`,并修改配置文件
### 3. 为二进制文件`TokenPay`增加可执行权限
> `appsettings.json`说明参见:[appsettings.json](appsettings.md)
### 4. `宝塔应用管理器``Supervisor管理器`添加应用
### 2. 如需支持ETH系的区块链,可以重命名`EVMChains.Example.json``EVMChains.json`,并配置需要支持的区块链,配置文件中已添加`ETH``BSC``Polygon`三条区块链,如需其他ETH系的区块链可自由拓展。每条区块链配置都带有一个`Enable`参数,表示是否启用此区块链,默认的三条区块链的此项配置都为`false`,请将需要启用的区块链`Enable`参数更改为`true`
> `EVMChains.json`说明参见:[EVMChains.json](EVMChains.md)
### 3. 为二进制文件`TokenPay`增加可执行权限
### 5. `宝塔应用管理器``Supervisor管理器`添加应用
> 应用名称:TokenPay
> 运行身份:root
> 应用环境:无 (`Supervisor管理器`无此项)
Expand Down
21 changes: 21 additions & 0 deletions Wiki/EVMChains.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#`EVMChains.json`说明

### 1. ETH系区块链配置参数说明
| 字段 | 类型 | 说明 |
| ---- | ---- | ---- |
| Enable | bool | 是否启用此区块链,支持的值: `true``false` |
| ChainName | string | 区块链名称 |
| ChainNameEN | string | 区块链英文名称 |
| BaseCoin | string | 基本币名称 |
| Decimals | int | 基本币精度,如:18表示小数点后有18位,6表示小数点后有6位 |
| ApiHost | string | api请求地址 |
| ApiKey | string | api请求的授权key |
| ERC20Name | string | ERC20代币名称,比如币安的就叫`BEP-20`,而不叫`ERC20`,所以特意加了这个 |
| ERC20 | object[] | 要支持的代币 |


### 2. ETH系区块链配置代币说明
| 字段 | 类型 | 说明 |
| ---- | ---- | ---- |
| Name | string | 代币名称,不管是哪条链的USDT,都是写USDT。USDC同理,此参数会用于向OKX服务器查询币价,`填写了错误的名称会导致无法自动获取币价` |
| ContractAddress | string | 合约地址,错误的合约地址将导致收款无法回调 |
20 changes: 16 additions & 4 deletions Wiki/appsettings.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

**为保证安全性,务必修改`ApiToken`**

```json
```
{
"Serilog": {
"MinimumLevel": {
Expand All @@ -20,7 +20,6 @@
"DB": "Data Source=|DataDirectory|TokenPay.db; Pooling=true;Min Pool Size=1"
},
"TRON-PRO-API-KEY": "xxxxxx-xxxx-xxxx-xxxxxxxxxxxx", // 避免接口请求频繁被限制,此处申请 https://www.trongrid.io/dashboard/keys
"ETH-API-KEY": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", // 避免接口请求频繁被限制,此处申请 https://etherscan.io/myapikey
"BaseCurrency": "CNY", //默认货币,支持 CNY、USD、EUR、GBP、AUD、HKD、TWD、SGD
"Rate": { //汇率 设置0将使用自动汇率
"USDT": 0,
Expand All @@ -30,8 +29,10 @@
},
"ExpireTime": 1800, //单位秒
"UseDynamicAddress": false, //是否使用动态地址,设为false时,与EPUSDT表现类似;设为true时,为每个下单用户分配单独的收款地址
"TRON-Address": [ "Txxxxxx1", "Txxxxxx2" ], // UseDynamicAddress设为false时在此配置TRON收款地址
"ETH-Address": [ "0x0000001", "0x0000002" ], // UseDynamicAddress设为false时在此配置ETH收款地址
"Address": { // UseDynamicAddress设为false时在此配置TRON收款地址,EVM可以替代所有ETH系列的收款地址,支持单独配置某条链的收款地址
"TRON": [ "Txxxx1" ],
"EVM": [ "0x111" ]
},
"OnlyConfirmed": true, //默认仅查询已确认的数据,如果想要回调更快,可以设置为false
"NotifyTimeOut": 3, //异步通知超时时间
"ApiToken": "666666", //异步通知密钥,请务必修改此密钥为随机字符串,脸滚键盘即可
Expand All @@ -43,3 +44,14 @@
}
```
# FAQ
### 如果配置了多条ETH系的区块链,如何独立指定某条区块链的收款地址?
> 为这条区块链配置Address参数即可,下方示例中新增了BSC的收款地址
```
"Address": {
"TRON": [ "Txxxx1" ],
"EVM": [ "0x00001" ],
"BSC": [ "0x00002" ]
},
```
2 changes: 1 addition & 1 deletion Wiki/docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ URL: `创建订单`接口传递的`NotifyUrl`字段内的URL
| OutOrderId | string | 外部订单号,调用 `创建订单` 接口时传递的外部订单号 |
| OrderUserKey | string | 支付用户标识,调用 `创建订单` 接口时传递的支付用户标识 |
| PayTime | string | 支付时间,示例:`2022-09-15 16:00:00` |
| Currency | string | 币种,`USDT_TRC20``TRX`|
| Currency | string | 币种,`USDT_TRC20``TRX`,如配置了`EVMChains.json`,原生币格式为`EVM_[ChainNameEN]_[BaseCoin]`,ERC20代币格式为:`EVM_[ChainNameEN]_[Erc20.Name]_[ERC20Name]`,如BSC的原生币为`EVM_BSC_BNB`,BSC的USDT代币为`EVM_BSC_USDT_BEP20` |
| Amount | string | 订单金额,此金额为人民币转换为`Currency`字段指定的币种后的金额 |
| ActualAmount | string | 订单金额,此金额为人民币金额 |
| FromAddress | string | 付款地址 |
Expand Down
Binary file modified Wiki/imgs/usdt_thanks.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Wiki/imgs/usdt_thanks_en.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
64 changes: 64 additions & 0 deletions src/TokenPay/BgServices/BaseBackgroundService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;

namespace CoinListenBot.BgServices.Base
{
public abstract class BaseBackgroundService : IHostedService, IDisposable
{
private Task? _executingTask;
protected readonly string? jobName;
protected readonly ILogger? __logger;
private readonly CancellationTokenSource _stoppingCts = new CancellationTokenSource();

protected BaseBackgroundService()
{
}
protected BaseBackgroundService(string JobName, ILogger logger)
{
__logger = logger;
jobName = JobName;
}
protected abstract Task ExecuteAsync(CancellationToken stoppingToken);

public virtual Task StartAsync(CancellationToken cancellationToken)
{
if (jobName != null && __logger != null)
__logger.LogInformation("后台任务 {JobName} 已启动", jobName);

_executingTask = ExecuteAsync(_stoppingCts.Token);

if (_executingTask.IsCompleted)
{
return _executingTask;
}

return Task.CompletedTask;
}

public virtual async Task StopAsync(CancellationToken cancellationToken)
{
if (_executingTask == null)
{
return;
}

try
{
if (jobName != null && __logger != null)
__logger.LogInformation("后台任务 {JobName} 已停止", jobName);
_stoppingCts.Cancel();
}
finally
{
await Task.WhenAny(_executingTask, Task.Delay(Timeout.Infinite, cancellationToken));
}

}

public virtual void Dispose()
{
_stoppingCts.Cancel();
}
}

}
Loading

0 comments on commit 67cc11f

Please sign in to comment.