Skip to content

Commit

Permalink
Merge pull request #21 from mirrorworld-universe/aide
Browse files Browse the repository at this point in the history
feat: Update main.go to track last sent slot and send block fees
  • Loading branch information
yusufyian authored Jul 7, 2024
2 parents b466b87 + 0d333ac commit 2eb1dfa
Showing 1 changed file with 17 additions and 39 deletions.
56 changes: 17 additions & 39 deletions hypergrid-aide/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ package main

import (
"fmt"
"io"
"os"
"strconv"

"log"

Expand All @@ -20,7 +18,7 @@ const SOLANA_RPC_ENDPOINT = "https://devnet1.sonic.game" //"http://localhost:889
const COSMOS_RPC_ENDPOINT = "http://localhost:26657"
const COSMOS_ADDRESS_PREFIX = "cosmos"
const COSMOS_HOME = "/home/ubuntu/.hypergrid-ssn"
const AIDE_LAST_SEND_SLOT = "/home/ubuntu/.hypergrid-ssn/last_slot.txt"

const AIDE_GET_BLOCKS_COUNT_LIMIT = 10

func CheckFileExist(fileName string) bool {
Expand Down Expand Up @@ -60,30 +58,21 @@ func main() {
gridId := resp.Identity.String()
println("Grid ID: ", gridId)
var last_sent_slot uint64
if CheckFileExist(AIDE_LAST_SEND_SLOT) {
var f *os.File
f, err = os.Open(AIDE_LAST_SEND_SLOT)
if err != nil {
log.Fatal(err)
}
defer f.Close()

fd, err := io.ReadAll(f)
if err != nil {
fmt.Println("read to fd fail", err)
var first_available_slot uint64

}
last_sent_slot, err = strconv.ParseUint(string(fd), 10, 64) // 将fd从[]byte转换为string,然后转换为int
if err != nil {
fmt.Println("convert fd to int fail", err)
first_available_slot, err = solana.GetFirstBlock()
if err != nil {
log.Fatal(err)
}

}
} else {
last_sent_slot = 0
last_sent_slot, err = tools.GetLastSentSlot()
if err != nil {
log.Fatal(err)
}
println("last_sent_slot: ", last_sent_slot)
blocks, err := solana.GetBlocks(last_sent_slot+1, AIDE_GET_BLOCKS_COUNT_LIMIT)
println("last_sent_slot2: ", last_sent_slot)
start_slot := max(first_available_slot-1, last_sent_slot) + 1
println("last_sent_slot: ", start_slot)
blocks, err := solana.GetBlocks(start_slot, AIDE_GET_BLOCKS_COUNT_LIMIT)
println("last_sent_slot2: ", start_slot)
if err != nil {
println("GetBlocks fail")
log.Fatal(err)
Expand All @@ -101,24 +90,13 @@ func main() {
}
fmt.Print("MsgCreateGridTxFee:", resp)
} else {
last_sent_slot = last_sent_slot + AIDE_GET_BLOCKS_COUNT_LIMIT
last_sent_slot = start_slot + AIDE_GET_BLOCKS_COUNT_LIMIT - 1
}

var f *os.File
if CheckFileExist(AIDE_LAST_SEND_SLOT) {
f, err = os.OpenFile(AIDE_LAST_SEND_SLOT, os.O_WRONLY, 0644)
if err != nil {
log.Fatal(err)
}
} else {
f, err = os.Create(AIDE_LAST_SEND_SLOT)
if err != nil {
log.Fatal(err)
}
_, err = tools.SetLastSentSlot(last_sent_slot)
if err != nil {
log.Fatal(err)
}
println("last slot: ", last_sent_slot)
_, err = f.WriteString(strconv.FormatUint(last_sent_slot, 10))
defer f.Close()

queryResp, err := cosmos.QueryAllGridBlockFees()
if err != nil {
Expand Down

0 comments on commit 2eb1dfa

Please sign in to comment.