Skip to content

Commit

Permalink
modify
Browse files Browse the repository at this point in the history
  • Loading branch information
goalongway committed Aug 30, 2024
1 parent f91d429 commit e361d07
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 39 deletions.
8 changes: 3 additions & 5 deletions listener/cmd/app/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ func main() {
cfg := config.LoadConfig()

db := initiates.InitDB(cfg.Database)
bitcoinRpc := initiates.InitBitcoinRpc(cfg.Bitcoin)
bsquaredRpc := initiates.InitEthereumRpc(cfg.Bsquared)
arbitrumRpc := initiates.InitEthereumRpc(cfg.Arbitrum)

Expand All @@ -24,25 +25,22 @@ func main() {

arbitrumBuilder := builder.NewBuilder(cfg.Builder.Arbitrum, cfg.Log, cfg.Arbitrum, db, arbitrumRpc)
arbitrumBuilder.Start()

// listener
//bsquaredRpc := initiates.InitEthereumRpc(cfg.Bsquared)
bsquaredListener := ethereum.NewListener(cfg.Log, cfg.Bsquared, bsquaredRpc, db)
bsquaredListener.Start()

//arbitrumRpc := initiates.InitEthereumRpc(cfg.Arbitrum)
arbitrumListener := ethereum.NewListener(cfg.Log, cfg.Arbitrum, arbitrumRpc, db)
arbitrumListener.Start()

bitcoinRpc := initiates.InitBitcoinRpc(cfg.Bitcoin)
bitcoinListener := bitcoin.NewListener(cfg.Log, cfg.Bitcoin, cfg.Particle, bitcoinRpc, db)
bitcoinListener.Start()
// validator

//bsquaredRpc := initiates.InitEthereumRpc(cfg.Bsquared)
// validator
bsquaredValidator := validator.NewValidator(cfg.Validator.Bsquared, cfg.Log, cfg.Bsquared, db, bsquaredRpc)
bsquaredValidator.Start()

//arbitrumRpc := initiates.InitEthereumRpc(cfg.Arbitrum)
arbitrumValidator := validator.NewValidator(cfg.Validator.Arbitrum, cfg.Log, cfg.Arbitrum, db, arbitrumRpc)
arbitrumValidator.Start()
select {}
Expand Down
15 changes: 8 additions & 7 deletions listener/cmd/listener/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bsquared.network/b2-message-channel-listener/internal/config"
"bsquared.network/b2-message-channel-listener/internal/initiates"
"bsquared.network/b2-message-channel-listener/internal/serves/listener/bitcoin"
"bsquared.network/b2-message-channel-listener/internal/serves/listener/ethereum"
"encoding/json"
"fmt"
"github.com/shopspring/decimal"
Expand All @@ -16,13 +17,13 @@ func main() {
fmt.Println(string(value))
db := initiates.InitDB(cfg.Database)

//bsquaredRpc := initiates.InitEthereumRpc(cfg.Bsquared)
//bsquaredListener := ethereum.NewListener(cfg.Log, cfg.Bsquared, bsquaredRpc, db)
//bsquaredListener.Start()
//
//arbitrumRpc := initiates.InitEthereumRpc(cfg.Arbitrum)
//arbitrumListener := ethereum.NewListener(cfg.Log, cfg.Arbitrum, arbitrumRpc, db)
//arbitrumListener.Start()
bsquaredRpc := initiates.InitEthereumRpc(cfg.Bsquared)
bsquaredListener := ethereum.NewListener(cfg.Log, cfg.Bsquared, bsquaredRpc, db)
bsquaredListener.Start()

arbitrumRpc := initiates.InitEthereumRpc(cfg.Arbitrum)
arbitrumListener := ethereum.NewListener(cfg.Log, cfg.Arbitrum, arbitrumRpc, db)
arbitrumListener.Start()

bitcoinRpc := initiates.InitBitcoinRpc(cfg.Bitcoin)
bitcoinListener := bitcoin.NewListener(cfg.Log, cfg.Bitcoin, cfg.Particle, bitcoinRpc, db)
Expand Down
58 changes: 33 additions & 25 deletions listener/cmd/test/main.go
Original file line number Diff line number Diff line change
@@ -1,36 +1,44 @@
package main

import (
"bsquared.network/b2-message-channel-listener/internal/utils/ethereum/message"
"crypto/ecdsa"
"bsquared.network/b2-message-channel-listener/internal/config"
"bsquared.network/b2-message-channel-listener/internal/initiates"
"encoding/json"
"fmt"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"math/big"
"github.com/shopspring/decimal"
)

func main() {

var chainId int64 = 1
var messageContract string = "0xb4a88c4086055b8f546911BaaED28b7CEE134EF9"
var fromChainId int64 = 0
fromId := big.NewInt(1)
var fromSender string = common.HexToAddress("0x0").Hex()
var toChainId int64 = 1
var contractAddress string = "0xbf99D4875C47D07Db5381c5092D669D3A0eBfB72"
var data string = "0xbee471d044748a02b1440b19e0e1b4caaccb14d3c9f6f20ec6c02a90445b34c700000000000000000000000000000000000000000000000000000000000000800000000000000000000000000b0c0149d5dbb9eec2c87cff703eadfe428df89100000000000000000000000000000000000000000000000000000000000186a0000000000000000000000000000000000000000000000000000000000000002a746231716b707464737573786b73636176756473326175646663367036377a7533726c307a6d6e377a7500000000000000000000000000000000000000000000"
var key *ecdsa.PrivateKey
key, err := crypto.ToECDSA(common.FromHex("0x67f20dc3b0842117c049b292dd88794b3321c95a1b607e735be88c34327420ba"))
signer := crypto.PubkeyToAddress(key.PublicKey).Hex()
fmt.Println("signer:", signer)

signature, err := message.SignMessageSend(chainId, messageContract, fromChainId, fromId, fromSender, toChainId, contractAddress, data, key)
if err != nil {
panic(err)
}
verify, err := message.VerifyMessageSend(chainId, messageContract, fromChainId, fromId, fromSender, toChainId, contractAddress, data, signer, signature)
decimal.DivisionPrecision = 18
cfg := config.LoadConfig()
bitcoinRpc := initiates.InitBitcoinRpc(cfg.Bitcoin)
info, err := bitcoinRpc.GetBlockChainInfo()
if err != nil {
panic(err)
}
fmt.Println("verify:", verify)
value, _ := json.Marshal(info)
fmt.Println("ChainInfo: ", string(value))
//return
//var chainId int64 = 1
//var messageContract string = "0xb4a88c4086055b8f546911BaaED28b7CEE134EF9"
//var fromChainId int64 = 0
//fromId := big.NewInt(1)
//var fromSender string = common.HexToAddress("0x0").Hex()
//var toChainId int64 = 1
//var contractAddress string = "0xbf99D4875C47D07Db5381c5092D669D3A0eBfB72"
//var data string = "0xbee471d044748a02b1440b19e0e1b4caaccb14d3c9f6f20ec6c02a90445b34c700000000000000000000000000000000000000000000000000000000000000800000000000000000000000000b0c0149d5dbb9eec2c87cff703eadfe428df89100000000000000000000000000000000000000000000000000000000000186a0000000000000000000000000000000000000000000000000000000000000002a746231716b707464737573786b73636176756473326175646663367036377a7533726c307a6d6e377a7500000000000000000000000000000000000000000000"
//var key *ecdsa.PrivateKey
//key, err := crypto.ToECDSA(common.FromHex("0x67f20dc3b0842117c049b292dd88794b3321c95a1b607e735be88c34327420ba"))
//signer := crypto.PubkeyToAddress(key.PublicKey).Hex()
//fmt.Println("signer:", signer)
//
//signature, err := message.SignMessageSend(chainId, messageContract, fromChainId, fromId, fromSender, toChainId, contractAddress, data, key)
//if err != nil {
// panic(err)
//}
//verify, err := message.VerifyMessageSend(chainId, messageContract, fromChainId, fromId, fromSender, toChainId, contractAddress, data, signer, signature)
//if err != nil {
// panic(err)
//}
//fmt.Println("verify:", verify)
}
1 change: 1 addition & 0 deletions listener/config/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ bitcoin:
ToContractAddress: 0xAaF7f27EA526B29cF4dA3b957Ed0C388070FcCE5
BtcUser: test
BtcPass: test
DisableTLS: false

bsquared:
name: bsquared
Expand Down
4 changes: 2 additions & 2 deletions listener/internal/initiates/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ func InitBitcoinRpc(config config.Blockchain) *rpcclient.Client {
Host: config.RpcUrl,
User: config.BtcUser,
Pass: config.BtcPass,
HTTPPostMode: true, // Bitcoin core only supports HTTP POST mode
DisableTLS: false, // Bitcoin core does not provide TLS by default
HTTPPostMode: true, // Bitcoin core only supports HTTP POST mode
DisableTLS: config.DisableTLS, // Bitcoin core does not provide TLS by default
}, nil)
if err != nil {
log.Panicf("client dial error: %s\n", err)
Expand Down

0 comments on commit e361d07

Please sign in to comment.