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

Daospace support plugin marketplace #116

Merged
Merged
Changes from 1 commit
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
896ca6a
feat: add dao extpoint
yubing744 Sep 5, 2022
2039a53
feat: add DAOExtensionPoint and test
yubing744 Sep 5, 2022
5c51355
feat: update DAOExt
yubing744 Sep 5, 2022
f5f15de
feat: add test for extpoint registry
yubing744 Sep 6, 2022
b0d8bc5
feat: test extpoint register and publish version
yubing744 Sep 6, 2022
39eef6b
feat: update dao_extension_point
yubing744 Sep 7, 2022
0c30fe7
feat: update dao_plugin_marketplace
yubing744 Sep 7, 2022
60d7680
feat: add test case for plugin marketplace
yubing744 Sep 8, 2022
43619d4
feat: update dao extension
yubing744 Sep 8, 2022
c36946c
feat: support star plugin
yubing744 Sep 9, 2022
8464153
feat: test star
yubing744 Sep 9, 2022
18e3732
feat: support unstar plugin
yubing744 Sep 9, 2022
782dedb
feat: add labels for plugin
yubing744 Sep 10, 2022
1f7ee30
feat: add update method for plugin
yubing744 Sep 10, 2022
248e0db
feat: add plugin events
yubing744 Sep 10, 2022
14046f0
feat: support labels for ExtPoint
yubing744 Sep 11, 2022
a3d6aa2
feat: star and unstar extpoint
yubing744 Sep 11, 2022
4ed9235
feat: test extension point owner NFT transfer
yubing744 Sep 11, 2022
b884ea9
feat: add events for operation
yubing744 Sep 11, 2022
2068b1f
feat: registry init for StdlibUpgradeScripts
yubing744 Sep 11, 2022
631dde6
Merge branch 'daospace-support-plugin-marketplace-2' into daospace-su…
yubing744 Sep 11, 2022
a3c9f21
feat: merge from main
yubing744 Sep 11, 2022
8a85e04
feat: integration Plugin Placemarket to DAOSpace
yubing744 Sep 11, 2022
9a6cec5
feat: config do_upgrade_from_v12_to_v12_1 for inner plugins
yubing744 Sep 11, 2022
79e0e72
feat: fix integration-tests fail
yubing744 Sep 12, 2022
bfc0e51
feat: merge from main
yubing744 Sep 15, 2022
6bf0ee6
Merge branch 'daospace-support-plugin-marketplace-3' into daospace-su…
yubing744 Sep 15, 2022
c0cae75
feat: remove DAOPluginMarketplace and DAOExtensionPoint script
yubing744 Sep 15, 2022
d35dd26
feat: format code
yubing744 Sep 15, 2022
5ea4714
feat: remove Star user
yubing744 Sep 15, 2022
fc0c9c7
feat: limit version count max 100
yubing744 Sep 15, 2022
ca6e7d4
feat: fix int test fail
yubing744 Sep 15, 2022
7b3e7f3
feat: fix all check about MoveAbort
yubing744 Sep 15, 2022
06d80af
feat: limit plugin version max 5
yubing744 Sep 15, 2022
701bbba
feat: limit Max version count for extension point as 99
yubing744 Sep 17, 2022
8968769
Merge branch 'daospace-support-plugin-marketplace-4' into daospace-su…
yubing744 Sep 17, 2022
fa9b41e
feat: remove plugin version from InstalledPluginInfo
yubing744 Sep 17, 2022
e4a9065
Merge branch 'daospace-support-plugin-marketplace-4' into daospace-su…
yubing744 Sep 17, 2022
e069740
feat: limit update plugin and publish plugin version in PluginT module
yubing744 Sep 17, 2022
4cb63d5
feat: merge from main
yubing744 Sep 17, 2022
22f9d61
feat: add version tag repeat check
yubing744 Sep 17, 2022
d77db90
feat: mark MoveAbort for repeat tag
yubing744 Sep 17, 2022
6cf006c
feat: remove unused check for plugin init
yubing744 Sep 17, 2022
6324806
feat: change created_at and updated_at from now_milliseconds to now_s…
yubing744 Sep 17, 2022
ccb1b64
feat: limit input string length
yubing744 Sep 17, 2022
f6cbde4
feat: update NFT image with IPFS address
yubing744 Sep 17, 2022
6809215
feat: remove SalaryGovPlugin from daospaceplugin
yubing744 Sep 18, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: update dao_plugin_marketplace
  • Loading branch information
yubing744 committed Sep 7, 2022

Unverified

This user has not yet uploaded their public signing key.
commit 0c30fe7c4a6b0c4989e39b2fe37de84275104f0a
8 changes: 7 additions & 1 deletion build/StarcoinFramework/BuildInfo.yaml
Original file line number Diff line number Diff line change
@@ -72,6 +72,12 @@ compiled_package_info:
? address: "0x00000000000000000000000000000001"
name: DAOExtensionPointScript
: StarcoinFramework
? address: "0x00000000000000000000000000000001"
name: DAOPluginMarketplace
: StarcoinFramework
? address: "0x00000000000000000000000000000001"
name: DAOPluginMarketplaceScript
: StarcoinFramework
? address: "0x00000000000000000000000000000001"
name: DAORegistry
: StarcoinFramework
@@ -312,7 +318,7 @@ compiled_package_info:
? address: "0x00000000000000000000000000000001"
name: YieldFarmingV2
: StarcoinFramework
source_digest: DF124FD5E85E5C14C6F5A21D6357616B8010396EFE2C2727CF8E96FBBB5D2622
source_digest: 562AE45A335B9D81104E0C2A4708883E709899F46A4768F3733813C39A0C89B8
build_flags:
dev_mode: false
test_mode: false
Binary file not shown.
2 changes: 2 additions & 0 deletions build/StarcoinFramework/docs/README.md
Original file line number Diff line number Diff line change
@@ -34,6 +34,8 @@ This is the root document for the Move StarcoinFramework module documentation. T
- [`0x1::DAOAccount`](DAOAccount.md#0x1_DAOAccount)
- [`0x1::DAOExtensionPoint`](DAOExtensionPoint.md#0x1_DAOExtensionPoint)
- [`0x1::DAOExtensionPointScript`](DAOExtensionPoint.md#0x1_DAOExtensionPointScript)
- [`0x1::DAOPluginMarketplace`](DAOPluginMarketplace.md#0x1_DAOPluginMarketplace)
- [`0x1::DAOPluginMarketplaceScript`](DAOPluginMarketplace.md#0x1_DAOPluginMarketplaceScript)
- [`0x1::DAORegistry`](DAORegistry.md#0x1_DAORegistry)
- [`0x1::DAOSpace`](DAOSpace.md#0x1_DAOSpace)
- [`0x1::Dao`](Dao.md#0x1_Dao)
Binary file modified build/StarcoinFramework/source_maps/GenesisSignerCapability.mvsm
Binary file not shown.
23 changes: 23 additions & 0 deletions integration-tests/daospace/dao_plugin_marketplace_init.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
processed 5 tasks

task 3 'run'. lines 7-15:
{
"gas_used": 151127,
"status": "Executed"
}

task 4 'run'. lines 17-25:
{
"gas_used": 15477,
"status": {
"MoveAbort": {
"location": {
"Module": {
"address": "0x00000000000000000000000000000001",
"name": "DAOPluginMarketplace"
}
},
"abort_code": "25606"
}
}
}
25 changes: 25 additions & 0 deletions integration-tests/daospace/dao_plugin_marketplace_init.move
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//# init -n dev

//# faucet --addr Genesis

//# faucet --addr bob --amount 2000000000

//# run --signers Genesis
script {
use StarcoinFramework::DAOPluginMarketplaceScript;

fun main(_sender: signer) {
DAOPluginMarketplaceScript::initialize();
}
}
// check: EXECUTED

//# run --signers Genesis
script {
use StarcoinFramework::DAOPluginMarketplaceScript;

fun main(_sender: signer) {
DAOPluginMarketplaceScript::initialize();
}
}
// check: EXECUTED
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//# init -n dev

//# faucet --addr Genesis

//# faucet --addr creator --amount 100000000000

//# publish
module creator::TestPlugin {
use StarcoinFramework::DAOPluginMarketplace;

struct TestPlugin has store, copy, drop {}

const NAME: vector<u8> = b"TestPlugin";

/// directly upgrade the sender account to DAOAccount and create DAO
public(script) fun initialize(sender: signer) {
DAOPluginMarketplace::register_plugin<TestPlugin>(
&sender,
NAME,
b"ipfs://description",
);
}
}

//# run --signers Genesis
script {
use StarcoinFramework::DAOPluginMarketplaceScript;

fun main(_sender: signer) {
DAOPluginMarketplaceScript::initialize();
}
}
// check: EXECUTED

//# run --signers creator
script {
use creator::TestPlugin;

fun main(sender: signer) {
TestPlugin::initialize(sender);
}
}
// check: EXECUTED
1 change: 1 addition & 0 deletions sources/GenesisSignerCapability.move
Original file line number Diff line number Diff line change
@@ -9,6 +9,7 @@ module StarcoinFramework::GenesisSignerCapability {
friend StarcoinFramework::StdlibUpgradeScripts;
friend StarcoinFramework::DAORegistry;
friend StarcoinFramework::DAOExtensionPoint;
friend StarcoinFramework::DAOPluginMarketplace;
friend StarcoinFramework::Block;


2 changes: 1 addition & 1 deletion sources/daospace/DAOExtensionPoint.move
Original file line number Diff line number Diff line change
@@ -126,7 +126,7 @@ module StarcoinFramework::DAOExtensionPoint {
let genesis_account = GenesisSignerCapability::get_genesis_signer();
move_to(&genesis_account, DAOExtensionPoint{
id: extpoint_id,
name: name,
name: name,
describe: describe,
next_version_number: 2,
versions: Vector::singleton<Version>(version),
211 changes: 211 additions & 0 deletions sources/daospace/DAOPluginMarketplace.move
Original file line number Diff line number Diff line change
@@ -0,0 +1,211 @@
module StarcoinFramework::DAOPluginMarketplace {
use StarcoinFramework::GenesisSignerCapability;
use StarcoinFramework::CoreAddresses;
use StarcoinFramework::Errors;
use StarcoinFramework::Signer;
use StarcoinFramework::Timestamp;
use StarcoinFramework::Vector;
use StarcoinFramework::NFT;
use StarcoinFramework::NFTGallery;

const ERR_ALREADY_INITIALIZED: u64 = 100;
const ERR_NOT_CONTRACT_OWNER: u64 = 101;
const ERR_NOT_FOUND_PLUGIN: u64 = 102;
const ERR_EXPECT_PLUGIN_NFT: u64 = 103;
const ERR_PLUGIN_ALREADY_EXISTS: u64 = 104;

struct PluginVersion has store {
number: u64, //Numeric version number, such as 1, 2, 3
version: vector<u8>, //Plugin version number, e.g. v0.1.1
required_caps: vector<vector<u8>>, //ability to depend
export_caps: vector<vector<u8>>, //ability to export
implement_extpoints: vector<vector<u8>>, //Implemented extension points
depend_extpoints: vector<vector<u8>>, //Dependent extension points
contract_module: vector<u8>, //Contract module, format: ${address}::${module}
js_entry_uri: vector<u8>, //Front-end JS code resource URI, for example: "https://cdn.xxxx.xxxx/xxxx/xxxxx.js"
created_at: u64, //Plugin creation time
}

struct Star has store {
addr: address, //Star's wallet address, which can be a short address, such as zhangsan.stc
created_at: u64, //creation time
}

struct Comment has store {
addr: address, //The commenter's wallet address, which can be a short address, such as zhangsan.stc
content: vector<u8>, //comments
created_at: u64, //creation time
}

struct PluginRegistry has key, store {
next_plugin_id: u64,
}

struct PluginEntry<phantom PluginT> has key, store {
id: u64, //Plugin ID
name: vector<u8>, //plugin name
describe: vector<u8>, //Plugin description
git_repo: vector<u8>, //git repository code
next_version_number: u64, //next version number
versions: vector<PluginVersion>, //All versions of the plugin
stars: vector<Star>,//All stars of the plugin
comments: vector<Comment>, //All comments for plugins
created_at: u64, //Plugin creation time
update_at: u64, //Plugin last update time
}

/// Plugin Owner NFT
struct PluginOwnerNFTMeta has copy, store, drop {
plugin_id: u64,
registry_address: address,
}

struct PluginOwnerNFTBody has store{}

struct PluginOwnerNFTMintCapHolder has key {
cap: NFT::MintCapability<PluginOwnerNFTMeta>,
nft_metadata: NFT::Metadata,
}

fun next_plugin_id(plugin_registry: &mut PluginRegistry): u64 {
let plugin_id = plugin_registry.next_plugin_id;
plugin_registry.next_plugin_id = plugin_id + 1;
plugin_id
}

fun next_plugin_version_number<PluginT>(plugin: &mut PluginEntry<PluginT>): u64 {
let version_number = plugin.next_version_number;
plugin.next_version_number = version_number + 1;
version_number
}

fun has_plugin_nft(sender_addr: address, plugin_id: u64): bool {
if (!NFTGallery::is_accept<PluginOwnerNFTMeta, PluginOwnerNFTBody>(sender_addr)) {
return false
};

let nft_infos = NFTGallery::get_nft_infos<PluginOwnerNFTMeta, PluginOwnerNFTBody>(sender_addr);
let len = Vector::length(&nft_infos);
if (len == 0) {
return false
};

let idx = len - 1;
loop {
let nft_info = Vector::borrow(&nft_infos, idx);
let (_, _, _, type_meta) = NFT::unpack_info<PluginOwnerNFTMeta>(*nft_info);
if (type_meta.plugin_id == plugin_id) {
return true
};

if (idx == 0) {
return false
};

idx = idx - 1;
}
}

fun ensure_exists_plugin_nft(sender_addr: address, plugin_id: u64) {
assert!(has_plugin_nft(sender_addr, plugin_id), Errors::invalid_state(ERR_EXPECT_PLUGIN_NFT));
}

public fun initialize() {
assert!(!exists<PluginRegistry>(CoreAddresses::GENESIS_ADDRESS()), Errors::already_published(ERR_ALREADY_INITIALIZED));
let signer = GenesisSignerCapability::get_genesis_signer();

let nft_name = b"PO";
let nft_image = b"SVG image";
let nft_description = b"The plugin owner NFT";
let basemeta = NFT::new_meta_with_image_data(nft_name, nft_image, nft_description);
let basemeta_bak = *&basemeta;
NFT::register_v2<PluginOwnerNFTMeta>(&signer, basemeta);

let nft_mint_cap = NFT::remove_mint_capability<PluginOwnerNFTMeta>(&signer);
move_to(&signer, PluginOwnerNFTMintCapHolder{
cap: nft_mint_cap,
nft_metadata: basemeta_bak,
});

move_to(&signer, PluginRegistry{
next_plugin_id: 1,
});
}

public fun register_plugin<PluginT: store>(sender: &signer, name: vector<u8>, describe: vector<u8>): u64 acquires PluginRegistry, PluginOwnerNFTMintCapHolder {
assert!(!exists<PluginEntry<PluginT>>(CoreAddresses::GENESIS_ADDRESS()), Errors::already_published(ERR_PLUGIN_ALREADY_EXISTS));
let plugin_registry = borrow_global_mut<PluginRegistry>(CoreAddresses::GENESIS_ADDRESS());
let plugin_id = next_plugin_id(plugin_registry);

let genesis_account = GenesisSignerCapability::get_genesis_signer();
move_to(&genesis_account, PluginEntry<PluginT>{
id: plugin_id,
name: name,
describe: describe,
git_repo: Vector::empty<u8>(),
next_version_number: 1,
versions: Vector::empty<PluginVersion>(),
stars: Vector::empty<Star>(),
comments: Vector::empty<Comment>(),
created_at: Timestamp::now_milliseconds(),
update_at: Timestamp::now_milliseconds(),
});

// grant owner NFT to sender
let nft_mint_cap = borrow_global_mut<PluginOwnerNFTMintCapHolder>(CoreAddresses::GENESIS_ADDRESS());
let meta = PluginOwnerNFTMeta{
registry_address: CoreAddresses::GENESIS_ADDRESS(),
plugin_id: plugin_id,
};

let nft = NFT::mint_with_cap_v2(CoreAddresses::GENESIS_ADDRESS(), &mut nft_mint_cap.cap, *&nft_mint_cap.nft_metadata, meta, PluginOwnerNFTBody{});
NFTGallery::deposit(sender, nft);

plugin_id
}

public fun publish_plugin_version<PluginT>(
sender: &signer,
plugin_id:u64,
version: vector<u8>,
required_caps: vector<vector<u8>>,
export_caps: vector<vector<u8>>,
implement_extpoints: vector<vector<u8>>,
depend_extpoints: vector<vector<u8>>,
contract_module: vector<u8>,
js_entry_uri: vector<u8>,
) acquires PluginEntry {
ensure_exists_plugin_nft(Signer::address_of(sender), plugin_id);

let plugin = borrow_global_mut<PluginEntry<PluginT>>(CoreAddresses::GENESIS_ADDRESS());

let version_number = next_plugin_version_number(plugin);
Vector::push_back<PluginVersion>(&mut plugin.versions, PluginVersion{
number: version_number,
version: version,
required_caps: required_caps,
export_caps: export_caps,
implement_extpoints: implement_extpoints,
depend_extpoints: depend_extpoints,
contract_module: contract_module,
js_entry_uri: js_entry_uri,
created_at: Timestamp::now_milliseconds(),
});
}

public fun exists_plugin_version<PluginT>(
version_number: u64,
): bool acquires PluginEntry {
let plugin = borrow_global_mut<PluginEntry<PluginT>>(CoreAddresses::GENESIS_ADDRESS());
return version_number > 0 && version_number < plugin.next_version_number
}
}


module StarcoinFramework::DAOPluginMarketplaceScript {
use StarcoinFramework::DAOPluginMarketplace;

public(script) fun initialize() {
DAOPluginMarketplace::initialize();
}
jolestar marked this conversation as resolved.
Show resolved Hide resolved
}