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

Support watching custom scripts #71

Merged
merged 6 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
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
622 changes: 447 additions & 175 deletions api-spec/protobuf/gen/go/ocean/v1/notification.pb.go

Large diffs are not rendered by default.

84 changes: 84 additions & 0 deletions api-spec/protobuf/gen/go/ocean/v1/notification_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion api-spec/protobuf/ocean/v1/account.proto
Original file line number Diff line number Diff line change
Expand Up @@ -156,4 +156,4 @@ message DeleteAccountRequest{
// Account namespace or label.
string account_name = 1;
}
message DeleteAccountResponse{}
message DeleteAccountResponse{}
30 changes: 27 additions & 3 deletions api-spec/protobuf/ocean/v1/notification.proto
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ import "ocean/v1/types.proto";
// server-side stream or by subscribing webhooks invoked whenever an event
// occurs.
service NotificationService {
// WatchExternalScript allows to get notified about utxos/txs related to the given
// external script, ie. not derived from a wallet account.
// The service answers with the label assigned to the given script.
// The label is used as identifier of the utxos/txs received from the streams.
rpc WatchExternalScript(WatchExternalScriptRequest) returns(WatchExternalScriptResponse);
// UnwatchExternalScript allows to stop watching for the script identified with
// the given label.
rpc UnwatchExternalScript(UnwatchExternalScriptRequest) returns(UnwatchExternalScriptResponse);

//**************//
// STREAMS //
//**************//
Expand All @@ -24,14 +33,29 @@ service NotificationService {
//***************//

// Adds a webhook registered for some kind of event.
rpc AddWebhook(AddWebhookRequest) returns(AddWebhookResponse){}
rpc AddWebhook(AddWebhookRequest) returns(AddWebhookResponse);

// Removes some previously added webhook.
rpc RemoveWebhook(RemoveWebhookRequest) returns(RemoveWebhookResponse){}
rpc RemoveWebhook(RemoveWebhookRequest) returns(RemoveWebhookResponse);

// Returns registered webhooks.
rpc ListWebhooks(ListWebhooksRequest) returns(ListWebhooksResponse){}
rpc ListWebhooks(ListWebhooksRequest) returns(ListWebhooksResponse);
}

message WatchExternalScriptRequest {
// The script to watch.
string script = 1;
// Optional: the private blinding key in case the script locks confidential utxos to unblind.
string blinding_key = 2;
}
message WatchExternalScriptResponse {
string label = 1;
}

message UnwatchExternalScriptRequest {
string label = 1;
}
message UnwatchExternalScriptResponse {}

message TransactionNotificationsRequest{}
message TransactionNotificationsResponse{
Expand Down
3 changes: 2 additions & 1 deletion internal/app-config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,8 @@ func (c *AppConfig) notificationService() *application.NotificationService {
}

rm, _ := c.repoManager()
c.notifySvc = application.NewNotificationService(rm)
bcs, _ := c.bcScanner()
c.notifySvc = application.NewNotificationService(rm, bcs)
return c.notifySvc
}

Expand Down
23 changes: 0 additions & 23 deletions internal/core/application/account_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,29 +269,6 @@ func (as *AccountService) registerHandlerForWalletEvents() {
as.bcScanner.StopWatchForAccount(event.AccountName)
},
)
// Start watching for when utxos are spent as soon as they are added to the storage.
as.repoManager.RegisterHandlerForUtxoEvent(
domain.UtxoAdded, func(event domain.UtxoEvent) {
accountName := event.Utxos[0].AccountName
as.bcScanner.WatchForUtxos(accountName, event.Utxos)
},
)

// In background, make sure to watch for all utxos to get notified when they are spent.
go func() {
utxos, err := as.repoManager.UtxoRepository().GetAllUtxos(
context.Background(),
)
if err != nil {
as.warn(err, "account service: error while getting all utxos")
return
}
for _, u := range utxos {
if !u.IsSpent() {
as.bcScanner.WatchForUtxos(u.AccountName, []domain.UtxoInfo{u.Info()})
}
}
}()
}

func (as *AccountService) listenToUtxoChannel(
Expand Down
Loading
Loading