merge transactions and update
This commit is contained in:
@@ -6,10 +6,10 @@ import (
|
||||
)
|
||||
|
||||
type IChainServer interface {
|
||||
AddAddress(address string, msg any) error
|
||||
RemoveAddress(address string) error
|
||||
Listen(symbol string, ch chan any)
|
||||
Transfer(symbol string, msg any) error
|
||||
AddAddress(msg any) error
|
||||
RemoveAddress(msg any) error
|
||||
Listen(ch chan any)
|
||||
Transfer(msg any) error
|
||||
Stop()
|
||||
}
|
||||
|
||||
@@ -30,40 +30,40 @@ func (b *BlockChainServer) RegisterChain(name string, chain IChainServer) {
|
||||
b.chains[name] = chain
|
||||
}
|
||||
|
||||
func (b *BlockChainServer) AddAddress(chain, address string, msg any) error {
|
||||
func (b *BlockChainServer) AddAddress(chain string, msg any) error {
|
||||
if srv, ok := b.chains[chain]; ok {
|
||||
srv.AddAddress(address, msg)
|
||||
fmt.Printf("✅ 添加监听地址: chain=%s, address=%s\n", chain, address)
|
||||
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, address string) error {
|
||||
func (b *BlockChainServer) RemoveAddress(chain string, msg any) error {
|
||||
if srv, ok := b.chains[chain]; ok {
|
||||
srv.RemoveAddress(address)
|
||||
fmt.Printf("🗑️ 移除监听地址: chain=%s, address=%s\n", chain, address)
|
||||
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, symbol string, ch chan any) error {
|
||||
func (b *BlockChainServer) Listen(chain string, ch chan any) error {
|
||||
if srv, ok := b.chains[chain]; ok {
|
||||
go func() {
|
||||
srv.Listen(symbol, ch)
|
||||
srv.Listen(ch)
|
||||
}()
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("链未注册: %s", chain)
|
||||
}
|
||||
|
||||
func (b *BlockChainServer) Transfer(chain, symbol string, msg any) error {
|
||||
func (b *BlockChainServer) Transfer(chain string, msg any) error {
|
||||
if srv, ok := b.chains[chain]; ok {
|
||||
fmt.Printf("💸 %s-%s发起转账: %+v\n", chain, symbol, msg)
|
||||
return srv.Transfer(symbol, msg)
|
||||
fmt.Printf("💸 %s发起转账: %+v\n", chain, msg)
|
||||
return srv.Transfer(msg)
|
||||
}
|
||||
return fmt.Errorf("链未注册: %s", chain)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user