Skip to content
This repository has been archived by the owner on Feb 23, 2023. It is now read-only.

Replace pseudocode CAP-33 examples with real SDK code. #254

Merged
merged 6 commits into from
Oct 15, 2020

Conversation

Shaptic
Copy link
Contributor

@Shaptic Shaptic commented Oct 7, 2020

This adds code samples for the following:

  • sponsoring a trustline
  • transferring sponsorship to another account
  • revoking sponsorships

(as with #251, cc @sisuresh and @stellar/horizon-committers)

@stellar-jenkins
Copy link

Something went wrong with PR preview build please check

@stellar-jenkins
Copy link

@stellar-jenkins
Copy link

@Shaptic
Copy link
Contributor Author

Shaptic commented Oct 7, 2020

@rice2000 @vcarl any insights as to why the preview page is rendering the examples as monospace rather than Go code? I believe I followed the format of other examples.

@vcarl
Copy link
Contributor

vcarl commented Oct 7, 2020

Ah @Shaptic looks like you need import { CodeExample } from "components/CodeExample"; at the top of the file

@rice2000
Copy link
Contributor

rice2000 commented Oct 8, 2020

This looks great to me, and I'd love to merge it ASAP, but I can't verify the code myself. @Shaptic do you need a set of eyes on it or have you tested it and verified that it works?

Copy link
Contributor

@sisuresh sisuresh left a comment

Choose a reason for hiding this comment

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

Added a couple comments. I don't know go so let me know if my comments don't make sense.

sponsorTrustline := []txnbuild.Operation{
&txnbuild.BeginSponsoringFutureReserves{
SourceAccount: &s1Account,
SponsoredID: sponsoredAccount,
Copy link
Contributor

Choose a reason for hiding this comment

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

Should sponsoredAccount be aAccount here? If so, the other uses of sponsoredAccount should probably be updated to the corresponding account as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

aAccount is the full key-pair, whereas sponsoredAccount is just its public key (you can see sponsoredAccount := aAccount.Address() happen earlier). I figured it was a more descriptive variable name, but would you say it's more confusing since it implies a difference between the two?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah I see. Yeah I was a little confused about what was going on here, but that's my fault for not clearly reading the preamble. I think the example would be easier to understand if you just used A.Address() though. That line already specifies that you're setting the SponsoredID, which is just another way to say sponsored account. You could add a comment to clarify that. What do you think?

Copy link
Contributor Author

@Shaptic Shaptic Oct 9, 2020

Choose a reason for hiding this comment

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

I think you're right. I was trying to figure out why I went with a separate variable in the first place and it's because of this line [L206 if the link doesn't work] (and other revocations). The Account: field should be a *string type, but you can't pass &A.Address() (I'm not sure why, pretty new to Go myself; I think it's because it's an rvalue?).

I think renaming the variable to A := aAccount.Address() will kill two birds with one stone: consolidate all references to the public key and make it clear that it's still Account A, not some newly-introduced sponsored account. Thoughts?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah that sounds like a good idea!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Had to use aAddress since A was taken lol but hopefully still gets the point across.

Line: &assets[2],
Limit: txnbuild.MaxTrustlineLimit,
},
&txnbuild.EndSponsoringFutureReserves{},
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like the transaction source account is aAccount, so the source account here doesn't have to be specified. I noticed in some of your other examples you do specify the source account even if it's equal to the transaction source account. Might be a good idea to keep the usage consistent.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call, I'll consolidate this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed, I believe

@Shaptic
Copy link
Contributor Author

Shaptic commented Oct 9, 2020

@rice2000 I'd definitely prefer another pair of eyes on it as a sanity check; I pinged the team to take a look at their leisure.

@stellar-jenkins
Copy link

@2opremio
Copy link

Sorry for arriving late. My concern about this type of documentation is, How do we prevent it from biroting? Is there a way to automatically make sure it doesn't?

@2opremio
Copy link

Sorry for arriving late. My concern about this type of documentation is, How do we prevent it from biroting? Is there a way to automatically make sure it doesn't?

Answering to myself, I have created an issue covering this at #257

Copy link

@abuiles abuiles left a comment

Choose a reason for hiding this comment

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

Looks good to me!

I think it would be helpful to include an example where you need to specify the source account in &txnbuild.EndSponsoringFutureReserves{},

It is helpful for scenarios where someone is creating a sponsored account or assuming all the costs on behalf of the sponsored account.

@Shaptic
Copy link
Contributor Author

Shaptic commented Oct 14, 2020

@abuiles, I've created #258 to get this out in the meantime. Can redirect focus to that use case after clearing my queue.

@vcarl / @rice2000 looks like we're good here!

Copy link
Contributor

@rice2000 rice2000 left a comment

Choose a reason for hiding this comment

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

Fantastic!

@rice2000 rice2000 merged commit 06edb73 into stellar:master Oct 15, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants