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
4 changes: 2 additions & 2 deletions api/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (s *Server) SignPluginMessages(c echo.Context) error {
return fmt.Errorf("policy plugin ID mismatch")
}

if err := s.plugin.ValidateProposedTransactions(policy, []vtypes.PluginKeysignRequest{req}); err != nil {
if err := s.plugin.ValidateProposedTransactions(*policy, []vtypes.PluginKeysignRequest{req}); err != nil {
return fmt.Errorf("failed to validate transaction proposal: %w", err)
}

Expand Down Expand Up @@ -261,7 +261,7 @@ func (s *Server) DeletePluginPolicyById(c echo.Context) error {
// This is because we have different signature stored in the database.
policy.Signature = reqBody.Signature

if !s.verifyPolicySignature(policy) {
if !s.verifyPolicySignature(*policy) {
return c.JSON(http.StatusForbidden, NewErrorResponse("Invalid policy signature"))
}

Expand Down
38 changes: 0 additions & 38 deletions internal/types/broadcast.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@ import "fmt"

type BroadcastStrategy string

const (
BroadcastImmediate BroadcastStrategy = "IMMEDIATE"
BroadcastPrivate BroadcastStrategy = "PRIVATE_MEMPOOL"
BroadcastManual BroadcastStrategy = "MANUAL"
)

type TransactionError struct {
Code string
Message string
Expand All @@ -19,35 +13,3 @@ type TransactionError struct {
func (e *TransactionError) Error() string {
return fmt.Sprintf("%s: %s", e.Code, e.Message)
}

const (
// nonce related
ErrNonce = "NONCE_TOO_LOW"

// gas related
ErrGasTooLow = "GAS_TOO_LOW"
ErrGasTooHigh = "GAS_TOO_HIGH"
ErrGasPriceUnderpriced = "GAS_UNDERPRICED"

// balance related
ErrInsufficientFunds = "INSUFFICIENT_FUNDS"

// network/RPC related
ErrRPCConnectionFailed = "RPC_CONNECTION_FAILED"

// transaction state
ErrTxDropped = "TX_DROPPED"
ErrTxTimeout = "TX_TIMEOUT"

// contract related
ErrExecutionReverted = "EXECUTION_REVERTED"

// retriable errors
ErrRetriable = "RETRIABLE_ERROR"

// permanent failure
ErrPermanentFailure = "PERMANENT_FAILURE"

// other
ErrUnknown = "UNKNOWN_ERROR"
)
7 changes: 4 additions & 3 deletions plugin/fees/fees.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ import (
vtypes "github.com/vultisig/verifier/types"
"golang.org/x/sync/errgroup"

"github.com/vultisig/verifier/vault"

"github.com/vultisig/plugin/internal/types"
"github.com/vultisig/plugin/internal/verifierapi"
plugincommon "github.com/vultisig/plugin/plugin/common"
"github.com/vultisig/plugin/storage"
"github.com/vultisig/verifier/vault"
)

/*
Expand Down Expand Up @@ -161,7 +162,7 @@ func (fp *FeePlugin) collectFeesByPolicyId(ctx context.Context, policyId string)
if err != nil {
return fmt.Errorf("failed to get plugin policy: %w", err)
}
return fp.executeFeeCollection(ctx, policy)
return fp.executeFeeCollection(ctx, *policy)
}

func (fp *FeePlugin) collectAllFees(ctx context.Context) error {
Expand Down Expand Up @@ -229,7 +230,7 @@ func (fp *FeePlugin) executeFeeCollection(ctx context.Context, feePolicy vtypes.
"amount": checkAmount,
}).Info("Collecting fee ids: ", feesToCollect)

//Here we check if the fee collection is already in progress for any of the specific fee ids
// Here we check if the fee collection is already in progress for any of the specific fee ids
feeRun, err := fp.db.CreateFeeRun(ctx, feePolicy.ID, types.FeeRunStateDraft, feesResponse.Fees)
if err != nil {
return fmt.Errorf("failed to create fee run: %w", err)
Expand Down
11 changes: 6 additions & 5 deletions plugin/payroll/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ import (
"time"

"github.com/google/uuid"
"github.com/vultisig/plugin/common"
"github.com/vultisig/plugin/internal/scheduler"
"github.com/vultisig/plugin/internal/tasks"
"github.com/vultisig/recipes/chain"
reth "github.com/vultisig/recipes/ethereum"
"github.com/vultisig/recipes/sdk/evm"
Expand All @@ -22,6 +19,10 @@ import (
"github.com/vultisig/vultiserver/contexthelper"
"golang.org/x/sync/errgroup"

"github.com/vultisig/plugin/common"
"github.com/vultisig/plugin/internal/scheduler"
"github.com/vultisig/plugin/internal/tasks"

gcommon "github.com/ethereum/go-ethereum/common"
"github.com/hibiken/asynq"
"github.com/sirupsen/logrus"
Expand Down Expand Up @@ -58,7 +59,7 @@ func (p *PayrollPlugin) HandleSchedulerTrigger(c context.Context, t *asynq.Task)
return fmt.Errorf("failed to get plugin policy: %s, %w", err, asynq.SkipRetry)
}

reqs, err := p.ProposeTransactions(pluginPolicy)
reqs, err := p.ProposeTransactions(*pluginPolicy)
if err != nil {
p.logger.WithError(err).Error("p.ProposeTransactions")
return fmt.Errorf("p.ProposeTransactions: %s, %w", err, asynq.SkipRetry)
Expand All @@ -68,7 +69,7 @@ func (p *PayrollPlugin) HandleSchedulerTrigger(c context.Context, t *asynq.Task)
for _, _req := range reqs {
req := _req
eg.Go(func() error {
return p.initSign(ctx, req, pluginPolicy)
return p.initSign(ctx, req, *pluginPolicy)
})
}
err = eg.Wait()
Expand Down
16 changes: 4 additions & 12 deletions service/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type Policy interface {
UpdatePolicy(ctx context.Context, policy vtypes.PluginPolicy) (*vtypes.PluginPolicy, error)
DeletePolicy(ctx context.Context, policyID uuid.UUID, signature string) error
GetPluginPolicies(ctx context.Context, pluginID vtypes.PluginID, publicKey string, onlyActive bool) ([]vtypes.PluginPolicy, error)
GetPluginPolicy(ctx context.Context, policyID uuid.UUID) (vtypes.PluginPolicy, error)
GetPluginPolicy(ctx context.Context, policyID uuid.UUID) (*vtypes.PluginPolicy, error)
}

var _ Policy = (*PolicyService)(nil)
Expand Down Expand Up @@ -126,17 +126,9 @@ func (s *PolicyService) DeletePolicy(ctx context.Context, policyID uuid.UUID, si
}

func (s *PolicyService) GetPluginPolicies(ctx context.Context, pluginID vtypes.PluginID, publicKey string, onlyActive bool) ([]vtypes.PluginPolicy, error) {
policies, err := s.db.GetAllPluginPolicies(ctx, publicKey, pluginID, onlyActive)
if err != nil {
return nil, fmt.Errorf("failed to get policies: %w", err)
}
return policies, nil
return s.db.GetAllPluginPolicies(ctx, publicKey, pluginID, onlyActive)
Comment thread
johnnyluo marked this conversation as resolved.
}

func (s *PolicyService) GetPluginPolicy(ctx context.Context, policyID uuid.UUID) (vtypes.PluginPolicy, error) {
policy, err := s.db.GetPluginPolicy(ctx, policyID)
if err != nil {
return vtypes.PluginPolicy{}, fmt.Errorf("failed to get policy: %w", err)
}
return policy, nil
func (s *PolicyService) GetPluginPolicy(ctx context.Context, policyID uuid.UUID) (*vtypes.PluginPolicy, error) {
return s.db.GetPluginPolicy(ctx, policyID)
Comment thread
johnnyluo marked this conversation as resolved.
}
4 changes: 2 additions & 2 deletions storage/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
type DatabaseStorage interface {
Close() error

GetPluginPolicy(ctx context.Context, id uuid.UUID) (vtypes.PluginPolicy, error)
GetPluginPolicy(ctx context.Context, id uuid.UUID) (*vtypes.PluginPolicy, error)
GetAllPluginPolicies(ctx context.Context, publicKey string, pluginID vtypes.PluginID, onlyActive bool) ([]vtypes.PluginPolicy, error)
DeletePluginPolicyTx(ctx context.Context, dbTx pgx.Tx, id uuid.UUID) error
InsertPluginPolicyTx(ctx context.Context, dbTx pgx.Tx, policy vtypes.PluginPolicy) (*vtypes.PluginPolicy, error)
Expand All @@ -30,7 +30,7 @@ type DatabaseStorage interface {
UpdateTriggerStatus(ctx context.Context, policyID uuid.UUID, status types.TimeTriggerStatus) error
GetTriggerStatus(ctx context.Context, policyID uuid.UUID) (types.TimeTriggerStatus, error)

CreateFeeRun(ctx context.Context, policyId uuid.UUID, state types.FeeRunState, fees []verifierapi.FeeDto) (types.FeeRun, error)
CreateFeeRun(ctx context.Context, policyId uuid.UUID, state types.FeeRunState, fees []verifierapi.FeeDto) (*types.FeeRun, error)

Pool() *pgxpool.Pool
}
24 changes: 11 additions & 13 deletions storage/postgres/fees.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,54 +6,52 @@ import (
"fmt"

"github.com/google/uuid"

"github.com/vultisig/plugin/internal/types"
"github.com/vultisig/plugin/internal/verifierapi"
)

func (p *PostgresBackend) CreateFeeRun(ctx context.Context, policyId uuid.UUID, state types.FeeRunState, fees []verifierapi.FeeDto) (types.FeeRun, error) {

func (p *PostgresBackend) CreateFeeRun(ctx context.Context, policyId uuid.UUID, state types.FeeRunState, fees []verifierapi.FeeDto) (*types.FeeRun, error) {
// Check policy id is valid
query := `select plugin_id from plugin_policies where id = $1`
policyrows := p.pool.QueryRow(ctx, query, policyId)
var pluginId string
err := policyrows.Scan(&pluginId)
if err != nil {
return types.FeeRun{}, err
return nil, err
}
if pluginId != "vultisig-fees-feee" {
return types.FeeRun{}, errors.New("plugin id not found or not vultisig-fees-feee")
return nil, errors.New("plugin id not found or not vultisig-fees-feee")
Comment thread
johnnyluo marked this conversation as resolved.
}

tx, err := p.pool.Begin(ctx)
if err != nil {
return types.FeeRun{}, err
return nil, err
}

defer tx.Rollback(ctx)
runId := uuid.New()
_, err = tx.Exec(ctx, `insert into fee_run (id, status, policy_id) values ($1, $2, $3) returning id`, runId, state, policyId)
if err != nil {
tx.Rollback(ctx)
return types.FeeRun{}, fmt.Errorf("failed to insert fee run: %w", err)
return nil, fmt.Errorf("failed to insert fee run: %w", err)
}

for _, fee := range fees {
_, err = tx.Exec(ctx, `insert into fee (id, fee_run_id, amount) values ($1, $2, $3)`, fee.ID, runId, fee.Amount)
if err != nil {
tx.Rollback(ctx)
return types.FeeRun{}, fmt.Errorf("failed to insert fee: %s", err)
return nil, fmt.Errorf("failed to insert fee: %w", err)
}
}

err = tx.Commit(ctx)
if err != nil {
return types.FeeRun{}, fmt.Errorf("failed to commit transaction: %s", err)
return nil, fmt.Errorf("failed to commit transaction: %w", err)
}

var run types.FeeRun
err = p.pool.QueryRow(ctx, `select id, status, created_at, updated_at, tx_id, policy_id, total_amount, fee_count from fee_run_with_totals where id = $1`, runId).Scan(&run.ID, &run.Status, &run.CreatedAt, &run.UpdatedAt, &run.TxID, &run.PolicyID, &run.TotalAmount, &run.FeeCount)
if err != nil {
return types.FeeRun{}, fmt.Errorf("failed to get fee run (post commit): %s", err)
return nil, fmt.Errorf("failed to get fee run (post commit): %s", err)
}

return run, nil
return &run, nil
}
10 changes: 5 additions & 5 deletions storage/postgres/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import (
vtypes "github.com/vultisig/verifier/types"
)

func (p *PostgresBackend) GetPluginPolicy(ctx context.Context, id uuid.UUID) (vtypes.PluginPolicy, error) {
func (p *PostgresBackend) GetPluginPolicy(ctx context.Context, id uuid.UUID) (*vtypes.PluginPolicy, error) {
if p.pool == nil {
return vtypes.PluginPolicy{}, fmt.Errorf("database pool is nil")
return nil, fmt.Errorf("database pool is nil")
}
var policy vtypes.PluginPolicy
query := `
Expand All @@ -33,15 +33,15 @@ func (p *PostgresBackend) GetPluginPolicy(ctx context.Context, id uuid.UUID) (vt
)

if err != nil {
return vtypes.PluginPolicy{}, fmt.Errorf("failed to get policy: %w", err)
return nil, fmt.Errorf("failed to get policy: %w", err)
}
return policy, nil
return &policy, nil
}

func (p *PostgresBackend) GetAllPluginPolicies(ctx context.Context, publicKey string, pluginID vtypes.PluginID, onlyActive bool) ([]vtypes.PluginPolicy, error) {

if p.pool == nil {
return []vtypes.PluginPolicy{}, fmt.Errorf("database pool is nil")
return nil, fmt.Errorf("database pool is nil")
}

query := `
Expand Down