Skip to content

Commit 24a2f37

Browse files
authored
user optimistic wallets writing to io json (#586)
1 parent 73bc86b commit 24a2f37

3 files changed

Lines changed: 25 additions & 0 deletions

File tree

internal/ipwl/generate_io.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
package ipwl
22

33
import (
4+
"fmt"
45
"io/ioutil"
56
"log"
7+
"os"
68
"path/filepath"
79

810
"github.com/labdao/plex/internal/ipfs"
11+
"github.com/labdao/plex/internal/web3"
912
)
1013

1114
func findMatchingFiles(inputDir string, tool Tool, layers int) (map[string][]string, error) {
@@ -88,12 +91,22 @@ func generateInputCombinations(inputFilepaths map[string][]string) []map[string]
8891
func createIOEntries(toolInfo ToolInfo, tool Tool, inputCombinations []map[string]string) []IO {
8992
var ioData []IO
9093

94+
var userID string
95+
96+
if web3.IsValidEthereumAddress(os.Getenv("RECIPIENT_WALLET")) {
97+
userID = os.Getenv("RECIPIENT_WALLET")
98+
} else {
99+
fmt.Println("RECIPIENT_WALLET is not a valid Ethereum address. Using empty string as user ID.")
100+
userID = ""
101+
}
102+
91103
for _, combination := range inputCombinations {
92104
ioEntry := IO{
93105
Tool: toolInfo,
94106
State: "created",
95107
Inputs: map[string]FileInput{},
96108
Outputs: map[string]Output{},
109+
UserID: userID,
97110
}
98111

99112
for inputName, path := range combination {

internal/ipwl/io.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ type IO struct {
4747
Outputs map[string]Output `json:"outputs"`
4848
State string `json:"state"`
4949
ErrMsg string `json:"errMsg"`
50+
UserID string `json:"userId"`
5051
BacalhauJobId string `json:"bacalhauJobId"`
5152
}
5253

internal/web3/wallet.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package web3
2+
3+
import (
4+
"regexp"
5+
)
6+
7+
func IsValidEthereumAddress(address string) bool {
8+
pattern := `^0x[0-9a-fA-F]{40}$`
9+
match, _ := regexp.MatchString(pattern, address)
10+
return match
11+
}

0 commit comments

Comments
 (0)