update
This commit is contained in:
@@ -1,21 +1,22 @@
|
||||
// 区块链网络抽象接口统一实现
|
||||
package blockchain
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"sync"
|
||||
)
|
||||
|
||||
type IChainServer interface {
|
||||
AddAddress(msg any) error
|
||||
RemoveAddress(msg any) error
|
||||
Listen(ch chan any)
|
||||
Transfer(msg any) error
|
||||
Listen() error
|
||||
ListenMsg()
|
||||
Transfer(from, to, symbol string, amount, fee float64) error
|
||||
Stop()
|
||||
}
|
||||
|
||||
type BlockChainServer struct {
|
||||
mu sync.Mutex
|
||||
chains map[string]IChainServer // "ETH", "TRON", "BTC"
|
||||
chains map[string]IChainServer
|
||||
}
|
||||
|
||||
func NewBlockChainServer() *BlockChainServer {
|
||||
@@ -30,40 +31,41 @@ func (b *BlockChainServer) RegisterChain(name string, chain IChainServer) {
|
||||
b.chains[name] = chain
|
||||
}
|
||||
|
||||
func (b *BlockChainServer) AddAddress(chain string, msg any) error {
|
||||
if srv, ok := b.chains[chain]; ok {
|
||||
srv.AddAddress(msg)
|
||||
fmt.Printf("✅ 添加监听地址: chain=%s, msg=%v\n", chain, msg)
|
||||
return nil
|
||||
} else {
|
||||
return fmt.Errorf("⚠️ 链未注册: %s\n", chain)
|
||||
}
|
||||
}
|
||||
|
||||
func (b *BlockChainServer) RemoveAddress(chain string, msg any) error {
|
||||
if srv, ok := b.chains[chain]; ok {
|
||||
srv.RemoveAddress(msg)
|
||||
fmt.Printf("🗑️ 移除监听地址: chain=%s, msg=%s\n", chain, msg)
|
||||
return nil
|
||||
} else {
|
||||
return fmt.Errorf("⚠️ 链未注册: %s\n", chain)
|
||||
}
|
||||
}
|
||||
|
||||
func (b *BlockChainServer) Listen(chain string, ch chan any) error {
|
||||
if srv, ok := b.chains[chain]; ok {
|
||||
go func() {
|
||||
srv.Listen(ch)
|
||||
err := srv.Listen()
|
||||
if err != nil {
|
||||
log.Printf("Start Listen error: %v", err)
|
||||
return
|
||||
}
|
||||
}()
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("链未注册: %s", chain)
|
||||
}
|
||||
|
||||
func (b *BlockChainServer) Transfer(chain string, msg any) error {
|
||||
func (b *BlockChainServer) ListenMsg(chain string) error {
|
||||
if srv, ok := b.chains[chain]; ok {
|
||||
fmt.Printf("💸 %s发起转账: %+v\n", chain, msg)
|
||||
return srv.Transfer(msg)
|
||||
go func() {
|
||||
srv.ListenMsg()
|
||||
}()
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("链未注册: %s", chain)
|
||||
}
|
||||
|
||||
func (b *BlockChainServer) Transfer(chain, from, to, symbol string, amount, fee float64) error {
|
||||
if srv, ok := b.chains[chain]; ok {
|
||||
fmt.Printf("💸 发起转账: Chain(%s)-Symbol(%s), From(%s), To(%s), Amount(%f)\n", chain, symbol, from, to, amount)
|
||||
go func() {
|
||||
err := srv.Transfer(from, to, symbol, amount, fee)
|
||||
if err != nil {
|
||||
log.Printf("Transfer Error: %v\n Transfer has Exited", err)
|
||||
return
|
||||
}
|
||||
}()
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("链未注册: %s", chain)
|
||||
}
|
||||
@@ -72,6 +74,7 @@ func (b *BlockChainServer) Stop(chain string) {
|
||||
if srv, ok := b.chains[chain]; ok {
|
||||
fmt.Printf("💸 关闭服务: %+v\n", chain)
|
||||
srv.Stop()
|
||||
return
|
||||
}
|
||||
fmt.Printf("链未注册: %s", chain)
|
||||
}
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.8.0;
|
||||
|
||||
contract MultiSend {
|
||||
function multiTransfer(address[] calldata to, uint256[] calldata amounts) external payable {
|
||||
uint256 length = to.length;
|
||||
require(length == amounts.length, "Arrays must have the same length");
|
||||
|
||||
for (uint256 i = 0; i < length; i++) {
|
||||
payable(to[i]).transfer(amounts[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.8.0;
|
||||
|
||||
interface IERC20 {
|
||||
function transfer(address recipient, uint256 amount) external returns (bool);
|
||||
}
|
||||
|
||||
contract MultiSendUSDT {
|
||||
address public tokenAddress;
|
||||
|
||||
constructor(address _tokenAddress) {
|
||||
tokenAddress = _tokenAddress;
|
||||
}
|
||||
|
||||
function multiTransfer(address[] calldata to, uint256[] calldata amounts) external {
|
||||
IERC20 token = IERC20(tokenAddress);
|
||||
uint256 length = to.length;
|
||||
require(length == amounts.length, "Arrays must have the same length");
|
||||
|
||||
for (uint256 i = 0; i < length; i++) {
|
||||
token.transfer(to[i], amounts[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
1295
internal/blockchain/eth/eth_prv.go
Normal file
1295
internal/blockchain/eth/eth_prv.go
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user