Skip to content
This repository was archived by the owner on Feb 8, 2026. It is now read-only.
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
41 changes: 22 additions & 19 deletions api/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ import (
v1 "github.com/vultisig/commondata/go/vultisig/vault/v1"
"github.com/vultisig/mobile-tss-lib/tss"
vcommon "github.com/vultisig/verifier/common"
"github.com/vultisig/verifier/tx_indexer/pkg/storage"
vtypes "github.com/vultisig/verifier/types"

"github.com/vultisig/plugin/common"
"github.com/vultisig/plugin/internal/sigutil"
"github.com/vultisig/plugin/internal/tasks"
"github.com/vultisig/plugin/internal/types"
)

type ErrorResponse struct {
Expand Down Expand Up @@ -99,21 +99,36 @@ func (s *Server) SignPluginMessages(c echo.Context) error {

req.Parties = []string{common.PluginPartyID, common.VerifierPartyID}

if s.txIndexerService != nil {
for i, msg := range req.Messages {
txToTrack, e := s.txIndexerService.CreateTx(
c.Request().Context(),
storage.CreateTxDto{
PluginID: policy.PluginID,
ChainID: msg.Chain,
PolicyID: policy.ID,
FromPublicKey: req.PublicKey,
ProposedTxHex: req.Transaction,
},
)
if e != nil {
return fmt.Errorf("s.txIndexerService.CreateTx: %w", e)
}
req.Messages[i].TxIndexerID = txToTrack.ID.String()
}
}

buf, err := json.Marshal(req)
if err != nil {
return fmt.Errorf("fail to marshal to json, err: %w", err)
}

// TODO: check if this is relevant
// check that tx is done only once per period
// (by @webpiratt: period depends on particular dca/payroll strategy (monthly/daily tx send, etc),
// maybe consider to add some additional metadata there to enable tx replay protection correctly)
// should we also copy the db to the vultiserver, so that it can be used by the vultiserver (and use scheduler.go)? or query the blockchain?

txToSign, err := s.db.GetTransactionByHash(c.Request().Context(), txHash)
if err != nil {
s.logger.Errorf("Failed to get transaction by hash from database: %v", err)
return fmt.Errorf("fail to get transaction by hash: %w", err)
}

s.logger.Debug("PLUGIN SERVER: KEYSIGN TASK")

ti, err := s.client.EnqueueContext(c.Request().Context(),
Expand All @@ -122,22 +137,10 @@ func (s *Server) SignPluginMessages(c echo.Context) error {
asynq.Timeout(2*time.Minute),
asynq.Retention(5*time.Minute),
asynq.Queue(tasks.QUEUE_NAME))

if err != nil {
txToSign.Metadata["error"] = err.Error()
if updateErr := s.db.UpdateTransactionStatus(c.Request().Context(), txToSign.ID, types.StatusSigningFailed, txToSign.Metadata); updateErr != nil {
s.logger.Errorf("Failed to update transaction status: %v", updateErr)
}
return fmt.Errorf("fail to enqueue keysign task: %w", err)
}

txToSign.Metadata["task_id"] = ti.ID
if err := s.db.UpdateTransactionStatus(c.Request().Context(), txToSign.ID, types.StatusSigned, txToSign.Metadata); err != nil {
s.logger.Errorf("Failed to update transaction with task ID: %v", err)
}

s.logger.Infof("Created transaction history for tx from plugin: %s...", req.Transaction[:min(20, len(req.Transaction))])

return c.JSON(http.StatusOK, ti.ID)
}

Expand Down
50 changes: 27 additions & 23 deletions api/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/vultisig/mobile-tss-lib/tss"
vcommon "github.com/vultisig/verifier/common"
"github.com/vultisig/verifier/plugin"
"github.com/vultisig/verifier/tx_indexer"
vtypes "github.com/vultisig/verifier/types"
"github.com/vultisig/verifier/vault"

Expand All @@ -30,18 +31,19 @@ import (
)

type Server struct {
cfg ServerConfig
db storage.DatabaseStorage
redis *storage.RedisStorage
vaultStorage vault.Storage
client *asynq.Client
inspector *asynq.Inspector
sdClient *statsd.Client
scheduler *scheduler.SchedulerService
policyService service.Policy
plugin plugin.Plugin
logger *logrus.Logger
mode string
cfg ServerConfig
db storage.DatabaseStorage
redis *storage.RedisStorage
vaultStorage vault.Storage
client *asynq.Client
inspector *asynq.Inspector
sdClient *statsd.Client
scheduler *scheduler.SchedulerService
policyService service.Policy
plugin plugin.Plugin
txIndexerService *tx_indexer.Service
logger *logrus.Logger
mode string
}

// NewServer returns a new server.
Expand All @@ -55,6 +57,7 @@ func NewServer(
inspector *asynq.Inspector,
sdClient *statsd.Client,
p plugin.Plugin,
txIndexerService *tx_indexer.Service,
) *Server {
logger := logrus.WithField("service", "plugin").Logger
schedulerService, err := scheduler.NewSchedulerService(
Expand All @@ -73,17 +76,18 @@ func NewServer(
}

return &Server{
cfg: cfg,
redis: redis,
client: client,
inspector: inspector,
sdClient: sdClient,
vaultStorage: vaultStorage,
plugin: p,
db: db,
scheduler: schedulerService,
logger: logger,
policyService: policyService,
cfg: cfg,
redis: redis,
client: client,
inspector: inspector,
sdClient: sdClient,
vaultStorage: vaultStorage,
plugin: p,
db: db,
scheduler: schedulerService,
logger: logger,
policyService: policyService,
txIndexerService: txIndexerService,
}
}

Expand Down
20 changes: 19 additions & 1 deletion cmd/dca/server/main.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package main

import (
"context"
"fmt"
"net"

"github.com/DataDog/datadog-go/statsd"
"github.com/hibiken/asynq"
"github.com/sirupsen/logrus"
"github.com/vultisig/verifier/tx_indexer"
tx_indexer_storage "github.com/vultisig/verifier/tx_indexer/pkg/storage"
"github.com/vultisig/verifier/vault"

"github.com/vultisig/plugin/api"
Expand All @@ -16,6 +19,8 @@ import (
)

func main() {
ctx := context.Background()

cfg, err := GetConfigure()
if err != nil {
panic(err)
Expand Down Expand Up @@ -50,6 +55,17 @@ func main() {
panic(err)
}

txIndexerStore, err := tx_indexer_storage.NewPostgresTxIndexStore(ctx, cfg.Database.DSN)
if err != nil {
panic(fmt.Errorf("tx_indexer_storage.NewPostgresTxIndexStore: %w", err))
}

txIndexerService := tx_indexer.NewService(
logger,
txIndexerStore,
tx_indexer.Chains(),
)

db, err := postgres.NewPostgresBackend(cfg.Database.DSN, nil)
if err != nil {
logger.Fatalf("Failed to connect to database: %v", err)
Expand All @@ -67,7 +83,9 @@ func main() {
client,
inspector,
sdClient,
p)
p,
txIndexerService,
)
if err := server.StartServer(); err != nil {
panic(err)
}
Expand Down
3 changes: 3 additions & 0 deletions cmd/dca/worker/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ import (
)

type DCAWorkerConfig struct {
Database struct {
DSN string `mapstructure:"dsn" json:"dsn,omitempty"`
} `mapstructure:"database" json:"database,omitempty"`
Comment thread
webpiratt marked this conversation as resolved.
Redis storage.RedisConfig `mapstructure:"redis" json:"redis,omitempty"`
BlockStorage vault_config.BlockStorageConfig `mapstructure:"block_storage" json:"block_storage,omitempty"`
VaultServiceConfig vault_config.Config `mapstructure:"vault_service" json:"vault_service,omitempty"`
Expand Down
19 changes: 18 additions & 1 deletion cmd/dca/worker/main.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
package main

import (
"context"
"fmt"

"github.com/DataDog/datadog-go/statsd"
"github.com/hibiken/asynq"
"github.com/sirupsen/logrus"
"github.com/vultisig/verifier/tx_indexer"
"github.com/vultisig/verifier/tx_indexer/pkg/storage"
"github.com/vultisig/verifier/vault"

"github.com/vultisig/plugin/internal/tasks"
)

func main() {
ctx := context.Background()

cfg, err := GetConfigure()
if err != nil {
panic(err)
Expand Down Expand Up @@ -45,12 +50,24 @@ func main() {
},
},
)

txIndexerStore, err := storage.NewPostgresTxIndexStore(ctx, cfg.Database.DSN)
if err != nil {
panic(fmt.Errorf("storage.NewPostgresTxIndexStore: %w", err))
}

txIndexerService := tx_indexer.NewService(
logger,
txIndexerStore,
tx_indexer.Chains(),
)

vaultService, err := vault.NewManagementService(
cfg.VaultServiceConfig,
client,
sdClient,
vaultStorage,
nil, // not used in plugin
txIndexerService,
)
if err != nil {
panic(fmt.Errorf("failed to create vault service: %w", err))
Expand Down
20 changes: 19 additions & 1 deletion cmd/payroll/server/main.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package main

import (
"context"
"fmt"
"net"

"github.com/DataDog/datadog-go/statsd"
"github.com/hibiken/asynq"
"github.com/sirupsen/logrus"
"github.com/vultisig/verifier/tx_indexer"
tx_indexer_storage "github.com/vultisig/verifier/tx_indexer/pkg/storage"
"github.com/vultisig/verifier/vault"

"github.com/vultisig/plugin/api"
Expand All @@ -16,6 +19,8 @@ import (
)

func main() {
ctx := context.Background()

cfg, err := GetConfigure()
if err != nil {
panic(err)
Expand Down Expand Up @@ -51,6 +56,17 @@ func main() {
panic(err)
}

txIndexerStore, err := tx_indexer_storage.NewPostgresTxIndexStore(ctx, cfg.Database.DSN)
if err != nil {
panic(fmt.Errorf("tx_indexer_storage.NewPostgresTxIndexStore: %w", err))
}

Comment thread
webpiratt marked this conversation as resolved.
txIndexerService := tx_indexer.NewService(
logger,
txIndexerStore,
tx_indexer.Chains(),
)

db, err := postgres.NewPostgresBackend(cfg.Database.DSN, nil)
if err != nil {
logger.Fatalf("Failed to connect to database: %v", err)
Expand All @@ -68,7 +84,9 @@ func main() {
client,
inspector,
sdClient,
p)
p,
txIndexerService,
)
if err := server.StartServer(); err != nil {
panic(err)
}
Expand Down
19 changes: 18 additions & 1 deletion cmd/payroll/worker/main.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package main

import (
"context"
"fmt"

"github.com/DataDog/datadog-go/statsd"
"github.com/hibiken/asynq"
"github.com/sirupsen/logrus"
"github.com/vultisig/verifier/tx_indexer"
"github.com/vultisig/verifier/tx_indexer/pkg/storage"
"github.com/vultisig/verifier/vault"

"github.com/vultisig/plugin/internal/scheduler"
Expand All @@ -15,6 +18,8 @@ import (
)

func main() {
ctx := context.Background()

cfg, err := GetConfigure()
if err != nil {
panic(err)
Expand Down Expand Up @@ -49,12 +54,24 @@ func main() {
},
},
)

txIndexerStore, err := storage.NewPostgresTxIndexStore(ctx, cfg.Database.DSN)
if err != nil {
panic(fmt.Errorf("storage.NewPostgresTxIndexStore: %w", err))
}

txIndexerService := tx_indexer.NewService(
logger,
txIndexerStore,
tx_indexer.Chains(),
)

vaultService, err := vault.NewManagementService(
cfg.VaultServiceConfig,
client,
sdClient,
vaultStorage,
nil, // not used in plugin
txIndexerService,
)
if err != nil {
panic(fmt.Errorf("failed to create vault service: %w", err))
Expand Down
Loading