...
参数名称 | 类型 | 描述 |
---|---|---|
sender | signer | 发起方 |
state_channel_id |
| 状态通道ID |
from_height | u128 | 起始高度 |
to_height | u128 | 结束的高度 |
change_set | vector<u8> | 变更集 |
change_set 数据格式:
代码块 |
---|
{ "accounts": { "0x34561234666799440x6c31f522bb1bdc6c625f5a39ce4d8c95": { "rooch_demo::editor::Document": { } } } |
返回值:
无
业务逻辑:
发起结算提案。该方法会检查 from_height-1和状态通道中的settledHeight是否相等。
支持的提案:
...
提案Action
...
提案描述
...
SettlementAction
...
结算
...
PunishAction
...
惩罚
调用示例:
协同编辑器
代码块 |
---|
aptos move run \
--function-id rooch::state_channel::create_settlement_proposal_entry \
--type-args=rooch_demo::editor::Document \
--args=1001 1 100 b"23A145AB448872B1" |
聊天合约
代码块 |
---|
aptos move run \
--function-id rooch::state_channel::create_settlement_proposal_entry \
--type-args=rooch_demo::chat::ChatGroup \
--args=1001 1 100 b"23A145AB448872B1" |
MoveCraft合约
代码块 |
---|
aptos move run \
--function-id rooch::state_channel::create_settlement_proposal_entry \
--type-args=rooch_demo::movecraft::Land \
--args=1001 1 100 b"23A145AB448872B1" |
1.3.3 对提案进行投票
代码块 |
---|
rooch::state_channel:vote_proposal_entry |
类型参数:
...
类型参数
...
约束
...
描述
...
StateT
...
store
...
状态类型
参数:
...
参数名称
...
类型
...
描述
...
sender
...
signer
...
发起方
...
state_channel_id
...
u64
...
状态通道ID
...
proposal_id
...
u64
...
提案ID
...
vote_option
...
u8
...
投票选项:
0:反对
1: 赞成
2:弃权
返回值:
无
业务逻辑:
对提案投票。
调用示例:
协同编辑器
代码块 |
---|
aptos move run \
--function-id rooch::state_channel::vote_proposal_entry \
--type-args=rooch_demo::editor::Document \
--args=1001 1 1 |
...
`new`:[],
`modify`: ['old_doc_DATA', 'new_doc_DATA'],
`delete`: [],
}
},
"0xf1e8acab0eb5d19288fa1f68167bdee2": {
"0x1::token::Token<0x1::STC::STC>": {
`new`:[],
`modify`: [],
`delete`: [true],
}
},
}
} |
返回值:
无
业务逻辑:
发起结算提案。该方法会检查 from_height-1和状态通道中的settledHeight是否相等。
支持的提案:
提案Action | 提案描述 |
---|---|
SettlementAction | 结算 |
PunishAction | 惩罚 |
调用示例:
协同编辑器
代码块 |
---|
aptos move run \ --function-id rooch::state_channel::votecreate_settlement_proposal_entry \ --type-args=rooch_demo::chat::editor::Document \ --args=1001 1 100 b"23A145AB448872B1" |
聊天合约
代码块 |
---|
aptos move run \ --function-id rooch::state_channel::create_settlement_proposal_entry \ --type-args=rooch_demo::chat::ChatGroup \ --args=1001 1 1100 b"23A145AB448872B1" |
MoveCraft合约
代码块 |
---|
aptos move run \ --function-id rooch::state_channel::votecreate_settlement_proposal_entry \ --type-args=rooch_demo::movecraft::Land \ --args=1001 1 1100 b"23A145AB448872B1" |
1.3.
...
3 对提案进行投票
代码块 |
---|
rooch::state_channel:executevote_proposal_entry |
类型参数:
类型参数 | 约束 | 描述 |
---|---|---|
| store | 状态类型 |
ProposalAction
store
参数:
参数名称 | 类型 | 描述 |
---|---|---|
sender | signer | 发起方 |
state_channel_id |
u256
| 状态通道ID |
proposal_id |
u64 | 提案ID |
返回值:
ProposalAction
业务逻辑:
执行提案。
调用示例:
协同编辑器
...
vote_option | u8 | 投票选项: 0:反对 1: 赞成 2:弃权 |
返回值:
无
业务逻辑:
对提案投票。
调用示例:
协同编辑器
代码块 |
---|
aptos move run \
--function-id rooch::state_channel::vote_proposal_entry \
--type-args=rooch_demo::editor::Document \
--args=1001 1 1 |
聊天合约
代码块 |
---|
aptos move run \
--function-id rooch::state_channel::vote_proposal_entry \
--type-args=rooch_demo::chat::ChatGroup \
--args=1001 1 1 |
MoveCraft合约
代码块 |
---|
aptos move run \
--function-id rooch::state_channel::vote_proposal_entry \
--type-args=rooch_demo::movecraft::Land \
--args=1001 1 1 |
1.3.4 执行提案
代码块 |
---|
rooch::state_channel:execute_proposal |
类型参数:
类型参数 | 约束 | 描述 |
---|---|---|
| store | 状态类型 |
ProposalAction | store | 提案Action |
参数:
参数名称 | 类型 | 描述 |
---|---|---|
sender | signer | 发起方 |
state_channel_id |
| 状态通道ID |
proposal_id | u256 | 提案ID |
返回值:
ProposalAction
业务逻辑:
执行提案。
调用示例:
协同编辑器
代码块 |
---|
module rooch_demo::editor { use rooch::state_channel::{Self, StateChannel}; const ERR_FILE_NOT_EXISTS: u64 = 5; public entry fun document_settlement<Document>(account: &signer, state_channel_id: u64, proposal_id: u64) { let editor = borrow_global_mut<DocumentEditor>(EDITOR_ADDRESS); let editing_doc = table::borrow<u64, EditingDocument>(&editor.editingDocuments, state_channel_id); let settlement_cap = editing_doc.settlement_cap; let doc = state_channel::borrow_mut<Document>(account, settlement_cap, state_channel_id); let settlement_action = state_channel::execute_proposal(editing_doc.channel_id, proposal_id) let change_sets = state_channel::get_change_sets(settlement_action) let n = len(change_sets.state); while(i < n) { let change_set = change_sets.state[i] document_apply_change_set(doc, change_set); i = i + 1 } } fun document_apply_change_set(doc: &mut Docuemnt, cs: state_channel::StateChangeSet) { if op::is_new(cs) { let new = op::new(cs) if new.path == "elements" { document_create_element(doc, new.data) } } else if (op::is_modify(cs)) { const ERR_FILE_NOT_EXISTS: u64 = 5; let modify = op::modify(cs) public entryif fun document_settlement<Document>(account: &signer, state_channel_id: u64, proposal_id: u64) {new.path == "elements" { let editor = borrowdocument_globalupdate_mut<DocumentEditor>(EDITOR_ADDRESS);element(doc, modify.id, modify.val) } let editing_doc = table::borrow<u64, EditingDocument>(&editor.editingDocuments, state_channel_id); } else { let settlement_cap = editing_doc.settlement_cap; let del = op::delete(cs) letif docdel.type == state_channel::borrow_mut<Document>(account, settlement_cap, state_channel_id);"rooch_demo::editor::Element" { let settlement_action = state_channel::execute_proposal(editing_doc.channel_id, proposal_document_delete_element(doc, del.id) let change_sets = state_channel::get_change_sets(settlement_action)} } } } |
聊天合约
代码块 |
---|
module rooch_demo::chat { let n = len(change_sets.state);use rooch::state_channel::{Self, StateChannel}; const ERR_FILE_NOT_EXISTS: u64 = while(i5; < n) { public entry fun let change_set = change_sets.state[i]chat_group_settlement<ChatGroup>(account: &signer, state_channel_id: u64, proposal_id: u64) { let chat_server = document_apply_change_set(doc, change_setstate_channel::get_config_label(state_channel_id, "server_address"); i = i + 1 let server } = borrow_global_mut<Server>(chat_server); } let chat_session = fun documentserver_applyborrow_changechat_set(doc: &mut Docuemnt, cs: session(state_channel::StateChangeSet_id); { if op::is_new(cs) { let settlement_cap = chat_session.settlement_cap; let new = op::new(cs) let if new.path == "elements" { chat_group = state_channel::borrow_mut<ChatGroup>(account, settlement_cap, state_channel_id); let settlement_action = document_create_element(doc, new.datastate_channel::execute_proposal(state_channel_id, proposal_id) let account_change_sets } = state_channel::get_change_sets(settlement_action, @rooch_demo) } else if (op::is_modify(cs)) { let modify = op::modify(cs) if table::contains(account_change_sets, "rooch_demo::chat::ChatGroup") { if new.path == "elements"let {op = table::borrow_mut(account_change_sets, "rooch_demo::chat::ChatGroup"); documentchat_group_updateapply_elementop(doc, modify.id, modify.val)chat_group, op) } } } else { fun chat_group_apply_op(chat_group: &mut ChatGroup, cs: op::OP<vector<u8>>) { let del =if (op::deleteis_modify(cs)) { if del.type == "rooch_demo::editor::Element" { let modify_data = op::modify(cs) documentchat_deletegroup_elementupdate(docchat_group, del.idmodify_data) } else if(op::is_delete(cs)){ } } } |
聊天合约
代码块 |
---|
aptos move run \ --function-id rooch::state_channel::vote_proposal_entry \ --type-args=rooch_demo::chat::ChatGroup \ --args=1001 1 1chat_group_destroy(chat_group) } } } |
MoveCraft合约
代码块 |
---|
aptos move run \ --function-id rooch::state_channel::vote_proposal_entry \ --type-args=rooch_demo::movecraft::Land \ --args=1001 1 1 |
...