Skip to content
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

community announcement via community factory contract #79

Merged
merged 16 commits into from
Jan 8, 2024
Merged

Conversation

ailisp
Copy link
Collaborator

@ailisp ailisp commented Dec 14, 2023

It works on manual testing on testnet.

Basically this pr

  • add a simple community factory and a community contract.
  • in create_community, create foo.communities.devhub.near account, add access key, deploy contract, grant social db access to devhub.near
  • in update_community, call social.near to update profile name and image is updated
  • in delete community, call foo.communities.devhub.near to self destroy

TODO:

  • add back community_addon and update_community test as workspace test because unit test no longer work due to cross contract call in create_community
  • add workspace tests for this PR
  • (After this PR approved) manual deploy community factory to community.devhub.near and manual call create_community_account for existing communities.

Note: doing migration and self-upgrade community factory similar to main contract should work, but I think it doesn't worth the effort:

  • These contracts are unlikely need to be changed it has granted full social db write access to devhub.near.
  • And it's also not a real migration: we can add create factory account, deploy factory contract and create_community_accounts as a migration, but it doesn't actually migrate any state.
  • Self-upgrade needs more thought. Most of time factory contract is not changed, we should detect this to prevent unnecessary self upgrade on every commit. We'll also need to all update community contracts that deployed by the factory contract, but factory contract doesn't keep track of that, only devhub contract does. So this has to be implement on devhub contract and considering gas limit. It will be much easier to upgrade with a client side script.

Copy link
Collaborator

@frol frol left a comment

Choose a reason for hiding this comment

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

Nice! It feels it is 80% done

src/lib.rs Outdated Show resolved Hide resolved
@ailisp ailisp marked this pull request as ready for review December 18, 2023 12:09
@ailisp
Copy link
Collaborator Author

ailisp commented Dec 18, 2023

@frol PTAL. If it looks good, please approve and I'll do the manual migration, then merge PR. Otherwise I'll first address your concerns.

The discussions part is awaiting requirements from Ori. Based on current requirement, my understanding is that's an indexer side thing (people add social db post with extra info to link it to an community, and frontend load these posts rendering in discussion), so won't require changes here.

src/community/mod.rs Outdated Show resolved Hide resolved
src/lib.rs Outdated Show resolved Hide resolved
src/lib.rs Outdated Show resolved Hide resolved
@ailisp
Copy link
Collaborator Author

ailisp commented Dec 19, 2023

@elliotBraem I end up rename add_community_announcement to set_community_socialdb, the interface is as you imagined above.

@frol
Copy link
Collaborator

frol commented Dec 21, 2023

Based on current requirement, my understanding is that's an indexer side thing (people add social db post with extra info to link it to an community, and frontend load these posts rendering in discussion), so won't require changes here.

@ailisp I would just make it part of the UI implementation, so in order to start a discussion:

  1. DevHub's component will help the users prepare a post to their social DB feed (nothing special)
  2. On successful publishing, DevHub's component will make Near.call('devhub.near', 'add_community_discussion', {"community_handle": "protocol", "social_db_post_reference": ...}) (I did not put too much thought into the naming, please, consider to have better names whenever needed), so it will be a user action to "re-share" the post to community discussions. This will even allow to implement re-sharing the same post to several communities while keeping likes and comments in one place.

frol
frol previously approved these changes Dec 21, 2023
Copy link
Collaborator

@frol frol left a comment

Choose a reason for hiding this comment

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

@ailisp I have updated GitHub CI environment variable NEAR_GIGSBOARD_ACCOUNT_ID to point to devhub.near instead of devgovgigs.near, so merging this PR won't change the production contract, instead, we can start working on slowly migrating everything over to the new contract.

community-factory/src/lib.rs Outdated Show resolved Hide resolved
Comment on lines +27 to +28
let community_account_id: AccountId =
format!("{}.{}", community, env::current_account_id()).parse().unwrap();
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is also a good candidate for a dedicated method in near-account-id: near/near-account-id-rs#23

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah this helper is also neat

community/Cargo.toml Outdated Show resolved Hide resolved
community/src/lib.rs Outdated Show resolved Hide resolved
community/src/social_db.rs Outdated Show resolved Hide resolved
@elliotBraem
Copy link
Contributor

@ailisp I've been setting up the develop branch for Announcements, it's configured with bodevhub.testnet.

So far, I'm facing an issue where get_all_communities_metadata is giving an error:

near contract call-function as-read-only bodevhub.testnet get_all_communities_metadata json-args {} network-config testnet now

Error:
   0: Failed to fetch query for view method: 'get_all_communities_metadata' (contract <bodevhub.testnet> on network <testnet>)
   1: Failed to make a view-function call
   2: handler error: [Function call returned an error: wasm execution failed with error: HostError(GuestPanic { panic_msg: "Cannot deserialize element" })]

You can see that issue here, as no communities are showing. If it is fixed and contract is upgraded, then this page should successfully show communities. Not sure if it's bad data or something with the PR

Otherwise, creating community is working after attaching 2N and get_community has no issue: see here

@ailisp
Copy link
Collaborator Author

ailisp commented Jan 2, 2024

@elliotBraem I see what happened. There is a community created before a schema-breaking change. And I forgot to run migration before adding new communities. Let me fix it

UPDATE: fixed. but i cleared the communities. You will need to recreate communities.

@ailisp
Copy link
Collaborator Author

ailisp commented Jan 3, 2024

Hi @elliotBraem I make some refactors to make the contract work on both mainnet & testnet.

And redeploy a version to bodevhub.testnet & community.bodevhub.testnet. Please test again with frontend.

For your convenience, here is my testing command for create community and add announcement:

near-cli contract call-function as-transaction bodevhub.testnet create_community json-args '{"inputs":{"handle":"zkp5","name":"zeroknowledge","tag":"zerok","description":"aaaaaa","logo_url":"http://example.com","banner_url":"http://example.com","bio_markdown":"bbb"}}' prepaid-gas '50.000 TeraGas' attached-deposit '2 NEAR' sign-as az233.testnet network-config testnet sign-with-macos-keychain send

near-cli contract call-function as-transaction bodevhub.testnet set_community_socialdb json-args '{"handle":"zkp5","data":{"post":{"main":"{\"type\":\"md\",\"text\":\"whats happening\"}"}}}' prepaid-gas '30.000 TeraGas' attached-deposit '0 NEAR' sign-as az233.testnet network-config testnet sign-with-macos-keychain send

@ailisp ailisp merged commit d956d42 into main Jan 8, 2024
1 check passed
@ailisp ailisp deleted the announcement branch January 8, 2024 08:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants