Files
ark/server/internal/infrastructure/ocean-wallet/notification.go
Pietralberto Mazza dc00d60585 Rename folders (#97)
* Rename arkd folder & drop cli

* Rename ark cli folder & update docs

* Update readme

* Fix

* scripts: add build-all

* Add target to build cli for all platforms

* Update build scripts

---------

Co-authored-by: tiero <3596602+tiero@users.noreply.github.com>
2024-02-09 19:32:58 +01:00

48 lines
1.1 KiB
Go

package oceanwallet
import (
"context"
"crypto/sha256"
"encoding/hex"
pb "github.com/ark-network/ark/api-spec/protobuf/gen/ocean/v1"
"github.com/ark-network/ark/internal/core/domain"
"github.com/btcsuite/btcd/chaincfg/chainhash"
)
func (s *service) WatchScripts(ctx context.Context, scripts []string) error {
for _, script := range scripts {
if _, err := s.notifyClient.WatchExternalScript(ctx, &pb.WatchExternalScriptRequest{
Script: script,
}); err != nil {
return err
}
}
return nil
}
func (s *service) UnwatchScripts(ctx context.Context, scripts []string) error {
for _, script := range scripts {
scriptHash := calcScriptHash(script)
if _, err := s.notifyClient.UnwatchExternalScript(ctx, &pb.UnwatchExternalScriptRequest{
Label: scriptHash,
}); err != nil {
return err
}
}
return nil
}
func (s *service) GetNotificationChannel(ctx context.Context) chan []domain.VtxoKey {
return s.chVtxos
}
func calcScriptHash(script string) string {
buf, _ := hex.DecodeString(script)
hashedBuf := sha256.Sum256(buf)
hash, _ := chainhash.NewHash(hashedBuf[:])
return hash.String()
}