@@ -13,57 +13,57 @@ import (
1313)
1414
1515var (
16- Disputes = avl.NewTree()
17- DisputeDuration = 2 * int64(time.Minute.Seconds())
18- RevealDuration = 2 * int64(time.Minute.Seconds())
19- VoteTokenPrice = 1 * int64(1_000_000) // in GNOT
16+ disputes = avl.NewTree()
17+ disputeDuration = 2 * int64(time.Minute.Seconds())
18+ revealDuration = 2 * int64(time.Minute.Seconds())
19+ voteTokenPrice = 1 * int64(1_000_000) // in GNOT
2020 VoteToken = newOOToken("Gno Optimistic Oracle Token", "goot", 6)
2121)
2222
2323func initiateDispute(id string) {
24- if _, exists := Disputes .Get(id); exists {
24+ if _, exists := disputes .Get(id); exists {
2525 panic("error: Dispute for this request already exists.")
2626 }
2727 dispute := Dispute{
2828 RequestId: id,
2929 Votes: []Vote{},
3030 Voters: avl.NewTree(),
3131 IsResolved: false,
32- EndTime: time.Now().Add(time.Duration(DisputeDuration ) * time.Second),
33- EndRevealTime: time.Now().Add(time.Duration(DisputeDuration+RevealDuration ) * time.Second),
32+ EndTime: time.Now().Add(time.Duration(disputeDuration ) * time.Second),
33+ EndRevealTime: time.Now().Add(time.Duration(disputeDuration+revealDuration ) * time.Second),
3434 }
35- Disputes .Set(id, dispute)
35+ disputes .Set(id, dispute)
3636 chain.Emit("DisputeInitiated", "id", id)
3737}
3838
3939// -- PUBLIC FUNCTIONS --
4040
41- // BuyInitialVoteToken allows a user to buy their first vote token by sending VoteTokenPrice amount of ugnot.
41+ // BuyInitialVoteToken allows a user to buy their first vote token by sending voteTokenPrice amount of ugnot.
4242func BuyInitialVoteToken(_ realm) {
4343 caller := runtime.OriginCaller()
4444 coins := banker.OriginSend()
45- if len(coins) != 1 || coins.AmountOf("ugnot") != VoteTokenPrice {
46- panic("error: Must send exactly " + strconv.Itoa(int(VoteTokenPrice /1_000_000)) + " gnot to get a vote token.")
45+ if len(coins) != 1 || coins.AmountOf("ugnot") != voteTokenPrice {
46+ panic("error: Must send exactly " + strconv.Itoa(int(voteTokenPrice /1_000_000)) + " gnot to get a vote token.")
4747 }
4848
4949 balance := VoteToken.BalanceOf(caller)
5050 if balance > 0 {
5151 panic("error: You already have a vote token.")
5252 }
5353
54- VoteToken.Mint (caller, 1)
54+ VoteToken.mint (caller, 1)
5555 chain.Emit("VoteTokenPurchased", "voter", caller.String())
5656}
5757
5858// BalanceOfVoteToken returns the number of vote tokens held by the caller.
5959func BalanceOfVoteToken(_ realm) int64 {
60- return VoteToken.balanceOf (runtime.PreviousRealm().Address())
60+ return VoteToken.BalanceOf (runtime.PreviousRealm().Address())
6161}
6262
6363// VoteOnDispute allows a user to commit a vote during a dispute.
6464func VoteOnDispute(_ realm, id string, hash string) {
6565 dispute := getDispute(id)
66- res, _ := Requests .Get(id)
66+ res, _ := requests .Get(id)
6767 request := res.(DataRequest)
6868 if request.Proposer == runtime.PreviousRealm().Address() || request.Disputer == runtime.PreviousRealm().Address() {
6969 panic("error: Proposer and Disputer cannot vote in this dispute.")
@@ -92,7 +92,7 @@ func VoteOnDispute(_ realm, id string, hash string) {
9292 }
9393 dispute.Votes = append(dispute.Votes, vote)
9494 dispute.Voters.Set(string(vote.Voter), Voter{HasVoted: true, VoteIndex: int64(len(dispute.Votes) - 1)})
95- Disputes .Set(id, dispute)
95+ disputes .Set(id, dispute)
9696 chain.Emit("VoteSubmitted", "id", id, "voter", vote.Voter.String())
9797}
9898
@@ -127,7 +127,7 @@ func RevealVote(_ realm, id string, value int64, salt string) {
127127 vote.Revealed = true
128128 dispute.NbResolvedVotes += 1
129129 dispute.Votes[voter.(Voter).VoteIndex] = vote
130- Disputes .Set(id, dispute)
130+ disputes .Set(id, dispute)
131131 chain.Emit("VoteRevealed", "id", id, "voter", vote.Voter.String(), "value", strconv.Itoa(int(value)))
132132}
133133
@@ -143,13 +143,13 @@ func ResolveDispute(_ realm, id string) {
143143 val := resolve(id)
144144 dispute.WinningValue = val
145145 dispute.IsResolved = true
146- Disputes .Set(id, dispute)
146+ disputes .Set(id, dispute)
147147 // Update the original request with the winning value
148148 request := getRequest(id)
149149
150150 request.ProposedValue = val
151151 request.State = "Resolved"
152- Requests .Set(id, request)
152+ requests .Set(id, request)
153153 chain.Emit("DisputeResolved", "id", id, "winningValue", strconv.Itoa(int(val)))
154154 chain.Emit("RequestResolved", "id", id, "winningValue", strconv.Itoa(int(val)))
155155
@@ -161,15 +161,15 @@ func ResolveDispute(_ realm, id string) {
161161 // Refund + reward the proposer if the dispute did not change the value
162162 winner = request.Proposer
163163 }
164- Bank .SendCoins(runtime.CurrentRealm().Address(), winner, chain.Coins{chain.Coin{Denom: "ugnot", Amount: Bond + RequesterReward }})
164+ bank .SendCoins(runtime.CurrentRealm().Address(), winner, chain.Coins{chain.Coin{Denom: "ugnot", Amount: bond + requesterReward }})
165165}
166166
167167// -- admin functions --
168168
169169// SetDisputeDuration sets the duration (in seconds) for the voting period.
170170func SetDisputeDuration(_ realm, duration int64) {
171171 if runtime.OriginCaller() == admin {
172- DisputeDuration = duration * int64(time.Second)
172+ disputeDuration = duration * int64(time.Second)
173173 } else {
174174 panic("error: Only admin can set dispute duration.")
175175 }
@@ -178,7 +178,7 @@ func SetDisputeDuration(_ realm, duration int64) {
178178// SetRevealDuration sets the duration (in seconds) for the reveal period.
179179func SetRevealDuration(_ realm, duration int64) {
180180 if runtime.OriginCaller() == admin {
181- RevealDuration = duration * int64(time.Second)
181+ revealDuration = duration * int64(time.Second)
182182 } else {
183183 panic("error: Only admin can set reveal duration.")
184184 }
@@ -187,7 +187,7 @@ func SetRevealDuration(_ realm, duration int64) {
187187// SetVoteTokenPrice sets the price (in ugnot) to cast a vote.
188188func SetVoteTokenPrice(_ realm, price int64) {
189189 if runtime.OriginCaller() == admin {
190- VoteTokenPrice = price
190+ voteTokenPrice = price
191191 } else {
192192 panic("error: Only admin can set vote price.")
193193 }
@@ -202,12 +202,12 @@ func GetDispute(_ realm, id string) Dispute {
202202
203203// GetDisputeDuration returns the current dispute duration.
204204func GetDisputeDuration(_ realm) int64 {
205- return DisputeDuration
205+ return disputeDuration
206206}
207207
208208// GetVoteTokenPrice returns the current vote price.
209209func GetVoteTokenPrice(_ realm) int64 {
210- return VoteTokenPrice
210+ return voteTokenPrice
211211}
212212
213213// GetDisputeEndTime returns the end time of the voting period for a specific dispute.
@@ -230,13 +230,13 @@ func GetRevealEndTime(_ realm, id string) time.Time {
230230
231231// GetRevealDuration returns the current reveal duration.
232232func GetRevealDuration(_ realm) int64 {
233- return RevealDuration
233+ return revealDuration
234234}
235235
236236// Utils functions
237237
238238func getDispute(id string) Dispute {
239- dispute, exists := Disputes .Get(id)
239+ dispute, exists := disputes .Get(id)
240240 if !exists {
241241 panic("error: Dispute with this ID does not exist.")
242242 }
0 commit comments