generated from multiversx/mx-template-sc
-
Notifications
You must be signed in to change notification settings - Fork 6
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
added docs and small owner fix #32
Merged
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ac36955
added docs and small owner fix
mihaicalinluca aba4252
Merge branch 'main' into game-sc-tests
mihaicalinluca fb75aab
fix docs after review
mihaicalinluca cc47157
Merge remote-tracking branch 'origin/game-sc-tests' into game-sc-tests
mihaicalinluca 03c6823
fix words after review
mihaicalinluca File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,78 @@ | ||
# lib | ||
# Game lobby SC | ||
|
||
`lib` is a simple Smart Contract. | ||
|
||
## Overview | ||
This smart contract covers the functionality of a basic game lobby under a set of rules imposed by the owner. | ||
|
||
**A user** can create a new wager game with the following specifications: | ||
- `waiting time` | ||
- `minimum number of players` | ||
- `maximum number of players` | ||
- `wager` | ||
|
||
and has to pay a fee for each new game. | ||
|
||
**The owner** can: | ||
- `enable/disable` the contract for maintenance | ||
- set the `game starting fee` amount | ||
- set the `token id` for the currency of the SC (used for game starting fee, wager and reward) | ||
- `send rewards` or return the wager to the users who participated in a specific game | ||
|
||
Each player has to pay the `wager` amount set by the game creator in the `token id` set by the owner in order to join the game. | ||
|
||
The game is considered `invalid` until the `minimum number of players` have joined the game and if the `waiting time` has passed, no more players can join. | ||
|
||
The SC does not have any logic for calculating the winner, so it expects input from the owner with the winners' addresses and the percentage (*100) of the total reward (sum of wagers) won by each. | ||
|
||
**The game**: | ||
- If the game is `invalid`, the `wager` amount will be returned to the players that have joined the game and the `game starting fee` will be returned to the creator | ||
- If the game is `valid`, but no winners are provided, such in the case of a tie/draw, the contract will send back the `wager` amount paid by every player who joined | ||
- If the game is `valid` and winners are provided, the SC will send the reward to the them, based on the input of the owner. | ||
|
||
## Endpoints | ||
### createGame | ||
```rust | ||
#[payable("*")] | ||
#[endpoint(createGame)] | ||
fn create_game( | ||
&self, | ||
waiting_time: u64, | ||
number_of_players_min: u64, | ||
number_of_players_max: u64, | ||
wager: BigUint, | ||
``` | ||
Creates a game with a new id using the parameters sent by the caller if the payment is right (payment should be equal to `game starting fee`). | ||
The SC calculates min and max from the parameters so you don't have to worry if you placed them wrong. | ||
|
||
|
||
### joinGame | ||
```rust | ||
#[payable("*")] | ||
#[endpoint(joinGame)] | ||
fn join_game(&self, game_id: u64) | ||
``` | ||
Caller can join a game with an existing game id if the payment is right (payment should be equal to `wager`). | ||
|
||
|
||
### sendReward | ||
```rust | ||
#[only_owner] | ||
#[endpoint(sendReward)] | ||
fn send_reward( | ||
&self, | ||
game_id: u64, | ||
winners: OptionalValue<MultiValueEncoded<(ManagedAddress, u64)>>, | ||
``` | ||
Owner can send the rewards for the players through this endpoint. | ||
|
||
|
||
**winners:** | ||
- the address of the winner | ||
- the percentage of the reward pool the winner is entitled to * 100, (e.g: for 12.53%, the owner should send 1253 as parameter) | ||
|
||
### claimBackWager | ||
```rust | ||
#[endpoint(claimBackWager)] | ||
fn claim_back_wager(&self, game_id: u64) | ||
``` | ||
Caller can manually claim back the `wager` if the game is `invalid` and the `waiting time` has passed (in case the owner has not already sent the wager through the **sendReward** endpoint) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
send the rewards to them