|
| 1 | +package main |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + "fmt" |
| 6 | + "log" |
| 7 | + "os" |
| 8 | + "path/filepath" |
| 9 | + "time" |
| 10 | + |
| 11 | + lumera "github.com/LumeraProtocol/supernode/pkg/lumera" |
| 12 | + "github.com/LumeraProtocol/supernode/pkg/raptorq" |
| 13 | + "github.com/LumeraProtocol/supernode/pkg/storage/rqstore" |
| 14 | + "github.com/LumeraProtocol/supernode/supernode/config" |
| 15 | +) |
| 16 | + |
| 17 | +func main() { |
| 18 | + // 1- ctx |
| 19 | + ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) |
| 20 | + defer cancel() |
| 21 | + |
| 22 | + // 2- Load the configuration |
| 23 | + cfgFile := "config.yml" |
| 24 | + appConfig, err := config.LoadConfig(cfgFile) |
| 25 | + if err != nil { |
| 26 | + log.Fatalf("Failed to load configuration file %s: %v", cfgFile, err) |
| 27 | + } |
| 28 | + |
| 29 | + // 3- RaptorQ configuration |
| 30 | + |
| 31 | + config := raptorq.NewConfig() |
| 32 | + |
| 33 | + config.RqFilesDir = appConfig.RaptorQConfig.FilesDir |
| 34 | + client := raptorq.NewClient() |
| 35 | + |
| 36 | + // Server address using the config |
| 37 | + address := fmt.Sprintf("%s:%d", config.Host, config.Port) |
| 38 | + |
| 39 | + // Connect to the server |
| 40 | + connection, err := client.Connect(ctx, address) |
| 41 | + if err != nil { |
| 42 | + log.Fatalf("Failed to connect to RaptorQ server at %s: %v", address, err) |
| 43 | + } |
| 44 | + defer connection.Close() |
| 45 | + |
| 46 | + // 4- Initialize the Lumera client |
| 47 | + lumeraClient, err := lumera.NewClient( |
| 48 | + ctx, |
| 49 | + lumera.WithGRPCAddr(appConfig.LumeraClientConfig.GRPCAddr), |
| 50 | + lumera.WithChainID(appConfig.LumeraClientConfig.ChainID), |
| 51 | + lumera.WithTimeout(appConfig.LumeraClientConfig.Timeout), |
| 52 | + ) |
| 53 | + if err != nil { |
| 54 | + log.Fatalf("Failed to initialize Lumera client: %v", err) |
| 55 | + } |
| 56 | + |
| 57 | + store, err := initRQStore() |
| 58 | + if err != nil { |
| 59 | + log.Fatalf("Failed to initialize RaptorQ store: %v", err) |
| 60 | + } |
| 61 | + rq := connection.RaptorQ(config, lumeraClient, store) |
| 62 | + |
| 63 | + // File path to process |
| 64 | + filePath := "/home/enxsys/Documents/Github/supernode/sdk/example/Excalidraw.zip" |
| 65 | + |
| 66 | + // 1. Call EncodeMetaData |
| 67 | + fmt.Println("Calling EncodeMetaData...") |
| 68 | + encodeMetaResp, err := rq.EncodeMetaData(ctx, raptorq.EncodeMetadataRequest{ |
| 69 | + Path: filePath, |
| 70 | + FilesNumber: 5, |
| 71 | + BlockHash: "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef", |
| 72 | + PastelId: "jXYWiR42BRvhu3Ts9SYzrXj2D4m7y3qYJL35R4buTd4TdmPZWwF9", |
| 73 | + }) |
| 74 | + if err != nil { |
| 75 | + log.Fatalf("EncodeMetaData failed: %v", err) |
| 76 | + } |
| 77 | + |
| 78 | + fmt.Println("EncodeMetaData response:", encodeMetaResp) |
| 79 | + |
| 80 | +} |
| 81 | + |
| 82 | +func initRQStore() (rqstore.Store, error) { |
| 83 | + |
| 84 | + home, _ := os.UserHomeDir() |
| 85 | + |
| 86 | + rqDir := filepath.Join(home, filepath.Join("supernode", "raptorq_files")) |
| 87 | + |
| 88 | + if err := os.MkdirAll(rqDir, 0700); err != nil { |
| 89 | + return nil, fmt.Errorf("failed to create RQ store directory: %w", err) |
| 90 | + } |
| 91 | + |
| 92 | + rqStoreFile := rqDir + "/rqstore.db" |
| 93 | + |
| 94 | + return rqstore.NewSQLiteRQStore(rqStoreFile) |
| 95 | +} |
0 commit comments