Files
ark/server/internal/infrastructure/wallet/liquid-standalone/notification.go
Marco Argentieri 1b0252f3e4 Migrate to Go Workspaces (#243)
* api-spec: move the api-spec to root and init go.mod

* go mod tidy

* move buf files in the root as well

* gh action for api-spec changes only

* gh action for api-spec on push and pr

* introduce go.work and remove all replaces

* solve dependencies and force btcd/btcec@v2.3.3

* go work sync

* force btcd/btcec@v2.3.3

* go mod tidy
2024-08-13 03:27:41 +02: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/server/internal/core/ports"
"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 map[string]ports.VtxoWithValue {
return s.chVtxos
}
func calcScriptHash(script string) string {
buf, _ := hex.DecodeString(script)
hashedBuf := sha256.Sum256(buf)
hash, _ := chainhash.NewHash(hashedBuf[:])
return hash.String()
}