...
参数名称 | 类型 | 描述 |
---|---|---|
sender | signer | 发起方 |
state_channel_id |
| 状态通道ID |
proposal_id | u256 | 提案ID |
返回值:
ProposalAction
业务逻辑:
执行提案。执行提案,检查提案是否投票通过,如果投票通过返回提案Action。
调用示例:
协同编辑器
代码块 |
---|
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_proposalproposal<SettlementAction>(editing_doc.channel_id, proposal_id) let change_sets = state_channel::get_account_change_sets(settlement_action, @rooch_demo) let ndoc_op = len(change_sets.state); while(i < n) { let change_set = change_sets.state[i]state_channel::get_change_set_op<Document>(change_sets) document_apply_change_set(doc, changedoc_setop); i = i + 1 } } fun document_apply_change_set(doc: &mut Docuemnt, cs: state_channel::StateChangeSet) { if (op::is_newmodify(cs)) { let newmodify_doc = op::newmodify(cs) if new.path == "elements" { document_createupdate_element(doc, new.data) modify_doc) } } else if (op::is_modifydelete(cs)) { let modify = op::modify(cs)document_destroy(doc) } if new.path == "elements"} } |
聊天合约
代码块 |
---|
module rooch_demo::chat { use rooch::state_channel::{Self, StateChannel}; document_update_element(doc, modify.id, modify.val) const ERR_FILE_NOT_EXISTS: u64 = 5; } public entry fun } else { chat_group_settlement<ChatGroup>(account: &signer, state_channel_id: u64, proposal_id: u64) { let delchat_server = opstate_channel::delete(cs)get_config_label(state_channel_id, "server_address"); if del.type == "rooch_demo::editor::Element" { let server = borrow_global_mut<Server>(chat_server); let document_delete_element(doc, del.id)chat_session = server_borrow_chat_session(state_channel_id); let settlement_cap }= chat_session.settlement_cap; } } } |
聊天合约
代码块 |
---|
module rooch_demo::chat { let chat_group = use rooch::state_channel::{Self, StateChannel}borrow_mut<ChatGroup>(account, settlement_cap, state_channel_id); let const ERR_FILE_NOT_EXISTS: u64 = 5; public entry fun chat_group_settlement<ChatGroup>(account: &signer, settlement_action = state_channel::execute_proposal(state_channel_id: u64, proposal_id: u64) { let chataccount_change_serversets = state_channel::get_configchange_labelsets(statesettlement_channel_idaction, "server@rooch_address"demo); let server = borrow_global_mut<Server>(chat_server);if table::contains(account_change_sets, "rooch_demo::chat::ChatGroup") { let chat_sessionop = server_table::borrow_chat_mut(account_change_sets, "rooch_demo::chat::ChatGroup"); chat_group_apply_op(chat_group, op) } } fun chat_group_apply_op(chat_group: &mut ChatGroup, cs: op::OP<vector<u8>>) { if (op::is_modify(cs)) { let modify_data = op::modify(cs) chat_group_update(chat_group, modify_data) } else if(op::is_delete(cs)){ chat_group_destroy(chat_group) } } } |
MoveCraft合约
代码块 |
---|
module rooch_demo::movecraft { use rooch::state_channel::{Self, StateChannel}; const ERR_FILE_NOT_EXISTS: u64 = 5; public entry fun land_settlement<ChatGroup>(account: &signer, state_channel_id: u64, proposal_id: u64) { let world = state_channel::get_label(state_channel_id, "world_address"); let land_session = world_borrow_land_session(state_channel_id); let settlement_cap = chatland_session.settlement_cap; let chat_groupland = state_channel::borrow_mut<ChatGroup>mut<Land>(account, settlement_cap, state_channel_id); let settlement_action = state_channel::execute_proposal(state_channel_id, proposal_id) let account_change_sets = state_channel::get_account_change_sets(settlement_action, @rooch_demo) if table::contains(account_change_sets, "rooch_demo::chat::ChatGroupLand") { let op = table::borrow_mut(account_change_sets, "rooch_demo::chat::ChatGroupLand"); chat_groupland_apply_op(chat_groupland, op) } } fun chatland_group_apply_op(chat_group: &mut ChatGroup, cs: op::OP<vector<u8>>) { if (op::is_modify(cs)) { let modify_data = op::modify(cs) chat_group_update(chat_group, modify_data) land: &mut Land, cs: op::OP<vector<u8>>) { } elseif if(op::is_deletemodify(cs)) { chat_group_destroy(chat_grouplet modify_data = op::modify(cs) } land_update(land, modify_data) } } |
MoveCraft合约
代码块 |
---|
aptos move run \ --function-id rooch::state_channel::vote_proposal_entry \ } --type-args=rooch_demo::movecraft::Land \ --args=1001 1} 1} |
2、P2P Node
2.1 模块图
...
2.2 Stream接口
...