This repository has been archived by the owner on Aug 2, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
contract, swap, swap/txqueue: move backend into txqueue package and p…
…ass hash to WaitMined directly
- Loading branch information
1 parent
a638f1b
commit 4dd76ef
Showing
7 changed files
with
83 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package txqueue | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"time" | ||
|
||
"github.com/ethereum/go-ethereum/log" | ||
|
||
"github.com/ethereum/go-ethereum/accounts/abi/bind" | ||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/ethereum/go-ethereum/core/types" | ||
) | ||
|
||
var ( | ||
// ErrTransactionReverted is given when the transaction that cashes a cheque is reverted | ||
ErrTransactionReverted = errors.New("Transaction reverted") | ||
) | ||
|
||
// Backend wraps all methods required for contract deployment. | ||
type Backend interface { | ||
bind.ContractBackend | ||
TransactionReceipt(ctx context.Context, txHash common.Hash) (*types.Receipt, error) | ||
TransactionByHash(ctx context.Context, txHash common.Hash) (*types.Transaction, bool, error) | ||
} | ||
|
||
// WaitFunc is the default function used for waiting for a receipt of a transaction | ||
// this is overridden during in tests to automatically create a block on wait | ||
var WaitFunc = func(ctx context.Context, b Backend, hash common.Hash) (*types.Receipt, error) { | ||
queryTicker := time.NewTicker(time.Second) | ||
defer queryTicker.Stop() | ||
|
||
for { | ||
receipt, err := b.TransactionReceipt(ctx, hash) | ||
if receipt != nil { | ||
// indicate whether the transaction did not revert | ||
if receipt.Status != types.ReceiptStatusSuccessful { | ||
return nil, ErrTransactionReverted | ||
} | ||
return receipt, nil | ||
} | ||
if err != nil { | ||
log.Trace("Receipt retrieval failed", "err", err) | ||
} else { | ||
log.Trace("Transaction not yet mined") | ||
} | ||
// Wait for the next round. | ||
select { | ||
case <-ctx.Done(): | ||
return nil, ctx.Err() | ||
case <-queryTicker.C: | ||
} | ||
} | ||
} |