Skip to content
This repository has been archived by the owner on Aug 2, 2021. It is now read-only.

swap: refactor cashout logic to cashout processor #2066

Merged
merged 7 commits into from
Jan 10, 2020
Merged

Conversation

ralph-pichler
Copy link
Member

@ralph-pichler ralph-pichler commented Jan 7, 2020

This PR moves most of the cashout related logic into its own file (cashout.go) and onto its own receiver (CashoutProcessor) and splits CashChequeBeneficiary (in the contract package) into CashChequeBeneficiaryStart and CashChequeBeneficiaryResult.

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 the Swap 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:

  • puts the payout and cost estimation into its own estimatePayout function
  • introduces a maximum wait time for a transaction (DefaultTransactionTimeout)
  • introduces a test helper testDeployWithPrivateKey to make tests which don't need the full swap easier
  • introduces a test helper newSignedTestCheque to make creating signed cheques for tests easier

@@ -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
Copy link
Contributor

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"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Copy link
Contributor

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

Copy link
Member Author

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.

Copy link
Contributor

@Eknir Eknir left a 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.go Outdated Show resolved Hide resolved
swap/cashout.go Outdated Show resolved Hide resolved
swap/cashout_test.go Show resolved Hide resolved
swap/cashout_test.go Show resolved Hide resolved
swap/config.go Show resolved Hide resolved
swap/swap_test.go Outdated Show resolved Hide resolved
}

// the gas price in the simulated backend is 1 therefore the total transactionCost should be 50000 * 1 = 50000
if transactionCost != 50000 {
Copy link
Contributor

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?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -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
Copy link
Contributor

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

swap/cashout_test.go Show resolved Hide resolved
swap/cashout.go Show resolved Hide resolved
swap/config.go Show resolved Hide resolved
swap/swap.go Show resolved Hide resolved
Copy link
Contributor

@Eknir Eknir left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@ralph-pichler ralph-pichler merged commit 6e8f604 into master Jan 10, 2020
@ralph-pichler ralph-pichler deleted the swap_cashout_3 branch January 10, 2020 15:57
@acud acud added this to the 0.5.5 milestone Jan 21, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants