-
Notifications
You must be signed in to change notification settings - Fork 110
swap: refactor cashout logic to cashout processor #2066
Conversation
contracts/swap/swap.go
Outdated
@@ -48,8 +49,10 @@ type Contract interface { | |||
Withdraw(auth *bind.TransactOpts, amount *big.Int) (*types.Receipt, error) | |||
// Deposit sends a raw transaction to the chequebook, triggering the fallback—depositing amount | |||
Deposit(auth *bind.TransactOpts, amout *big.Int) (*types.Receipt, error) | |||
// CashChequeBeneficiary cashes the cheque by the beneficiary | |||
CashChequeBeneficiary(auth *bind.TransactOpts, beneficiary common.Address, cumulativePayout *big.Int, ownerSig []byte) (*CashChequeResult, *types.Receipt, error) | |||
// CashChequeBeneficiaryStart sends the transaction to a cash a cheque as the beneficiary |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small typo here: "to a cash a cheque"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It still says: to a cash a cheque
. Removing the first a
would fix it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed now. the same comment existed in two places and I only had fixed one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Elegant refactoring! I left some comments for improvements and will approve once resolved
swap/cashout_test.go
Outdated
} | ||
|
||
// the gas price in the simulated backend is 1 therefore the total transactionCost should be 50000 * 1 = 50000 | ||
if transactionCost != 50000 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we extract this into a constant?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
contracts/swap/swap.go
Outdated
@@ -48,8 +49,10 @@ type Contract interface { | |||
Withdraw(auth *bind.TransactOpts, amount *big.Int) (*types.Receipt, error) | |||
// Deposit sends a raw transaction to the chequebook, triggering the fallback—depositing amount | |||
Deposit(auth *bind.TransactOpts, amout *big.Int) (*types.Receipt, error) | |||
// CashChequeBeneficiary cashes the cheque by the beneficiary | |||
CashChequeBeneficiary(auth *bind.TransactOpts, beneficiary common.Address, cumulativePayout *big.Int, ownerSig []byte) (*CashChequeResult, *types.Receipt, error) | |||
// CashChequeBeneficiaryStart sends the transaction to a cash a cheque as the beneficiary |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It still says: to a cash a cheque
. Removing the first a
would fix it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
…estDeployWithPrivateKey
b51d350
to
a148161
Compare
This PR moves most of the cashout related logic into its own file (
cashout.go
) and onto its own receiver (CashoutProcessor
) and splitsCashChequeBeneficiary
(in thecontract
package) intoCashChequeBeneficiaryStart
andCashChequeBeneficiaryResult
.This by itself does not change any functionality. The changes made here are primarily to make implementing a proper cashout queue easier (as the PR for that was getting out of hand in terms of complexity). The
CashoutProcessor
was introduced as the responsibilities of theSwap
struct are already huge and cashing is orthogonal to the rest of the swap logic.This PR introduces several structs and passes them around instead of individual parameters. The reasoning behind this is that in a later PR this structs will be persisted to the local store to allow queueing wand waiting fo cashouts across client restarts.
In addition this PR also:
estimatePayout
functionDefaultTransactionTimeout
)testDeployWithPrivateKey
to make tests which don't need the full swap easiernewSignedTestCheque
to make creating signed cheques for tests easier