Transaction queue: return new tx hash
This commit is contained in:
parent
4635ced174
commit
a1b02b8792
|
@ -132,15 +132,16 @@ func onSendTransactionRequest(queuedTx les.QueuedTx) {
|
||||||
C.GethServiceSignalEvent(C.CString(string(body)))
|
C.GethServiceSignalEvent(C.CString(string(body)))
|
||||||
}
|
}
|
||||||
|
|
||||||
func completeTransaction(hash string) error {
|
func completeTransaction(hash string) (common.Hash, error) {
|
||||||
if currentNode != nil {
|
if currentNode != nil {
|
||||||
|
|
||||||
if lightEthereum != nil {
|
if lightEthereum != nil {
|
||||||
backend := lightEthereum.StatusBackend
|
backend := lightEthereum.StatusBackend
|
||||||
|
|
||||||
return backend.CompleteQueuedTransaction(les.QueuedTxHash(hash))
|
return backend.CompleteQueuedTransaction(les.QueuedTxHash(hash))
|
||||||
}
|
}
|
||||||
return errors.New("Could not retrieve light ethereum service")
|
|
||||||
|
return common.Hash{}, errors.New("can not retrieve LES service")
|
||||||
}
|
}
|
||||||
|
|
||||||
return errors.New("No running node detected for account unlock")
|
return common.Hash{}, errors.New("can not complete transaction: no running node detected")
|
||||||
}
|
}
|
||||||
|
|
|
@ -107,14 +107,17 @@ func TestAccountBindings(t *testing.T) {
|
||||||
sentinel := 0
|
sentinel := 0
|
||||||
backend.SetTransactionQueueHandler(func(queuedTx les.QueuedTx) {
|
backend.SetTransactionQueueHandler(func(queuedTx les.QueuedTx) {
|
||||||
glog.V(logger.Info).Infof("Queued transaction hash: %v\n", queuedTx.Hash.Hex())
|
glog.V(logger.Info).Infof("Queued transaction hash: %v\n", queuedTx.Hash.Hex())
|
||||||
if err := completeTransaction(queuedTx.Hash.Hex()); err != nil {
|
var txHash common.Hash
|
||||||
|
if txHash, err = completeTransaction(queuedTx.Hash.Hex()); err != nil {
|
||||||
t.Errorf("Test failed: cannot complete queued transation[%s]: %v", queuedTx.Hash.Hex(), err)
|
t.Errorf("Test failed: cannot complete queued transation[%s]: %v", queuedTx.Hash.Hex(), err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
glog.V(logger.Info).Infof("Transaction complete: https://testnet.etherscan.io/tx/%s", txHash.Hex())
|
||||||
sentinel = 1
|
sentinel = 1
|
||||||
})
|
})
|
||||||
|
|
||||||
// try completing non-existing transaction
|
// try completing non-existing transaction
|
||||||
if err := completeTransaction("0x1234512345123451234512345123456123451234512345123451234512345123"); err == nil {
|
if _, err := completeTransaction("0x1234512345123451234512345123456123451234512345123451234512345123"); err == nil {
|
||||||
t.Errorf("Test failed: error expected and not recieved")
|
t.Errorf("Test failed: error expected and not recieved")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -65,7 +65,7 @@ func UnlockAccount(address, password *C.char, seconds int) *C.char {
|
||||||
|
|
||||||
//export CompleteTransaction
|
//export CompleteTransaction
|
||||||
func CompleteTransaction(hash *C.char) *C.char {
|
func CompleteTransaction(hash *C.char) *C.char {
|
||||||
err := completeTransaction(C.GoString(hash))
|
txHash, err := completeTransaction(C.GoString(hash))
|
||||||
|
|
||||||
errString := emptyError
|
errString := emptyError
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -73,7 +73,8 @@ func CompleteTransaction(hash *C.char) *C.char {
|
||||||
errString = err.Error()
|
errString = err.Error()
|
||||||
}
|
}
|
||||||
|
|
||||||
out := JSONError{
|
out := CompleteTransactionResult{
|
||||||
|
Hash: txHash.Hex(),
|
||||||
Error: errString,
|
Error: errString,
|
||||||
}
|
}
|
||||||
outBytes, _ := json.Marshal(&out)
|
outBytes, _ := json.Marshal(&out)
|
||||||
|
|
|
@ -38,6 +38,11 @@ type SendTransactionEvent struct {
|
||||||
Args les.SendTxArgs `json:"args"`
|
Args les.SendTxArgs `json:"args"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type CompleteTransactionResult struct {
|
||||||
|
Hash string `json:"hash"`
|
||||||
|
Error string `json:"error"`
|
||||||
|
}
|
||||||
|
|
||||||
type GethEvent struct {
|
type GethEvent struct {
|
||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
Event interface{} `json:"event"`
|
Event interface{} `json:"event"`
|
||||||
|
|
9
src/vendor/github.com/ethereum/go-ethereum/les/status_backend.go
generated
vendored
9
src/vendor/github.com/ethereum/go-ethereum/les/status_backend.go
generated
vendored
|
@ -4,12 +4,12 @@ import (
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
"errors"
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/internal/ethapi"
|
"github.com/ethereum/go-ethereum/internal/ethapi"
|
||||||
"github.com/ethereum/go-ethereum/logger"
|
"github.com/ethereum/go-ethereum/logger"
|
||||||
"github.com/ethereum/go-ethereum/logger/glog"
|
"github.com/ethereum/go-ethereum/logger/glog"
|
||||||
"github.com/ethereum/go-ethereum/rpc"
|
"github.com/ethereum/go-ethereum/rpc"
|
||||||
"errors"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -102,14 +102,13 @@ func (b *StatusBackend) SendTransaction(ctx context.Context, args SendTxArgs) er
|
||||||
}
|
}
|
||||||
|
|
||||||
// CompleteQueuedTransaction wraps call to PublicTransactionPoolAPI.CompleteQueuedTransaction
|
// CompleteQueuedTransaction wraps call to PublicTransactionPoolAPI.CompleteQueuedTransaction
|
||||||
func (b *StatusBackend) CompleteQueuedTransaction(hash QueuedTxHash) error {
|
func (b *StatusBackend) CompleteQueuedTransaction(hash QueuedTxHash) (common.Hash, error) {
|
||||||
queuedTx, err := b.txEvictingQueue.getQueuedTransaction(hash)
|
queuedTx, err := b.txEvictingQueue.getQueuedTransaction(hash)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return common.Hash{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = b.txapi.CompleteQueuedTransaction(context.Background(), ethapi.SendTxArgs(queuedTx.Args))
|
return b.txapi.CompleteQueuedTransaction(context.Background(), ethapi.SendTxArgs(queuedTx.Args))
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetTransactionQueue wraps call to PublicTransactionPoolAPI.GetTransactionQueue
|
// GetTransactionQueue wraps call to PublicTransactionPoolAPI.GetTransactionQueue
|
||||||
|
|
Loading…
Reference in a new issue