-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#135 Added Council.ts and fixed small bug
- Loading branch information
1 parent
d36f17d
commit 9951318
Showing
5 changed files
with
119 additions
and
2 deletions.
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
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 |
---|---|---|
@@ -0,0 +1,50 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Council = void 0; | ||
const Coin_1 = require("./Coin"); | ||
class Council { | ||
constructor() { | ||
this.hashResponses = []; | ||
this.clearResponses = []; | ||
} | ||
static from(json) { | ||
let council = Object.assign(new Council(), json); | ||
console.log(json); | ||
council.hoshResponses = json.hoshResponses?.map(resp => { | ||
return WrapHashResponse.from(resp); | ||
}); | ||
council.clearResponses = json.clearResponses?.map(resp => { | ||
return WrapClearResponse.from(resp); | ||
}); | ||
council.treasury = Coin_1.Coin.from(json.treasury); | ||
council.status = CouncelingStatus[json.status]; | ||
return council; | ||
} | ||
} | ||
exports.Council = Council; | ||
class WrapClearResponse { | ||
static from(json) { | ||
return Object.assign(new WrapClearResponse(), json); | ||
} | ||
} | ||
class WrapHashResponse { | ||
static from(json) { | ||
return Object.assign(new WrapHashResponse(), json); | ||
} | ||
} | ||
var Response; | ||
(function (Response) { | ||
Response[Response["Yes"] = 0] = "Yes"; | ||
Response[Response["No"] = 1] = "No"; | ||
Response[Response["Suggestion"] = 2] = "Suggestion"; | ||
})(Response || (Response = {})); | ||
var CouncelingStatus; | ||
(function (CouncelingStatus) { | ||
CouncelingStatus[CouncelingStatus["councilDoesNotExist"] = 0] = "councilDoesNotExist"; | ||
CouncelingStatus[CouncelingStatus["councilOpen"] = 1] = "councilOpen"; | ||
CouncelingStatus[CouncelingStatus["councilCreated"] = 2] = "councilCreated"; | ||
CouncelingStatus[CouncelingStatus["councilClosed"] = 3] = "councilClosed"; | ||
CouncelingStatus[CouncelingStatus["commited"] = 4] = "commited"; | ||
CouncelingStatus[CouncelingStatus["revealed"] = 5] = "revealed"; | ||
CouncelingStatus[CouncelingStatus["suggestionsMade"] = 6] = "suggestionsMade"; | ||
})(CouncelingStatus || (CouncelingStatus = {})); |
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 |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { Coin } from "./Coin"; | ||
|
||
export class Council { | ||
cardId: number | ||
voters: Array<string> | ||
hashResponses: Array<WrapHashResponse> = [] | ||
clearResponses: Array<WrapClearResponse> = [] | ||
treasury: Coin | ||
status: CouncelingStatus | ||
trialStart: number | ||
|
||
static from(json) { | ||
let council = Object.assign(new Council(), json); | ||
console.log(json) | ||
council.hoshResponses = json.hoshResponses?.map(resp => { | ||
return WrapHashResponse.from(resp) | ||
}) | ||
council.clearResponses = json.clearResponses?.map(resp => { | ||
return WrapClearResponse.from(resp) | ||
}) | ||
council.treasury = Coin.from(json.treasury) | ||
council.status = CouncelingStatus[json.status] | ||
return council | ||
} | ||
} | ||
|
||
class WrapClearResponse { | ||
user: string | ||
response: Response | ||
suggestion: string | ||
|
||
static from(json) { | ||
return Object.assign(new WrapClearResponse(), json); | ||
} | ||
} | ||
|
||
class WrapHashResponse { | ||
user: string | ||
hash: string | ||
|
||
static from(json) { | ||
return Object.assign(new WrapHashResponse(), json); | ||
} | ||
} | ||
|
||
enum Response { | ||
Yes, | ||
No, | ||
Suggestion, | ||
} | ||
|
||
enum CouncelingStatus { | ||
councilDoesNotExist, | ||
councilOpen, | ||
councilCreated, | ||
councilClosed, | ||
commited, | ||
revealed, | ||
suggestionsMade, | ||
} |
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