-
Notifications
You must be signed in to change notification settings - Fork 12
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
Payroll contract example #94
base: develop
Are you sure you want to change the base?
Conversation
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.
Consider adding test cases for this contract. Alternatively, put it in the examples
folder if it is not intended to be part of the workspaces test suite.
One limitation with the multisig implementation is that it does not allow different roles to approve the action. So in this particular example if I want the manager and the employee to approve the action of disbursing pay it's not possible because they have different roles. If the multisig were to allow multiple enum variants to approve the same action, it's still possible that two employees could approve the action, or a different employee could approve. Here we want to specific accounts to make a combined approval. I don't think the default implementation supports such a pattern. This can be documented more clearly that the approval requires m votes among n equal peers (equal as in the same role). For this example will a custom implementation be more useful or is there some other helpful macro? |
So the |
I believe |
In the meantime I'll look into implementing a custom approval flow for this. It's for the best I think since the example will demonstrate a slightly more complex approval implementation. |
Add documentation/design comments in TODO notes
I've updated the example with a custom approval management. I've also noted down my documentation and design comments as Any suggestions for improving the example? There is one thing left to make it complete i.e. to subtract the logged hours once the transfer is complete. |
I'm working on the sandbox tests and I often get errors like this.
It doesn't actually mention which method call which makes it much harder to debug. Is there anyway to expose this information? It'll certainly help newcomers using repo. In the stack trace it points to the last line of the test. Although I think it fails earlier because removing the last line makes it point to the next last line.
|
Also I found that there are no examples where the output of a transaction call is used. While trying to do this I found that the result of a transaction is actually the base64 encoding of the return value. However the |
A custom implementation of ApprovalManager is pretty non-trivial to use. After initializing the configuration in the contract impl Payroll {
#[init]
pub fn new(owner: &AccountId) -> Self {
let mut contract = Payroll {
hourly_fee: 1000,
logged_time: UnorderedMap::new(PayrollKey::LOG),
};
<Payroll as ApprovalManager<PayrollAction, PayrollApproval, PayApprovalConfiguration>>::init(PayApprovalConfiguration {});
contract.add_role(owner, &Role::Manager);
contract
}
}
|
The contract demonstrates a simplified but relatable real world scenario where a payroll management contract can add and pay employees.
Among other things it demonstrates how and where to use macros for Rbac and patterns around collections, storage keys and Promises and handling errors in a non-trivial example.
Next step is to handle more error cases, include a multi-sig approval in this and create test cases to show how it works.