near-daos / sputnik-dao-contract

Smart contracts for https://app.astrodao.com
https://astrodao.com/
MIT License
107 stars 79 forks source link

What is HashSet<String> ? #177

Closed GaloisField2718 closed 2 years ago

GaloisField2718 commented 2 years ago

Hello,

How looks an HashSet element ?

It's to create a proposal to add a new role.

near call $DAO add_proposal ' {
    "proposal": {
        "description": "Add the new role member Stagiaire",
        "kind": {
            "ChangePolicyAddOrUpdateRole": {
                "role": {    
                    "name": "stagiaire",
                    "kind": {
                        "Group": ["anank3.testnet"]
                    },
                    "permissions": "[*:AddProposal, *:VoteApprove, *:VoteReject]",
                    "vote_policy": {}
                }
            }
        }
    }
} ' --accountId $NEAR_ACCT --amount $BOND_AMOUNT

Return the error

 ExecutionError: `Smart contract panicked: panicked at 'Failed to deserialize input from JSON.: Error("invalid type: string \\"[*:AddProposal, *:VoteApprove, *:VoteReject]\\", expected a sequence", line: 1, column: 225)', sputnikdao2/src/proposals.rs:482:1`

In the code there are :

 /// Add new role to the policy. If the role already exists, update it. This is short cut to updating the whole policy.
    ChangePolicyAddOrUpdateRole { role: RolePermission },
pub struct RolePermission {
    /// Name of the role to display to the user.
    pub name: String,
    /// Kind of the role: defines which users this permissions apply.
    pub kind: RoleKind,
    /// Set of actions on which proposals that this role is allowed to execute.
    /// <proposal_kind>:<action>
    pub permissions: HashSet<String>,
    /// For each proposal kind, defines voting policy.
    pub vote_policy: HashMap<String, VotePolicy>,
}
GaloisField2718 commented 2 years ago

Proposal : ChangePolicyAddOrUpdateRole

Must be written as :

near call $DAO add_proposal ' {
    "proposal": {
        "description": "Add the new role member Stagiaire",
        "kind": {
            "ChangePolicyAddOrUpdateRole": {
                "role": {    
                    "name": "stagiaire",
                    "kind": {
                        "Group": ["'$NEAR_ACCT.testnet'"]
                    },
                    "permissions": ["*:AddProposal", "*:VoteApprove", "*:VoteReject"],
                    "vote_policy": {}
                }
            }
        }
    }
} ' --accountId $NEAR_ACCT --amount $BOND_AMOUNT 

Especially, "permissions": ["*:AddProposal", "*:VoteApprove", "*:VoteReject"], it's a list of string.