Skip to content

Commit

Permalink
Merge branch 'release/v0.1.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
SixofClubsss committed Jan 19, 2024
2 parents 66337d8 + 3ad6589 commit 04984e5
Show file tree
Hide file tree
Showing 9 changed files with 93 additions and 53 deletions.
1 change: 1 addition & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Please select the right one.
- [ ] I have performed a self-review of my code
- [ ] I have commented my code
- [ ] My changes generate no new warnings
- [ ] I have updated the semver version (duel.version)

## License

Expand Down
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@

This file lists the changes to Duels repo with each version.

## 0.1.1 - January 19 2024

### Changed
* Go 1.21.5
* Fyne 2.4.3
* dReams 0.11.1
* Sort finals by height
* 90 sec TX confirm durations
* Cleaned up `rpc` client var names


## 0.1.0 - December 23 2023

Duels v0.1.0 is a showdown style game built on DERO, essentially over or under determined on chain
Expand Down
41 changes: 33 additions & 8 deletions duel/duel.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"io"
"net/http"
"sort"
"strconv"
"strings"
"sync"
Expand Down Expand Up @@ -221,8 +222,6 @@ func GetJoins() (update bool) {

updateSyncProgress(sync_prog)

e := Duels.SingleEntry(u)

n := strconv.Itoa(int(u))
_, init := gnomon.GetSCIDValuesByKey(DUELSCID, "init_"+n)
if init == nil || init[0] == 0 {
Expand All @@ -235,12 +234,13 @@ func GetJoins() (update bool) {
continue
}

e := Duels.SingleEntry(u)
if e.Num == "" {
logger.Debugln("[GetJoins] Making")

_, buffer := gnomon.GetSCIDValuesByKey(DUELSCID, "stamp_"+n)
if buffer == nil {
logger.Debugf("[GetAllDuels] %s no start stamp\n", n)
logger.Debugf("[GetJoins] %s no start stamp\n", n)
buffer = append(buffer, 0)
}

Expand Down Expand Up @@ -526,6 +526,9 @@ func GetAllDuels() (update bool) {
// Gets final duel results
func GetFinals() (update bool) {
if gnomon.IsReady() {
heights := make([]int64, 0, len(Duels.Index))
heightEntries := make(map[int64][]uint64)

for u, v := range Duels.Index {
if !rpc.Wallet.IsConnected() || !gnomon.IsReady() {
break
Expand All @@ -543,7 +546,6 @@ func GetFinals() (update bool) {
if v.Odds <= 950 {
v.Complete = true
v.Height = rpc.GetDaemonTx(winner[1]).Block_Height
Finals.All = append(Finals.All, u)
if v.DM == "Yes" {
if v.Odds > 475 {
v.Duelist.Died = true
Expand All @@ -561,14 +563,37 @@ func GetFinals() (update bool) {
}
logger.Debugf("[GetFinals] %s invalid winner string\n", n)
}
} else if v.Complete && !Finals.ExistsIndex(u) {
Finals.All = append(Finals.All, u)
} else {
// Sort finals by height
update = true
var have bool
for _, k := range heights {
if k == v.Height {
have = true
break
}
}

heightEntries[v.Height] = append(heightEntries[v.Height], u)
if !have {
heights = append(heights, v.Height)
}
}
}
}

Finals.SortIndex(true)
sort.Slice(heights, func(i, j int) bool { return heights[i] > heights[j] })

var finals []uint64
for _, k := range heights {
if k != 0 {
finals = append(finals, heightEntries[k]...)
}
}

Duels.Lock()
Finals.All = finals
Duels.Unlock()
}

return
}
Expand Down
10 changes: 5 additions & 5 deletions duel/duel_layout.go
Original file line number Diff line number Diff line change
Expand Up @@ -928,9 +928,9 @@ func LayoutAllItems(asset_map map[string]string, d *dreams.AppObject) fyne.Canva
tx := Graveyard.Index[selected_grave].Revive()
go func() {
go menu.ShowMessageDialog("Revive", fmt.Sprintf("TX: %s\n\nAuto claim tx will be sent once revive is confirmed", tx), 3*time.Second, d.Window)
if rpc.ConfirmTx(tx, app_tag, 60) {
if rpc.ConfirmTx(tx, app_tag, 45) {
if claim := rpc.ClaimNFA(scid); claim != "" {
if rpc.ConfirmTx(claim, app_tag, 60) {
if rpc.ConfirmTx(claim, app_tag, 45) {
d.Notification(app_tag, fmt.Sprintf("Claimed: %s", scid))
}
}
Expand Down Expand Up @@ -998,7 +998,7 @@ func LayoutAllItems(asset_map map[string]string, d *dreams.AppObject) fyne.Canva
},
func() fyne.CanvasObject {
return container.NewBorder(
dwidget.NewCenterLabel(""),
container.NewCenter(widget.NewRichText()),
dwidget.NewCenterLabel(""),
nil,
nil,
Expand Down Expand Up @@ -1048,7 +1048,7 @@ func LayoutAllItems(asset_map map[string]string, d *dreams.AppObject) fyne.Canva

header := Duels.Index[id].resultsHeaderString()

if Duels.Index[id].Complete && Duels.Index[id].Opponent.Char != "" && o.(*fyne.Container).Objects[1].(*widget.Label).Text != header {
if Duels.Index[id].Complete && Duels.Index[id].Opponent.Char != "" && o.(*fyne.Container).Objects[1].(*fyne.Container).Objects[0].(*widget.RichText).String() != header {
var arrow fyne.CanvasObject
if Duels.Index[id].Odds < 475 {
arrow = bundle.LeftArrow(fyne.NewSize(80, 80))
Expand All @@ -1059,7 +1059,7 @@ func LayoutAllItems(asset_map map[string]string, d *dreams.AppObject) fyne.Canva
o.(*fyne.Container).Objects[0].(*fyne.Container).Objects[0].(*fyne.Container).Objects[2].(*fyne.Container).Objects[0].(*fyne.Container).Objects[0].(*fyne.Container).Objects[0] = arrow
o.(*fyne.Container).Objects[0].(*fyne.Container).Objects[0].(*fyne.Container).Objects[2].(*fyne.Container).Objects[1].(*widget.Label).SetText(Duels.Index[id].endedIn())

o.(*fyne.Container).Objects[1].(*widget.Label).SetText(header)
o.(*fyne.Container).Objects[1].(*fyne.Container).Objects[0].(*widget.RichText).ParseMarkdown(header)
o.(*fyne.Container).Objects[2].(*widget.Label).SetText(fmt.Sprintf("Winner: %s %s", chopAddr(Duels.Index[id].Winner), Leaders.getRecordByAddress(Duels.Index[id].Winner)))

o.(*fyne.Container).Objects[0].(*fyne.Container).Objects[0].(*fyne.Container).Objects[0].(*fyne.Container).Objects[0].(*fyne.Container).Objects[0].(*fyne.Container).Objects[0].(*widget.Label).SetText(Duels.Index[id].Duelist.findDuelResult())
Expand Down
20 changes: 10 additions & 10 deletions duel/duel_rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const DUELSCID = "d455bd7567453a1c11177b7a3bc58ed36aa8ead4503587bb8d86c7f308a91b

// Start a duel
func StartDuel(amt, items, rule, dm, op uint64, char, item1, item2, token string) (tx string) {
rpcClientW, ctx, cancel := rpc.SetWalletClient(rpc.Wallet.Rpc, rpc.Wallet.UserPass)
client, ctx, cancel := rpc.SetWalletClient(rpc.Wallet.Rpc, rpc.Wallet.UserPass)
defer cancel()

args := dero.Arguments{
Expand Down Expand Up @@ -82,7 +82,7 @@ func StartDuel(amt, items, rule, dm, op uint64, char, item1, item2, token string
Fees: fee,
}

if err := rpcClientW.CallFor(ctx, &txid, "transfer", params); err != nil {
if err := client.CallFor(ctx, &txid, "transfer", params); err != nil {
rpc.PrintError("[Duels] Start: %s", err)
return
}
Expand All @@ -94,7 +94,7 @@ func StartDuel(amt, items, rule, dm, op uint64, char, item1, item2, token string

// Accept joinable duel
func (duel entry) AcceptDuel(items, op uint64, char, item1, item2 string) (tx string) {
rpcClientW, ctx, cancel := rpc.SetWalletClient(rpc.Wallet.Rpc, rpc.Wallet.UserPass)
client, ctx, cancel := rpc.SetWalletClient(rpc.Wallet.Rpc, rpc.Wallet.UserPass)
defer cancel()

args := dero.Arguments{
Expand Down Expand Up @@ -157,7 +157,7 @@ func (duel entry) AcceptDuel(items, op uint64, char, item1, item2 string) (tx st
Fees: fee,
}

if err := rpcClientW.CallFor(ctx, &txid, "transfer", params); err != nil {
if err := client.CallFor(ctx, &txid, "transfer", params); err != nil {
rpc.PrintError("[Duels] Accept: %s", err)
return
}
Expand All @@ -169,7 +169,7 @@ func (duel entry) AcceptDuel(items, op uint64, char, item1, item2 string) (tx st

// Ref a duel, need to be owner or a ref on SC to call
func (duel entry) ref(n, addr string, win rune, odds uint64) (tx string) {
rpcClientW, ctx, cancel := rpc.SetWalletClient(rpc.Wallet.Rpc, rpc.Wallet.UserPass)
client, ctx, cancel := rpc.SetWalletClient(rpc.Wallet.Rpc, rpc.Wallet.UserPass)
defer cancel()

args := dero.Arguments{
Expand Down Expand Up @@ -234,7 +234,7 @@ func (duel entry) ref(n, addr string, win rune, odds uint64) (tx string) {
Fees: fee,
}

if err := rpcClientW.CallFor(ctx, &txid, "transfer", params); err != nil {
if err := client.CallFor(ctx, &txid, "transfer", params); err != nil {
rpc.PrintError("[Duels] Ref Duel: %s", err)
return
}
Expand All @@ -246,7 +246,7 @@ func (duel entry) ref(n, addr string, win rune, odds uint64) (tx string) {

// Revive a character from graveyard
func (grave grave) Revive() (tx string) {
rpcClientW, ctx, cancel := rpc.SetWalletClient(rpc.Wallet.Rpc, rpc.Wallet.UserPass)
client, ctx, cancel := rpc.SetWalletClient(rpc.Wallet.Rpc, rpc.Wallet.UserPass)
defer cancel()

args := dero.Arguments{
Expand Down Expand Up @@ -281,7 +281,7 @@ func (grave grave) Revive() (tx string) {
Fees: fee,
}

if err := rpcClientW.CallFor(ctx, &txid, "transfer", params); err != nil {
if err := client.CallFor(ctx, &txid, "transfer", params); err != nil {
rpc.PrintError("[Duels] Revive: %s", err)
return
}
Expand All @@ -293,7 +293,7 @@ func (grave grave) Revive() (tx string) {

// Refund a duel, used by owners, refs and players
func Refund(n string) (tx string) {
rpcClientW, ctx, cancel := rpc.SetWalletClient(rpc.Wallet.Rpc, rpc.Wallet.UserPass)
client, ctx, cancel := rpc.SetWalletClient(rpc.Wallet.Rpc, rpc.Wallet.UserPass)
defer cancel()

args := dero.Arguments{
Expand All @@ -312,7 +312,7 @@ func Refund(n string) (tx string) {
Fees: fee,
}

if err := rpcClientW.CallFor(ctx, &txid, "transfer", params); err != nil {
if err := client.CallFor(ctx, &txid, "transfer", params); err != nil {
rpc.PrintError("[Duels] Refund: %s", err)
return
}
Expand Down
24 changes: 8 additions & 16 deletions duel/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -423,10 +423,9 @@ func refGetJoins() {

if !e.validateCollection(false) {
logger.Warnln("[refGetJoins] Not a valid duelist, refunding")
retry := 0
tx := Refund(n)
time.Sleep(time.Second)
retry += rpc.ConfirmTxRetry(tx, "refService", 60)
rpc.ConfirmTx(tx, "refService", 50)
continue
}
Duels.WriteEntry(u, e)
Expand Down Expand Up @@ -558,10 +557,9 @@ func processReady() {
if e.Ready > 0 && !e.Complete {
if !e.validateCollection(true) || !e.validateCollection(false) {
logger.Warnln("[processReady] Not a valid collection, refunding")
retry := 0
tx := Refund(strconv.FormatUint(u, 10))
time.Sleep(time.Second)
retry += rpc.ConfirmTxRetry(tx, "refService", 60)
rpc.ConfirmTx(tx, "refService", 50)
continue
}

Expand All @@ -570,24 +568,18 @@ func processReady() {
// Will wait a minute after ready stamp before calling refDuel()
if now > stamp {
logger.Printf("[processReady] Processing #%s Death match (%s) Hardcore (%s)\n", e.Num, e.DM, e.Rule)
retry := 0
for retry < 4 {
tx := e.refDuel()
time.Sleep(time.Second)
retry += rpc.ConfirmTxRetry(tx, "refService", 60)
}
tx := e.refDuel()
time.Sleep(time.Second)
rpc.ConfirmTx(tx, "refService", 50)
} else {
for time.Now().Unix() < stamp {
logger.Debugf("[processReady] %d waiting for buffer\n", u)
time.Sleep(time.Second)
}
logger.Printf("[processReady] Processing #%s Death match (%s) Hardcore (%s)\n", e.Num, e.DM, e.Rule)
retry := 0
for retry < 4 {
tx := e.refDuel()
time.Sleep(time.Second)
retry += rpc.ConfirmTxRetry(tx, "refService", 60)
}
tx := e.refDuel()
time.Sleep(time.Second)
rpc.ConfirmTx(tx, "refService", 50)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion duel/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (

const app_tag = "Duels"

var version = semver.MustParse("0.1.0")
var version = semver.MustParse("0.1.1")
var gnomon = gnomes.NewGnomes()

// Check duel package version
Expand Down
10 changes: 5 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
module github.com/SixofClubsss/Duels

go 1.20
go 1.21.5

require (
fyne.io/fyne/v2 v2.4.1
fyne.io/fyne/v2 v2.4.4-0.20231224124904-a09bbd790b98
github.com/blang/semver/v4 v4.0.0
github.com/civilware/Gnomon v0.0.0-20231218151558-0ee387e75195
github.com/dReam-dApps/dReams v0.10.2-0.20231223102408-bb16636e1a47
github.com/civilware/Gnomon v0.0.0-20240102201536-a5900d5a61da
github.com/dReam-dApps/dReams v0.11.1-0.20240119220150-6bd74607a301
github.com/deroproject/derohe v0.0.0-20230604143809-765b2db1f482
github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815
github.com/sirupsen/logrus v1.9.3
)

require (
fyne.io/systray v1.10.1-0.20230722100817-88df1e0ffa9a // indirect
fyne.io/systray v1.10.1-0.20231115130155-104f5ef7839e // indirect
fyne.io/x/fyne v0.0.0-20230411205836-1ca0ead20763 // indirect
github.com/VictoriaMetrics/metrics v1.24.0 // indirect
github.com/beevik/ntp v1.3.0 // indirect
Expand Down
Loading

0 comments on commit 04984e5

Please sign in to comment.