mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 02:12:23 +00:00
allows client to send a signed transaction then call ethclient to send the transaction
This commit is contained in:
parent
3bdc44aaa5
commit
62f13352bb
1 changed files with 31 additions and 2 deletions
|
|
@ -16,6 +16,8 @@ import (
|
|||
"context"
|
||||
"time"
|
||||
"sync"
|
||||
"github.com/ShyftNetwork/go-empyrean/core/types"
|
||||
"github.com/ShyftNetwork/go-empyrean/rlp"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
@ -63,15 +65,18 @@ func handleRequest(conn net.Conn) {
|
|||
|
||||
messages := make(chan []byte)
|
||||
checkBalanceChan := make(chan []byte)
|
||||
sendTransactionChan := make(chan []byte)
|
||||
|
||||
|
||||
go readerConn(conn, messages)
|
||||
go handleMessages(messages, checkBalanceChan)
|
||||
go handleMessages(messages, checkBalanceChan, sendTransactionChan)
|
||||
go checkBalance(checkBalanceChan, conn)
|
||||
go sendTransaction(sendTransactionChan)
|
||||
|
||||
sendRingSignedMsg(conn)
|
||||
}
|
||||
|
||||
func handleMessages(channel chan []byte, checkBalancesChan chan []byte) {
|
||||
func handleMessages(channel chan []byte, checkBalancesChan chan []byte, sendTransactionChan chan []byte) {
|
||||
var prevMsg []byte
|
||||
var addressOfClient []byte
|
||||
var signatureFromClient []byte
|
||||
|
|
@ -92,6 +97,9 @@ func handleMessages(channel chan []byte, checkBalancesChan chan []byte) {
|
|||
fmt.Println("putting on channel 3")
|
||||
checkBalancesChan <- msg
|
||||
}
|
||||
if s == "-- SEND_TRANSACTION --" {
|
||||
sendTransactionChan <- msg
|
||||
}
|
||||
if s == "-- SIGNATURE --" {
|
||||
signatureFromClient = msg
|
||||
}
|
||||
|
|
@ -185,6 +193,27 @@ func checkBalance(checkBalanceChan chan []byte, conn net.Conn) {
|
|||
}
|
||||
}
|
||||
|
||||
func sendTransaction(sendTransactionChan chan []byte) {
|
||||
fmt.Println("in sendTransaction function")
|
||||
c, err := ethclient.Dial("http://127.0.0.1:8545")
|
||||
if err != nil {
|
||||
fmt.Println("Eth Client not initialized: " , err)
|
||||
}
|
||||
|
||||
for {
|
||||
signedTransactionBytes := <-sendTransactionChan
|
||||
signedTransaction := string(signedTransactionBytes[:])
|
||||
bytes, err := hexutil.Decode(signedTransaction)
|
||||
if err != nil {
|
||||
fmt.Println("error decoding signed transaction into bytes ", bytes)
|
||||
}
|
||||
var tx types.Transaction
|
||||
rlp.DecodeBytes(bytes, &tx)
|
||||
fmt.Println(tx.String())
|
||||
c.SendTransaction(context.Background(), &tx)
|
||||
}
|
||||
}
|
||||
|
||||
func sendRingSignedMsg(conn net.Conn){
|
||||
key, _ := crypto.HexToECDSA(testPrivHex)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue