From a1b02b8792f185cfd96809fbd11adf90db001b54 Mon Sep 17 00:00:00 2001 From: Victor Farazdagi Date: Tue, 9 Aug 2016 19:41:42 +0300 Subject: [PATCH] Transaction queue: return new tx hash --- src/gethdep.go | 9 +++++---- src/gethdep_test.go | 7 +++++-- src/library.go | 5 +++-- src/types.go | 5 +++++ .../ethereum/go-ethereum/les/status_backend.go | 9 ++++----- 5 files changed, 22 insertions(+), 13 deletions(-) diff --git a/src/gethdep.go b/src/gethdep.go index da9154f8e..819e840c3 100644 --- a/src/gethdep.go +++ b/src/gethdep.go @@ -132,15 +132,16 @@ func onSendTransactionRequest(queuedTx les.QueuedTx) { C.GethServiceSignalEvent(C.CString(string(body))) } -func completeTransaction(hash string) error { +func completeTransaction(hash string) (common.Hash, error) { if currentNode != nil { - if lightEthereum != nil { backend := lightEthereum.StatusBackend + 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") } diff --git a/src/gethdep_test.go b/src/gethdep_test.go index 639105432..9a0bceb1f 100644 --- a/src/gethdep_test.go +++ b/src/gethdep_test.go @@ -107,14 +107,17 @@ func TestAccountBindings(t *testing.T) { sentinel := 0 backend.SetTransactionQueueHandler(func(queuedTx les.QueuedTx) { 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) } + + glog.V(logger.Info).Infof("Transaction complete: https://testnet.etherscan.io/tx/%s", txHash.Hex()) sentinel = 1 }) // 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") } diff --git a/src/library.go b/src/library.go index ca771ff47..ffdee084e 100644 --- a/src/library.go +++ b/src/library.go @@ -65,7 +65,7 @@ func UnlockAccount(address, password *C.char, seconds int) *C.char { //export CompleteTransaction func CompleteTransaction(hash *C.char) *C.char { - err := completeTransaction(C.GoString(hash)) + txHash, err := completeTransaction(C.GoString(hash)) errString := emptyError if err != nil { @@ -73,7 +73,8 @@ func CompleteTransaction(hash *C.char) *C.char { errString = err.Error() } - out := JSONError{ + out := CompleteTransactionResult{ + Hash: txHash.Hex(), Error: errString, } outBytes, _ := json.Marshal(&out) diff --git a/src/types.go b/src/types.go index 6f38cbc17..224bf1f3f 100644 --- a/src/types.go +++ b/src/types.go @@ -38,6 +38,11 @@ type SendTransactionEvent struct { Args les.SendTxArgs `json:"args"` } +type CompleteTransactionResult struct { + Hash string `json:"hash"` + Error string `json:"error"` +} + type GethEvent struct { Type string `json:"type"` Event interface{} `json:"event"` diff --git a/src/vendor/github.com/ethereum/go-ethereum/les/status_backend.go b/src/vendor/github.com/ethereum/go-ethereum/les/status_backend.go index e91574602..91e140b88 100644 --- a/src/vendor/github.com/ethereum/go-ethereum/les/status_backend.go +++ b/src/vendor/github.com/ethereum/go-ethereum/les/status_backend.go @@ -4,12 +4,12 @@ import ( "golang.org/x/net/context" "sync" + "errors" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/internal/ethapi" "github.com/ethereum/go-ethereum/logger" "github.com/ethereum/go-ethereum/logger/glog" "github.com/ethereum/go-ethereum/rpc" - "errors" ) const ( @@ -102,14 +102,13 @@ func (b *StatusBackend) SendTransaction(ctx context.Context, args SendTxArgs) er } // 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) if err != nil { - return err + return common.Hash{}, err } - _, err = b.txapi.CompleteQueuedTransaction(context.Background(), ethapi.SendTxArgs(queuedTx.Args)) - return err + return b.txapi.CompleteQueuedTransaction(context.Background(), ethapi.SendTxArgs(queuedTx.Args)) } // GetTransactionQueue wraps call to PublicTransactionPoolAPI.GetTransactionQueue