fix(db): update repository to save and load delegate_party_id field
Update session repository to properly handle delegate_party_id column: - Add delegate_party_id to Save method INSERT and UPDATE statements - Add DelegatePartyID field to sessionRow struct - Update FindByUUID, FindByStatus, FindExpired, FindActive SELECT queries - Update scanSessions method to scan and pass delegate_party_id - Remove placeholder empty string, now loads actual value from database This completes the delegate party functionality by ensuring the delegate party ID is persisted and retrieved correctly from the database. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
391448063f
commit
13e81e37c9
|
|
@ -37,12 +37,13 @@ func (r *SessionPostgresRepo) Save(ctx context.Context, session *entities.MPCSes
|
||||||
_, err = tx.ExecContext(ctx, `
|
_, err = tx.ExecContext(ctx, `
|
||||||
INSERT INTO mpc_sessions (
|
INSERT INTO mpc_sessions (
|
||||||
id, session_type, threshold_n, threshold_t, status,
|
id, session_type, threshold_n, threshold_t, status,
|
||||||
message_hash, public_key, created_by, created_at, updated_at, expires_at, completed_at, version
|
message_hash, public_key, delegate_party_id, created_by, created_at, updated_at, expires_at, completed_at, version
|
||||||
) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13)
|
) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14)
|
||||||
ON CONFLICT (id) DO UPDATE SET
|
ON CONFLICT (id) DO UPDATE SET
|
||||||
status = EXCLUDED.status,
|
status = EXCLUDED.status,
|
||||||
message_hash = EXCLUDED.message_hash,
|
message_hash = EXCLUDED.message_hash,
|
||||||
public_key = EXCLUDED.public_key,
|
public_key = EXCLUDED.public_key,
|
||||||
|
delegate_party_id = EXCLUDED.delegate_party_id,
|
||||||
updated_at = EXCLUDED.updated_at,
|
updated_at = EXCLUDED.updated_at,
|
||||||
completed_at = EXCLUDED.completed_at,
|
completed_at = EXCLUDED.completed_at,
|
||||||
version = EXCLUDED.version
|
version = EXCLUDED.version
|
||||||
|
|
@ -54,6 +55,7 @@ func (r *SessionPostgresRepo) Save(ctx context.Context, session *entities.MPCSes
|
||||||
session.Status.String(),
|
session.Status.String(),
|
||||||
session.MessageHash,
|
session.MessageHash,
|
||||||
session.PublicKey,
|
session.PublicKey,
|
||||||
|
session.DelegatePartyID,
|
||||||
session.CreatedBy,
|
session.CreatedBy,
|
||||||
session.CreatedAt,
|
session.CreatedAt,
|
||||||
session.UpdatedAt,
|
session.UpdatedAt,
|
||||||
|
|
@ -116,7 +118,7 @@ func (r *SessionPostgresRepo) FindByUUID(ctx context.Context, id uuid.UUID) (*en
|
||||||
var session sessionRow
|
var session sessionRow
|
||||||
err := r.db.QueryRowContext(ctx, `
|
err := r.db.QueryRowContext(ctx, `
|
||||||
SELECT id, session_type, threshold_n, threshold_t, status,
|
SELECT id, session_type, threshold_n, threshold_t, status,
|
||||||
message_hash, public_key, created_by, created_at, updated_at, expires_at, completed_at, version
|
message_hash, public_key, delegate_party_id, created_by, created_at, updated_at, expires_at, completed_at, version
|
||||||
FROM mpc_sessions WHERE id = $1
|
FROM mpc_sessions WHERE id = $1
|
||||||
`, id).Scan(
|
`, id).Scan(
|
||||||
&session.ID,
|
&session.ID,
|
||||||
|
|
@ -126,6 +128,7 @@ func (r *SessionPostgresRepo) FindByUUID(ctx context.Context, id uuid.UUID) (*en
|
||||||
&session.Status,
|
&session.Status,
|
||||||
&session.MessageHash,
|
&session.MessageHash,
|
||||||
&session.PublicKey,
|
&session.PublicKey,
|
||||||
|
&session.DelegatePartyID,
|
||||||
&session.CreatedBy,
|
&session.CreatedBy,
|
||||||
&session.CreatedAt,
|
&session.CreatedAt,
|
||||||
&session.UpdatedAt,
|
&session.UpdatedAt,
|
||||||
|
|
@ -154,7 +157,7 @@ func (r *SessionPostgresRepo) FindByUUID(ctx context.Context, id uuid.UUID) (*en
|
||||||
session.Status,
|
session.Status,
|
||||||
session.MessageHash,
|
session.MessageHash,
|
||||||
session.PublicKey,
|
session.PublicKey,
|
||||||
"", // delegatePartyID - not stored in DB yet, will be empty for old sessions
|
session.DelegatePartyID,
|
||||||
session.CreatedBy,
|
session.CreatedBy,
|
||||||
session.CreatedAt,
|
session.CreatedAt,
|
||||||
session.UpdatedAt,
|
session.UpdatedAt,
|
||||||
|
|
@ -169,7 +172,7 @@ func (r *SessionPostgresRepo) FindByUUID(ctx context.Context, id uuid.UUID) (*en
|
||||||
func (r *SessionPostgresRepo) FindByStatus(ctx context.Context, status value_objects.SessionStatus) ([]*entities.MPCSession, error) {
|
func (r *SessionPostgresRepo) FindByStatus(ctx context.Context, status value_objects.SessionStatus) ([]*entities.MPCSession, error) {
|
||||||
rows, err := r.db.QueryContext(ctx, `
|
rows, err := r.db.QueryContext(ctx, `
|
||||||
SELECT id, session_type, threshold_n, threshold_t, status,
|
SELECT id, session_type, threshold_n, threshold_t, status,
|
||||||
message_hash, public_key, created_by, created_at, updated_at, expires_at, completed_at, version
|
message_hash, public_key, delegate_party_id, created_by, created_at, updated_at, expires_at, completed_at, version
|
||||||
FROM mpc_sessions WHERE status = $1
|
FROM mpc_sessions WHERE status = $1
|
||||||
`, status.String())
|
`, status.String())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -184,7 +187,7 @@ func (r *SessionPostgresRepo) FindByStatus(ctx context.Context, status value_obj
|
||||||
func (r *SessionPostgresRepo) FindExpired(ctx context.Context) ([]*entities.MPCSession, error) {
|
func (r *SessionPostgresRepo) FindExpired(ctx context.Context) ([]*entities.MPCSession, error) {
|
||||||
rows, err := r.db.QueryContext(ctx, `
|
rows, err := r.db.QueryContext(ctx, `
|
||||||
SELECT id, session_type, threshold_n, threshold_t, status,
|
SELECT id, session_type, threshold_n, threshold_t, status,
|
||||||
message_hash, public_key, created_by, created_at, updated_at, expires_at, completed_at, version
|
message_hash, public_key, delegate_party_id, created_by, created_at, updated_at, expires_at, completed_at, version
|
||||||
FROM mpc_sessions
|
FROM mpc_sessions
|
||||||
WHERE expires_at < NOW() AND status IN ('created', 'in_progress')
|
WHERE expires_at < NOW() AND status IN ('created', 'in_progress')
|
||||||
`)
|
`)
|
||||||
|
|
@ -200,7 +203,7 @@ func (r *SessionPostgresRepo) FindExpired(ctx context.Context) ([]*entities.MPCS
|
||||||
func (r *SessionPostgresRepo) FindActive(ctx context.Context) ([]*entities.MPCSession, error) {
|
func (r *SessionPostgresRepo) FindActive(ctx context.Context) ([]*entities.MPCSession, error) {
|
||||||
rows, err := r.db.QueryContext(ctx, `
|
rows, err := r.db.QueryContext(ctx, `
|
||||||
SELECT id, session_type, threshold_n, threshold_t, status,
|
SELECT id, session_type, threshold_n, threshold_t, status,
|
||||||
message_hash, public_key, created_by, created_at, updated_at, expires_at, completed_at, version
|
message_hash, public_key, delegate_party_id, created_by, created_at, updated_at, expires_at, completed_at, version
|
||||||
FROM mpc_sessions
|
FROM mpc_sessions
|
||||||
WHERE status IN ('created', 'in_progress')
|
WHERE status IN ('created', 'in_progress')
|
||||||
ORDER BY created_at ASC
|
ORDER BY created_at ASC
|
||||||
|
|
@ -483,6 +486,7 @@ func (r *SessionPostgresRepo) scanSessions(ctx context.Context, rows *sql.Rows)
|
||||||
&s.Status,
|
&s.Status,
|
||||||
&s.MessageHash,
|
&s.MessageHash,
|
||||||
&s.PublicKey,
|
&s.PublicKey,
|
||||||
|
&s.DelegatePartyID,
|
||||||
&s.CreatedBy,
|
&s.CreatedBy,
|
||||||
&s.CreatedAt,
|
&s.CreatedAt,
|
||||||
&s.UpdatedAt,
|
&s.UpdatedAt,
|
||||||
|
|
@ -507,7 +511,7 @@ func (r *SessionPostgresRepo) scanSessions(ctx context.Context, rows *sql.Rows)
|
||||||
s.Status,
|
s.Status,
|
||||||
s.MessageHash,
|
s.MessageHash,
|
||||||
s.PublicKey,
|
s.PublicKey,
|
||||||
"", // delegatePartyID - not stored in DB yet
|
s.DelegatePartyID,
|
||||||
s.CreatedBy,
|
s.CreatedBy,
|
||||||
s.CreatedAt,
|
s.CreatedAt,
|
||||||
s.UpdatedAt,
|
s.UpdatedAt,
|
||||||
|
|
@ -527,19 +531,20 @@ func (r *SessionPostgresRepo) scanSessions(ctx context.Context, rows *sql.Rows)
|
||||||
|
|
||||||
// Row types for scanning
|
// Row types for scanning
|
||||||
type sessionRow struct {
|
type sessionRow struct {
|
||||||
ID uuid.UUID
|
ID uuid.UUID
|
||||||
SessionType string
|
SessionType string
|
||||||
ThresholdN int
|
ThresholdN int
|
||||||
ThresholdT int
|
ThresholdT int
|
||||||
Status string
|
Status string
|
||||||
MessageHash []byte
|
MessageHash []byte
|
||||||
PublicKey []byte
|
PublicKey []byte
|
||||||
CreatedBy string
|
DelegatePartyID string
|
||||||
CreatedAt time.Time
|
CreatedBy string
|
||||||
UpdatedAt time.Time
|
CreatedAt time.Time
|
||||||
ExpiresAt time.Time
|
UpdatedAt time.Time
|
||||||
CompletedAt *time.Time
|
ExpiresAt time.Time
|
||||||
Version int64
|
CompletedAt *time.Time
|
||||||
|
Version int64
|
||||||
}
|
}
|
||||||
|
|
||||||
type participantRow struct {
|
type participantRow struct {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue