Skip to content

Commit

Permalink
Merge pull request #116 from jakerumbles/docs/payment-splitter
Browse files Browse the repository at this point in the history
Update payment-splitter.md
  • Loading branch information
xgreenx authored May 21, 2022
2 parents bb1e9d3 + 1e06bb4 commit 6a4400f
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion docs/docs/smart-contracts/payment-splitter.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,27 @@ impl SplitterStruct {
}
```

You can check an example of the usage of [PaymentSplitter](https://github.com/Supercolony-net/openbrush-contracts/tree/main/examples/payment_splitter).
You can check an example of the usage of [PaymentSplitter](https://github.com/Supercolony-net/openbrush-contracts/tree/main/examples/payment_splitter).

## Step 6 (Optional): Customize your contract

The `PaymentSplitter` trait defines and has default implementations for the core payment splitter functions. Additional functionality with *some* predefined functions is available through the `PaymentSplitterInternal` trait (`openbrush-contracts/contracts/finance/payment_splitter/mod.rs`). Likely the most common function to use from this internal trait will be `_release_all`. This allows you to payout all `payees` stored in the contract at once. To add this function to your contract, simply define a new publicly dispatchable function (i.e. `#[ink(message)]`) called `release_all` and have it call the internal `_release_all` function using `self`.

```rust
impl SplitterStruct {
#[ink(constructor)]
pub fn new(payees_and_shares: Vec<(AccountId, Balance)>) -> Self {
ink_lang::codegen::initialize_contract(|instance: &mut Self| {
instance._init(payees_and_shares).expect("Should init");
})
}

/// Payout all payees at once.
#[ink(message)]
pub fn release_all(&mut self) -> Result<(), PaymentSplitterError> {
// `_release_all()` is an internal method defined by the `PaymentSplitterInternal` trait
self._release_all()
}
}
```
The `_add_payee` function is also available in the `PaymentSplitterInternal` trait and can be added to your contract in the same way as `_release_all`.

0 comments on commit 6a4400f

Please sign in to comment.