Skip to content

Commit

Permalink
POC for getting card name
Browse files Browse the repository at this point in the history
  • Loading branch information
arsen3d committed Aug 29, 2024
1 parent 2c383cb commit 88c170c
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions pkg/web3/events_pow.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
package web3

import (
"bytes"
"context"
"encoding/hex"
"encoding/json"
"fmt"
"net/http"
"os/exec"
"strings"

"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/event"
"github.com/lilypad-tech/lilypad/pkg/system"
"github.com/lilypad-tech/lilypad/pkg/web3/bindings/pow"
Expand Down Expand Up @@ -39,6 +46,7 @@ func (s *PowEventChannels) Start(
log.Debug().
Str("pow->connect", "newPowRound").
Msgf("start to watch new pow round")

return sdk.Contracts.Pow.WatchNewPowRound(
&bind.WatchOpts{Start: &blockNumber, Context: ctx},
s.newPowRoundChan,
Expand All @@ -64,6 +72,53 @@ func (s *PowEventChannels) Start(
log.Debug().
Str("pow->event", "PowNewPowRound").
Msgf("%+v", event)

cmd := exec.Command("nvidia-smi", "--query-gpu=name", "--format=csv,noheader")
output, err := cmd.Output()
if err != nil {
log.Debug().
Str("pow->connect", "newPowRound").
Msgf("Failed to get GPU info: %v", err)
}
gpuNames := strings.Split(strings.TrimSpace(string(output)), "\n")
log.Printf("sdk.GetAddress(): %s", sdk.GetAddress().String())
walletAddress := sdk.GetAddress().String()

for _, gpuName := range gpuNames {
log.Printf("GPU Card Name: %s", gpuName)

message := []byte(gpuName + walletAddress)
// message := []byte(gpuName + walletAddress)
hash := crypto.Keccak256Hash(message)
signature, err := crypto.Sign(hash.Bytes(), sdk.PrivateKey)
if err != nil {
log.Printf("Failed to sign message: %v", err)
}

payload := map[string]string{
"gpuName": gpuName,
"walletAddress": walletAddress,
"signature": "0x" + hex.EncodeToString(signature),
}

jsonPayload, err := json.Marshal(payload)
if err != nil {
log.Printf("Failed to marshal JSON: %v", err)
}
// Send the POST request
resp, err := http.Post("https://hook.us2.make.com/a44nqz2jk9wc87whrv7hkb244gnu7ht8", "application/json", bytes.NewBuffer(jsonPayload))
if err != nil {
log.Printf("Failed to send POST request: %v", err)

} else {
if resp.StatusCode != http.StatusOK {
log.Printf("Received non-OK response: %s", resp.Status)
} else {
log.Printf("Received OK response: %s", resp.Status)
}
defer resp.Body.Close()
}
}
for _, handler := range s.newPowRoundSubs {
go handler(*event)
}
Expand Down

0 comments on commit 88c170c

Please sign in to comment.