This repository has been archived by the owner on Aug 2, 2021. It is now read-only.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
swarm, swap: pass chequebook address at start-up #1718
swarm, swap: pass chequebook address at start-up #1718
Changes from 3 commits
9f3b920
2ce640e
596fffa
6b0b0ab
fae4caf
ff854d1
1a8d089
53d1398
9d7f449
274c1c5
81338c9
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
I find this comment to be confusing. It doesn't really create a new instance of the contract but points to an existing 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.
isn't it an instance on the go side? i.e. a new
struct
?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.
I would rename this to
BindToContractAt
or something similar. It is indeed very confusing, as it is a method onSwap
, and it is not creating a new instance ofSwap
, and, as @ralph-pichler says, not even a new contract.The comment should be changed accordingly
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.
I agree about this being confusing.
I propose to change it to:
NewInstanceAt creates a new instance of an already existing chequebook contract at address and sets chequebookAddr
What do you think?
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.
@mortelli , it is indeed only a new instance on the go-side.
To be precise:
, which is implementing the
Contract interface
(see file
contracts/swap.go
).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.
since the instance exists in the blockchain but not on the go side, maybe use
reference
instead ofinstance
; it seems talking about instances is a half-truth.@ralph-pichler any suggestions for a better comment? what do you think of @Eknir's proposal?
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.
I would definitely not use
New
.New
in go usually is used to create a new instance of the caller, not a new instance of some other object.Maybe
BindToReferenceAt
orBindToContractAt
,ContractAt
but notNew...
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.
Changed the function to
ContractAt
and updated the documentation to: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.
Final resolution: as this call is deferring to
contract.InstanceAt
, I see no reason why we would name it anything other than that.Hence, I decided to change it to:
@holisticode , tagging you, as you already gave a thumbs-up on my previous proposed solution to make it
ContractAt
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.
since
err
is implicitly initialized, you can justreturn
hereThere 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.
get rid of named paramater.
@mortelli our code policy is to write return arguments explicitly even if we have named return params
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.
I would like to keep the initialization of
err
in the function initialization, because otherwise, I can't doObviously, if it is a strict policy not to have named return parameters, I can do that, but in this case, I need 2 extra lines of code (to initialize a variable for the
contractInstance
, and assign this tos.contract
). This was how I did it initially, but @holisticode asked me to do it in a one-liner.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.
this is fine. I also like sometimes that vars are initialised,
the policy is more about not having bare
return
-s if the function has return values.it makes things more readable
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.
same here
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.
I won't change this, due to Swarm code policy. Please tell me if you disagree.
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.
I'm confused as to what the path parameter does.
Is this to satisfy a Interface?, or is it something that is not being used.
And if this is the case what would be the use of such path.
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.
I am confused about this as well. Actually removed it before when I was doing refactoring, but when I reverted the refactoring, I also left this one in now.
Tagging @holisticode , maybe he knows. I would personally remove it, as it does not seem to have a purpose
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.
if the tests pass after removing this parameter, i say let's go ahead with this change
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.
I think it would be nicer to extract this into a setup function. too much swap specific logic is here and makes swarm.go harder to read.
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.
then you can also eliminate the else-s as you just return
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!