mirror of
https://github.com/aljazceru/ark.git
synced 2025-12-24 07:24:19 +01:00
* 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
48 lines
1.1 KiB
Go
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()
|
|
}
|