Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: POC for getting card name #312

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading