Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
dshulyak committed Jan 23, 2018
1 parent 820a67a commit 4dd9212
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 22 deletions.
2 changes: 1 addition & 1 deletion geth/common/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,6 @@ func CreateTransaction(ctx context.Context, args SendTxArgs) *QueuedTx {
Hash: common.Hash{},
Context: ctx,
Args: args,
Done: make(chan struct{}, 1),
Done: make(chan struct{}),
}
}
30 changes: 16 additions & 14 deletions geth/transactions/notifications.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package transactions

import (
"strconv"

"github.com/ethereum/go-ethereum/accounts/keystore"
"github.com/status-im/status-go/geth/common"
"github.com/status-im/status-go/geth/log"
Expand All @@ -13,15 +15,17 @@ const (
EventTransactionQueued = "transaction.queued"
// EventTransactionFailed is triggered when send transaction request fails
EventTransactionFailed = "transaction.failed"
)

SendTransactionNoErrorCode = "0"
SendTransactionDefaultErrorCode = "1"
SendTransactionPasswordErrorCode = "2"
SendTransactionTimeoutErrorCode = "3"
SendTransactionDiscardedErrorCode = "4"
const (
SendTransactionNoErrorCode = iota
SendTransactionDefaultErrorCode
SendTransactionPasswordErrorCode
SendTransactionTimeoutErrorCode
SendTransactionDiscardedErrorCode
)

var txReturnCodes = map[error]string{ // deliberately strings, in case more meaningful codes are to be returned
var txReturnCodes = map[error]int{ // deliberately strings, in case more meaningful codes are to be returned
nil: SendTransactionNoErrorCode,
keystore.ErrDecrypt: SendTransactionPasswordErrorCode,
queue.ErrQueuedTxTimedOut: SendTransactionTimeoutErrorCode,
Expand Down Expand Up @@ -59,29 +63,27 @@ type ReturnSendTransactionEvent struct {

// NotifyOnReturn returns handler that processes responses from internal tx manager
func NotifyOnReturn(queuedTx *common.QueuedTx) {
if queuedTx.Err == nil {
return
}

// discard notifications with empty tx
if queuedTx == nil {
return
}

// error occurred, signal up to application
// we don't want to notify a user if tx sent successfully
if queuedTx.Err == nil {
return
}
signal.Send(signal.Envelope{
Type: EventTransactionFailed,
Event: ReturnSendTransactionEvent{
ID: string(queuedTx.ID),
Args: queuedTx.Args,
MessageID: common.MessageIDFromContext(queuedTx.Context),
ErrorMessage: queuedTx.Err.Error(),
ErrorCode: sendTransactionErrorCode(queuedTx.Err),
ErrorCode: strconv.Itoa(sendTransactionErrorCode(queuedTx.Err)),
},
})
}

func sendTransactionErrorCode(err error) string {
func sendTransactionErrorCode(err error) int {
if code, ok := txReturnCodes[err]; ok {
return code
}
Expand Down
6 changes: 3 additions & 3 deletions geth/transactions/queue/queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ type TxQueue struct {
}

// NewTransactionQueue make new transaction queue
func NewQueue() *TxQueue {
func New() *TxQueue {
log.Info("initializing transaction queue")
return &TxQueue{
transactions: make(map[common.QueuedTxID]*common.QueuedTx),
Expand Down Expand Up @@ -210,13 +210,13 @@ func (q *TxQueue) done(tx *common.QueuedTx, hash gethcommon.Hash, err error) {
if err == nil {
q.remove(tx.ID)
tx.Hash = hash
tx.Done <- struct{}{}
close(tx.Done)
return
}
_, transient := transientErrs[err.Error()]
if !transient {
q.remove(tx.ID)
tx.Done <- struct{}{}
close(tx.Done)
}
}

Expand Down
2 changes: 1 addition & 1 deletion geth/transactions/queue/queue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type QueueTestSuite struct {
}

func (s *QueueTestSuite) SetupTest() {
s.queue = NewQueue()
s.queue = New()
s.queue.Start()
}

Expand Down
2 changes: 1 addition & 1 deletion geth/transactions/txqueue_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func NewManager(nodeManager common.NodeManager, accountManager common.AccountMan
return &Manager{
nodeManager: nodeManager,
accountManager: accountManager,
txQueue: queue.NewQueue(),
txQueue: queue.New(),
addrLock: &AddrLocker{},
notify: true,
}
Expand Down
4 changes: 2 additions & 2 deletions lib/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -1056,7 +1056,7 @@ func testDiscardTransaction(t *testing.T) bool { //nolint: gocyclo
}

receivedErrCode := event["error_code"].(string)
if receivedErrCode != transactions.SendTransactionDiscardedErrorCode {
if receivedErrCode != strconv.Itoa(transactions.SendTransactionDiscardedErrorCode) {
t.Errorf("unexpected error code received: got %v", receivedErrCode)
return
}
Expand Down Expand Up @@ -1143,7 +1143,7 @@ func testDiscardMultipleQueuedTransactions(t *testing.T) bool { //nolint: gocycl
}

receivedErrCode := event["error_code"].(string)
if receivedErrCode != transactions.SendTransactionDiscardedErrorCode {
if receivedErrCode != strconv.Itoa(transactions.SendTransactionDiscardedErrorCode) {
t.Errorf("unexpected error code received: got %v", receivedErrCode)
return
}
Expand Down

0 comments on commit 4dd9212

Please sign in to comment.