Skip to content

Commit 4936bc4

Browse files
sdk api updates
1 parent ab6d472 commit 4936bc4

File tree

10 files changed

+114
-214
lines changed

10 files changed

+114
-214
lines changed

sdk/action/client.go

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package action
33
import (
44
"context"
55
"fmt"
6-
"os"
76

87
"github.com/LumeraProtocol/supernode/sdk/config"
98
"github.com/LumeraProtocol/supernode/sdk/event"
@@ -15,7 +14,7 @@ import (
1514

1615
// Client defines the interface for action operations
1716
type Client interface {
18-
StartCascade(ctx context.Context, fileHash string, actionID string, filePath string, signedData string) (string, error)
17+
StartCascade(ctx context.Context, data []byte, actionID string) (string, error)
1918
DeleteTask(ctx context.Context, taskID string) error
2019
GetTask(ctx context.Context, taskID string) (*task.TaskEntry, bool)
2120
SubscribeToEvents(ctx context.Context, eventType event.EventType, handler event.Handler) error
@@ -54,36 +53,20 @@ func NewClient(ctx context.Context, config config.Config, logger log.Logger, key
5453

5554
// StartCascade initiates a cascade operation
5655
func (c *ClientImpl) StartCascade(ctx context.Context,
57-
fileHash string,
56+
data []byte,
5857
actionID string,
59-
filePath string,
60-
signedData string,
6158
) (string, error) {
62-
c.logger.Debug(ctx, "Starting cascade operation",
63-
"fileHash", fileHash,
64-
"actionID", actionID,
65-
"filePath", filePath,
66-
)
67-
68-
if fileHash == "" {
69-
c.logger.Error(ctx, "Empty file hash provided")
70-
return "", ErrEmptyFileHash
71-
}
59+
7260
if actionID == "" {
7361
c.logger.Error(ctx, "Empty action ID provided")
7462
return "", ErrEmptyActionID
7563
}
76-
if filePath == "" {
77-
c.logger.Error(ctx, "Empty file path provided")
78-
return "", ErrEmptyFilePath
79-
}
80-
_, err := os.Stat(filePath)
81-
if err != nil {
82-
c.logger.Error(ctx, "File not found", "filePath", filePath)
83-
return "", ErrEmptyFileNotFound
64+
if len(data) == 0 {
65+
c.logger.Error(ctx, "Empty data provided")
66+
return "", ErrEmptyData
8467
}
8568

86-
taskID, err := c.taskManager.CreateCascadeTask(ctx, fileHash, actionID, filePath, signedData)
69+
taskID, err := c.taskManager.CreateCascadeTask(ctx, data, actionID)
8770
if err != nil {
8871
c.logger.Error(ctx, "Failed to create cascade task", "error", err)
8972
return "", fmt.Errorf("failed to create cascade task: %w", err)

sdk/action/errors.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,14 @@ import (
66
)
77

88
var (
9-
ErrEmptyFileHash = errors.New("file hash cannot be empty")
10-
ErrEmptyActionID = errors.New("action ID cannot be empty")
11-
ErrEmptyFilePath = errors.New("file path cannot be empty")
12-
ErrEmptyFileNotFound = errors.New("file not found at the specified path")
13-
ErrNoValidAction = errors.New("no action found with the specified ID")
14-
ErrInvalidAction = errors.New("action is not in a valid state")
15-
ErrNoSupernodes = errors.New("no valid supernodes available")
16-
ErrTaskCreation = errors.New("failed to create task")
17-
ErrCommunication = errors.New("communication with supernode failed")
9+
ErrEmptyData = errors.New("data cannot be empty")
10+
ErrEmptyActionID = errors.New("action ID cannot be empty")
11+
ErrEmptyFileName = errors.New("file name cannot be empty")
12+
ErrNoValidAction = errors.New("no action found with the specified ID")
13+
ErrInvalidAction = errors.New("action is not in a valid state")
14+
ErrNoSupernodes = errors.New("no valid supernodes available")
15+
ErrTaskCreation = errors.New("failed to create task")
16+
ErrCommunication = errors.New("communication with supernode failed")
1817
)
1918

2019
// SupernodeError represents an error related to supernode operations

sdk/adapters/supernodeservice/types.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,12 @@ import (
66
"google.golang.org/grpc"
77
)
88

9-
type UploadInputDataRequest struct {
10-
Filename string
11-
ActionID string
12-
DataHash string
13-
SignedData string
14-
RqMax int32
15-
FilePath string
9+
type CascadeSupernodeRegisterRequest struct {
10+
data []byte
11+
actionID string
1612
}
1713

18-
type UploadInputDataResponse struct {
14+
type CascadeSupernodeRegisterResponse struct {
1915
Success bool
2016
Message string
2117
}

sdk/config/config.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const (
99
DefaultLocalCosmosAddress = "lumera1qv3" // Example address - replace with actual
1010
DefaultChainID = "lumera-testnet" // Example chain ID - replace with actual
1111
DefaultGRPCAddr = "127.0.0.1:9090"
12-
DefaultTimeout = 10 * time.Second
12+
DefaultTimeout = 10
1313
)
1414

1515
// AccountConfig holds peer-to-peer addresses, ports, etc.
@@ -19,9 +19,10 @@ type AccountConfig struct {
1919

2020
// LumeraConfig wraps all chain-specific dials.
2121
type LumeraConfig struct {
22-
GRPCAddr string // REQUIRED – e.g. "127.0.0.1:9090"
23-
ChainID string // REQUIRED – e.g. "lumera-mainnet"
24-
Timeout time.Duration // OPTIONAL – defaults to DefaultTimeout
22+
GRPCAddr string // REQUIRED – e.g. "127.0.0.1:9090"
23+
ChainID string // REQUIRED – e.g. "lumera-mainnet"
24+
Timeout int // OPTIONAL – defaults to DefaultTimeout
25+
KeyName string
2526
}
2627

2728
type Config struct {

sdk/task/cascade.go

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,23 +24,20 @@ const (
2424

2525
type CascadeTask struct {
2626
BaseTask
27-
FileHash string
28-
FilePath string
29-
SignedData string
27+
data []byte
28+
actionId string
3029
}
3130

3231
// NewCascadeTask creates a new CascadeTask using a BaseTask plus cascade-specific parameters
3332
func NewCascadeTask(
3433
base BaseTask,
35-
fileHash string,
36-
filePath string,
37-
signedData string,
34+
data []byte,
35+
actionId string,
36+
3837
) *CascadeTask {
3938
return &CascadeTask{
40-
BaseTask: base,
41-
FileHash: fileHash,
42-
FilePath: filePath,
43-
SignedData: signedData,
39+
BaseTask: base,
40+
data: data,
4441
}
4542
}
4643

@@ -156,7 +153,7 @@ func (t *CascadeTask) registerWithSupernodes(ctx context.Context, supernodes lum
156153
clientFactory := net.NewClientFactory(ctx, t.logger, t.keyring, factoryCfg)
157154

158155
req := &supernodeservice.UploadInputDataRequest{
159-
Filename: filepath.Base(t.FilePath),
156+
Data: filepath.Base(t.FilePath),
160157
ActionID: t.ActionID,
161158
DataHash: t.FileHash,
162159
SignedData: t.SignedData,

sdk/task/manager.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const MAX_EVENT_WORKERS = 100
1717

1818
// Manager handles task creation and management
1919
type Manager interface {
20-
CreateCascadeTask(ctx context.Context, fileHash, actionID, filePath string, signedData string) (string, error)
20+
CreateCascadeTask(ctx context.Context, data []byte, actionID string) (string, error)
2121
GetTask(ctx context.Context, taskID string) (*TaskEntry, bool)
2222
DeleteTask(ctx context.Context, taskID string) error
2323
SubscribeToEvents(ctx context.Context, eventType event.EventType, handler event.Handler)
@@ -84,14 +84,9 @@ func NewManager(
8484
// CreateCascadeTask creates and starts a Cascade task using the new pattern
8585
func (m *ManagerImpl) CreateCascadeTask(
8686
ctx context.Context,
87-
fileHash string,
87+
data []byte,
8888
actionID string,
89-
filePath string,
90-
signedData string,
9189
) (string, error) {
92-
m.logger.Info(ctx, "Creating cascade task",
93-
"fileHash", fileHash,
94-
"actionID", actionID)
9590

9691
// Generate task ID
9792
// slice this to 8 bytes
@@ -110,7 +105,7 @@ func (m *ManagerImpl) CreateCascadeTask(
110105
logger: m.logger,
111106
}
112107
// Create cascade-specific task
113-
task := NewCascadeTask(baseTask, fileHash, filePath, signedData)
108+
task := NewCascadeTask(baseTask, data, actionID)
114109

115110
// Store task in cache
116111
m.taskCache.Set(ctx, taskID, task, TaskTypeCascade)

sdk/task/task.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ const (
2929
)
3030

3131
// EventCallback is a function that processes events from tasks
32-
// Now includes context parameter for proper context propagation
3332
type EventCallback func(ctx context.Context, e event.Event)
3433

3534
// Task is the interface that all task types must implement

0 commit comments

Comments
 (0)