mirror of
https://github.com/fluencelabs/fluence-VRF
synced 2025-04-24 14:52:13 +00:00
state machine WIP
This commit is contained in:
parent
92b2b6f9ce
commit
53b322b8c8
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,4 +1,5 @@
|
||||
*.a
|
||||
*.o
|
||||
*.sw*
|
||||
*.dylib
|
||||
*.ll
|
||||
@ -24,5 +25,6 @@ tags
|
||||
node_modules/
|
||||
build/
|
||||
data/
|
||||
.idea/
|
||||
.eos-dev/
|
||||
wallet.pass
|
||||
|
20
main.cpp
20
main.cpp
@ -7,19 +7,31 @@ struct pub_key_type {
|
||||
|
||||
struct Game {
|
||||
bool new_game(int n) {
|
||||
if (state != STATE_NOT_STARTED)
|
||||
return false;
|
||||
|
||||
len = 0;
|
||||
players = (char**)malloc(sizeof(char*) * n);
|
||||
stakes = (int*)malloc(sizeof(int) * n);
|
||||
|
||||
state = STATE_GATHERING_STAKES;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool add_stake(int stake, pub_key_type pub_key) {
|
||||
if (state != STATE_GATHERING_STAKES)
|
||||
return false;
|
||||
|
||||
stakes[len] = stake;
|
||||
players[len] = pub_key.data;
|
||||
++len;
|
||||
return true;
|
||||
}
|
||||
|
||||
int get_stake(pub_key_type pub_key) {
|
||||
if (state == STATE_NOT_STARTED)
|
||||
return false;
|
||||
|
||||
for (int i = 0; i < len; i++) {
|
||||
if (compare(players[i], pub_key.data, pub_key.len))
|
||||
return stakes[i];
|
||||
@ -41,9 +53,17 @@ struct Game {
|
||||
}
|
||||
|
||||
char** get_participants() {
|
||||
if (state == STATE_NOT_STARTED)
|
||||
return 0;
|
||||
|
||||
return players;
|
||||
}
|
||||
private:
|
||||
static const int STATE_NOT_STARTED = 0;
|
||||
static const int STATE_GATHERING_STAKES = 1;
|
||||
static const int STATE_REVEALING = 2;
|
||||
int state;
|
||||
|
||||
int *stakes;
|
||||
char **players;
|
||||
int len;
|
||||
|
Loading…
x
Reference in New Issue
Block a user