Skip to content

Commit

Permalink
feat: upgrade binary to support v4 cardinfof schema (#412)
Browse files Browse the repository at this point in the history
  • Loading branch information
hunjixin authored Nov 5, 2024
1 parent 711ae57 commit d93c821
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 5 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ require (
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.28.0
go.opentelemetry.io/otel/sdk v1.28.0
go.opentelemetry.io/otel/trace v1.30.0
golang.org/x/crypto v0.25.0
gorgonia.org/cu v0.9.7-0.20240623234718-3cd40db700e9
k8s.io/apimachinery v0.29.0
)
Expand Down Expand Up @@ -182,7 +183,6 @@ require (
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.27.0 // indirect
go4.org v0.0.0-20230225012048-214862532bf5 // indirect
golang.org/x/crypto v0.25.0 // indirect
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 // indirect
golang.org/x/mod v0.19.0 // indirect
golang.org/x/net v0.27.0 // indirect
Expand Down
Binary file removed pkg/resourceprovider/card
Binary file not shown.
Binary file added pkg/resourceprovider/card-linux-amd64
Binary file not shown.
4 changes: 0 additions & 4 deletions pkg/resourceprovider/card.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
package resourceprovider

import (
_ "embed"
"fmt"
"os"
"os/exec"

"github.com/rs/zerolog/log"
)

//go:embed card
var cardBinary []byte

func PostCard(id string, challange string, difficulty string) error {
tmpFile, err := os.CreateTemp("", "card-*")
if err != nil {
Expand Down
10 changes: 10 additions & 0 deletions pkg/resourceprovider/card_embed_linux_amd64.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//go:build linux && amd64

package resourceprovider

import (
_ "embed"
)

//go:embed card-linux-amd64
var cardBinary []byte
5 changes: 5 additions & 0 deletions pkg/resourceprovider/card_embed_others.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//go:build !(linux && amd64)

package resourceprovider

var cardBinary []byte = []byte("just mock a string, make it buildable for other components")
2 changes: 2 additions & 0 deletions pkg/resourceprovider/resourceprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/hex"
"fmt"
"math/big"
"os"
"strconv"
"time"

Expand Down Expand Up @@ -134,6 +135,7 @@ func (resourceProvider *ResourceProvider) StartMineLoop(ctx context.Context) cha
difficulty, _ := uint256.FromBig(challenge.Difficulty)
uuid := uuid.New()

os.Setenv("WEB3_PRIVATE_KEY", resourceProvider.options.Web3.PrivateKey) //to ensure this env exit because binary need it but if user specific this with flag, no environment variable exit.
err = PostCard(uuid.String(), "0x"+hex.EncodeToString(challenge.Challenge[:]), challenge.Difficulty.String())
if err != nil {
log.Err(err).Msgf("Unable to post card")
Expand Down

0 comments on commit d93c821

Please sign in to comment.