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

swap: createCheque refactor#1677

Merged
mortelli merged 6 commits intoincentivesfrom
incentives_createCheque-refactor
Aug 16, 2019
Merged

swap: createCheque refactor#1677
mortelli merged 6 commits intoincentivesfrom
incentives_createCheque-refactor

Conversation

@mortelli
Copy link
Copy Markdown
Contributor

This PR addresses the comment originally posted by @zelig in PR #1554:

this is massively redundant and too complex.

loadLastSentCheque should be part of getCheque and here you only need the last values for serial number and cumulative amount.

So something like this:

serial, total, err := p.getLastChequeValues() // this simply returns 0, 0 if first cheque for peer
if err != nil {
   return nil, err
}
cheque := &Cheque{
   Params: &Params{
      Serial: serial + 1,
      Amount: total + amount,
      Timeout: defaultCashInDelay,
      Contract:  s.owner.Contract,
      Honey:  honey,
    },
    Beneficiary: beneficiary,
}
return cheque.Sign(s.owner.PrivateKey)

Copy link
Copy Markdown
Member

@ralph-pichler ralph-pichler left a comment

Choose a reason for hiding this comment

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

LGTM

swap/cheque.go Outdated
}

// Sign signs the cheque with supplied private key
// Sign returns a signature for the cheque with supplied private key
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Isn't it more correct to say something that it returns the signed cheque? Not really "just" a signature

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

where is the cheque returned, though?

Copy link
Copy Markdown
Contributor Author

@mortelli mortelli Aug 16, 2019

Choose a reason for hiding this comment

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

updated signature comment

}

func (s *Swap) getLastChequeValues(peer enode.ID) (serial, total uint64, err error) {
err = s.loadLastSentCheque(peer)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Maybe we can just return here, if there is an error, why also do getCheque and the rest?

Copy link
Copy Markdown
Contributor Author

@mortelli mortelli Aug 16, 2019

Choose a reason for hiding this comment

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

  • would we check for err != nil here, or also err != state.ErrNotFound?
  • if we take this function by itself–in the case that loadLastSentCheque fails, would we still want the lastCheque fields if exists == true?

Copy link
Copy Markdown
Contributor Author

@mortelli mortelli Aug 16, 2019

Choose a reason for hiding this comment

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

added err check with return statement

Copy link
Copy Markdown
Contributor

@holisticode holisticode left a comment

Choose a reason for hiding this comment

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

OK from my side, a minor textual thing and a code adjustment I leave to your judgement what you want to do with it

@mortelli mortelli merged commit 5f86a8e into incentives Aug 16, 2019
holisticode pushed a commit that referenced this pull request Aug 20, 2019
* swap: add getLastChequeValues function

* swap: iterate getLastChequeValues function

* swap: refactor createCheque

* swap: update comment for cheque Sign function

* swap: update cheque Sign function comment

* swap: add err check in getLastChequeValues function
holisticode pushed a commit that referenced this pull request Aug 26, 2019
* swap: add getLastChequeValues function

* swap: iterate getLastChequeValues function

* swap: refactor createCheque

* swap: update comment for cheque Sign function

* swap: update cheque Sign function comment

* swap: add err check in getLastChequeValues function
holisticode pushed a commit that referenced this pull request Aug 27, 2019
* swap: add getLastChequeValues function

* swap: iterate getLastChequeValues function

* swap: refactor createCheque

* swap: update comment for cheque Sign function

* swap: update cheque Sign function comment

* swap: add err check in getLastChequeValues function
@holisticode holisticode deleted the incentives_createCheque-refactor branch September 2, 2019 15:22
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.

3 participants