mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 10:22: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"
|
"context"
|
||||||
"time"
|
"time"
|
||||||
"sync"
|
"sync"
|
||||||
|
"github.com/ShyftNetwork/go-empyrean/core/types"
|
||||||
|
"github.com/ShyftNetwork/go-empyrean/rlp"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|
@ -63,15 +65,18 @@ func handleRequest(conn net.Conn) {
|
||||||
|
|
||||||
messages := make(chan []byte)
|
messages := make(chan []byte)
|
||||||
checkBalanceChan := make(chan []byte)
|
checkBalanceChan := make(chan []byte)
|
||||||
|
sendTransactionChan := make(chan []byte)
|
||||||
|
|
||||||
|
|
||||||
go readerConn(conn, messages)
|
go readerConn(conn, messages)
|
||||||
go handleMessages(messages, checkBalanceChan)
|
go handleMessages(messages, checkBalanceChan, sendTransactionChan)
|
||||||
go checkBalance(checkBalanceChan, conn)
|
go checkBalance(checkBalanceChan, conn)
|
||||||
|
go sendTransaction(sendTransactionChan)
|
||||||
|
|
||||||
sendRingSignedMsg(conn)
|
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 prevMsg []byte
|
||||||
var addressOfClient []byte
|
var addressOfClient []byte
|
||||||
var signatureFromClient []byte
|
var signatureFromClient []byte
|
||||||
|
|
@ -92,6 +97,9 @@ func handleMessages(channel chan []byte, checkBalancesChan chan []byte) {
|
||||||
fmt.Println("putting on channel 3")
|
fmt.Println("putting on channel 3")
|
||||||
checkBalancesChan <- msg
|
checkBalancesChan <- msg
|
||||||
}
|
}
|
||||||
|
if s == "-- SEND_TRANSACTION --" {
|
||||||
|
sendTransactionChan <- msg
|
||||||
|
}
|
||||||
if s == "-- SIGNATURE --" {
|
if s == "-- SIGNATURE --" {
|
||||||
signatureFromClient = msg
|
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){
|
func sendRingSignedMsg(conn net.Conn){
|
||||||
key, _ := crypto.HexToECDSA(testPrivHex)
|
key, _ := crypto.HexToECDSA(testPrivHex)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue