-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
added discussions accounts factory to community contract #88
Conversation
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.
At first glance, it looks good to me, but it is pretty late in the night, so I will let @ailisp to review it in more details and approve it
Your approach is working, however it requires deploy a discussion contract per community. Note that it's not the public key that grant permission to write given account's social db, but it's the
Assume this method in Now from frontend, when user create a discussion, we want to post as a near social post (easy) and also repost by call But you can see there is a problem: repost requires the |
…evhub-contract into feature/584-discussions
@frol @ailisp I removed the discussions factory as discussed with @ailisp. We will look post discussions to |
@ailisp @Tguntenaar The reason I wanted to have a separate account (discussions. sub-account) is to allow users to follow only announcements if necessary, and also the global "DevHub Communities Announcements" would be just a feed of community.devhub.near account which would just follow all the announcement accounts (xxx.community.devhub.near) - we would just need to add one more call to subscribe community.devhub.near to follow all the created communities (but not discussions). @Tguntenaar I am sorry, but I would like to ask you to get the discussions factory back. Once again, I want a clear separation between announcements and discussions. This allows us to use the standard SocialDB Index API (just like Social feed does), and be completely compatible with the rest of NEAR Social ecosystem. |
@Tguntenaar Let's also extends the community tests to check that discussions are also properly configured |
This reverts commit b614ef9.
@frol @ailisp @petersalomonsen Hey guys! The discussions tests fails with the following error: So the I think it has to do with the async nature of the cross contract call which isn't returned by create_community since it is wrapped in a So a solution would be to make |
I think you need to test this in the integration test and not in the unit test. I see you are trying to call |
…re/584-discussions
…ploys two accounts instead of 1
src/lib.rs
Outdated
promise.then( | ||
ext_devhub_community::ext(get_devhub_discussions_factory(&new_community.handle)) | ||
.with_unused_gas_weight(2) | ||
.with_attached_deposit(CREATE_DISCUSSION_BALANCE) | ||
.create_discussions_account(), | ||
); |
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 suggest the community contract to create the discussion subaccount on new
instead of "micro-managing" the community implementation from the main contract.
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.
@Tguntenaar Just to clarify. I suggest to make the following separation of concerns:
- root contract only calls community factory
- community factory only initializes the "announcements" contract
- "announcements" contract initializes the "discussions" contract
Pro tip: Since you cannot return a Promise from #[init]
method in near-sdk-rs, you can use the low-level API Promise::as_result()
while still returning Contract {}
from the init function itself. (Update all init functions where it is necessary, to make Promises attached to the result status of the initialization)
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 trying to call create_discussions_account
from the init function of the "announcements" contract (3).
How can one attach a deposit? I thought an init function isn't payable.
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.
Does it have to be a method decorated with #[init]
to do the initialization? Can't it just be a regular method that you call with a #[payable]
decorator?
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.
That works indeed! I'm not sure about the impact though. I guess it won't panic if the state is already initialized.
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.
@Tguntenaar Add #[payable]
above or below the #[init]
attribute and that is it: https://github.com/near/near-sdk-rs/blob/a12da50469c4a47640b6bd71ed4b433370978821/near-sdk-macros/src/core_impl/code_generator/item_impl_info.rs#L221-L231
5d46a0c
to
de38459
Compare
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.
Looks great!
This issue is supporting PR #645
@frolvlad @ailisp I would like to get some feedback on my approach.
I assumed that in order to create
discussions.${handle}.community.devhub.near
the${handle}.community.devhub.near
account needs to be an factory in itself.I added this image help describe what I did with some common terminology.

I added a
set_discussions_community_socialdb
function so the user can post on socialdb from the devhub.near contract. This usesget_devhub_discussions_account
which retrievesdiscussions.<handle>.community.devhub.near
.To support that I added a
create_discussions_account
function to the community contract. So the community contract is in essence a discussions factory. I copied most of what was the community contract to the discussions contract with some minor tweaks since it is a level down in subaccounts.In file
community/src/lib.rs
line 9 and 70 a PUBkey from devhub.near is used to give control to make posts on socialDB.Should this be devhub.near?