-
Notifications
You must be signed in to change notification settings - Fork 27
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
able to update DAOExt #108
Merged
Merged
Changes from 2 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
processed 9 tasks | ||
|
||
task 6 'run'. lines 65-74: | ||
{ | ||
"gas_used": 970329, | ||
"status": "Executed" | ||
} | ||
|
||
task 7 'run'. lines 76-85: | ||
{ | ||
"gas_used": 76940, | ||
"status": "Executed" | ||
} | ||
|
||
task 8 'run'. lines 87-96: | ||
{ | ||
"gas_used": 76940, | ||
"status": "Executed" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
//# init -n dev | ||
|
||
//# faucet --addr creator --amount 100000000000 | ||
|
||
//# faucet --addr alice --amount 10000000000 | ||
|
||
//# faucet --addr bob --amount 10000000000 | ||
|
||
//# publish | ||
module creator::DAOHelper { | ||
use StarcoinFramework::DAOAccount; | ||
use StarcoinFramework::DAOSpace::{Self, CapType}; | ||
use StarcoinFramework::Vector; | ||
use StarcoinFramework::Option; | ||
|
||
struct X has store, copy, drop { | ||
value: u64, | ||
} | ||
|
||
const NAME: vector<u8> = b"X"; | ||
|
||
/// directly upgrade the sender account to DAOAccount and create DAO | ||
public(script) fun create_dao( | ||
sender: signer, | ||
voting_delay: u64, | ||
voting_period: u64, | ||
voting_quorum_rate: u8, | ||
min_action_delay: u64, | ||
min_proposal_deposit: u128, ) { | ||
let dao_account_cap = DAOAccount::upgrade_to_dao(sender); | ||
|
||
|
||
//let dao_signer = DAOAccount::dao_signer(&dao_account_cap); | ||
let config = DAOSpace::new_dao_config( | ||
voting_delay, | ||
voting_period, | ||
voting_quorum_rate, | ||
min_action_delay, | ||
min_proposal_deposit, | ||
); | ||
let dao_ext = X { value: 0}; | ||
let dao_root_cap = DAOSpace::create_dao<X>(dao_account_cap, *&NAME, Option::none<vector<u8>>(), Option::none<vector<u8>>(), b"ipfs://description", dao_ext, config); | ||
DAOSpace::install_plugin_with_root_cap<X, XPlugin>(&dao_root_cap, required_caps()); | ||
|
||
DAOSpace::burn_root_cap(dao_root_cap); | ||
} | ||
|
||
struct XPlugin has store, drop {} | ||
|
||
public fun required_caps(): vector<CapType> { | ||
let caps = Vector::singleton(DAOSpace::modify_ext_cap_type()); | ||
caps | ||
} | ||
|
||
public fun modify_ext(value: u64): u64 { | ||
let witness = XPlugin {}; | ||
let ext_cap = DAOSpace::acquire_modify_ext_cap<X, XPlugin>(&witness); | ||
let X { value } = DAOSpace::modify_ext_with_cap<X, XPlugin>(&ext_cap, X { value }); | ||
value | ||
} | ||
} | ||
|
||
//# block --author 0x1 --timestamp 86400000 | ||
|
||
//# run --signers creator | ||
script { | ||
use creator::DAOHelper; | ||
|
||
fun main(sender: signer) { | ||
// time unit is millsecond | ||
DAOHelper::create_dao(sender, 10000, 3600000, 2, 10000, 10); | ||
} | ||
} | ||
// check: EXECUTED | ||
|
||
//# run --signers alice | ||
script { | ||
use creator::DAOHelper; | ||
|
||
fun main(_sender: signer) { | ||
let ext_value = DAOHelper::modify_ext(123); | ||
assert!(ext_value == 0, 101); | ||
} | ||
} | ||
// check: EXECUTED | ||
|
||
//# run --signers bob | ||
script { | ||
use creator::DAOHelper; | ||
|
||
fun main(_sender: signer) { | ||
let ext_value = DAOHelper::modify_ext(234); | ||
assert!(ext_value == 123, 101); | ||
} | ||
} | ||
// check: EXECUTED |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
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.
这里返回
DAOT
后,应该是插件接收 DAOT,那么要求 DAOT 必须有 destroy 方法 或者 drop 能力,否则插件将无法处理这个DAOT
?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.
有道理,确实是个问题。
解决办法:
我认为方案2 似乎更可行一点?
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.
2?DAOT 本来就是 DAOT 注册那个 module 定义的,其他的插件和构造不出来。
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.
我的意思就是,每个 DAO,比如 StarcoinDAO, 如果想要修改 ext, 那定义 StarcoinDAO 的时候,就要自己自己实现相应的方法去管理 modify_ext_with_cap 返回的 StarcoinDAO,就不能再用插件了。
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.
嗯,我也是这个意思。那是不是也不需要
cap
了,直接提供modify_ext
方法就行。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.
我现在的场景是将已安装的前端插件挂载到 DaoExt 中,后续添加前端插件可以更新就行
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.
这样是不是可以增加一个 vector<plugin_module> 结构,内部只保存一些字符串(安装的前端插件名、对应的合约插件名等)
可以配合新增加的
TypeInfo module
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.
看起来除了更新插件,应该还有读取 DAOExt 的需求? 你其实是想把合约当成一个数据库,用来存储前端插件,并提供读取,写入的功能?类似于下面这样的使用过程:
DAOSpace 不能直接读取和更新 DAOExt 的内容,只有把里面的 DAOExt 里面的struct 拿出来,你自己 DAO 里更新ext 的内容后再存回去。
这样的话也可以直接在你的模板 DAO 里面的,新增一个 struct 来管理就可以了。
@WGB5445 应该也是这个意思吧?
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.
@yubing744 既然这期打算同时考虑前端插件,那不如把前端插件的部分需求也直接定义在 DAOSpace 里?
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.
后面是计划时将前端插件直接集成进DAOSpace,但是能修改DAOExt应该是一个通用需求