Skip to content

Commit

Permalink
add signedat to the transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
charymalloju committed Nov 11, 2024
1 parent 43dc0dc commit dd81a62
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
18 changes: 16 additions & 2 deletions server/handler/transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ func (h *Handler) SignTransaction(c echo.Context) error {
})
}

_, err = h.DB.Exec("UPDATE transactions SET signatures=$1 WHERE id=$2", bz, id)
_, err = h.DB.Exec("UPDATE transactions SET signatures=$1, signed_at=$2 WHERE id=$3", bz, time.Now().UTC(), id)
if err != nil {
return c.JSON(http.StatusBadRequest, model.ErrorResponse{
Status: "error",
Expand Down Expand Up @@ -513,7 +513,21 @@ func (h *Handler) DeleteTransaction(c echo.Context) error {
})
}

_, err = h.DB.Exec("UPDATE transactions SET signatures='[]'::jsonb WHERE multisig_address=$1 and status='PENDING'", address)
row := h.DB.QueryRow(`SELECT signed_at FROM transactions WHERE id=$1 AND multisig_address=$2`, txId, address)

var transaction schema.Transaction
if err := row.Scan(
&transaction.Signatures,
); err != nil {
return c.JSON(http.StatusBadRequest, model.ErrorResponse{
Status: "error",
Message: err.Error(),
})
}

txSignedAt := transaction.SignedAt

_, err = h.DB.Exec("UPDATE transactions SET signatures='[]'::jsonb WHERE multisig_address=$1 and signed_at > $2", address, txSignedAt)
if err != nil {
return c.JSON(http.StatusBadRequest, model.ErrorResponse{
Status: "error",
Expand Down
2 changes: 2 additions & 0 deletions server/schema/transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type Transaction struct {
Signatures json.RawMessage `pg:"signatures" json:"signatures"`
LastUpdated time.Time `pg:"last_updated,use_zero" json:"last_updated"`
CreatedAt time.Time `pg:"created_at,use_zero" json:"created_at"`
SignedAt time.Time `pg:"signed_at,use_zero" sql:"-" json:"signed_at,omitempty"`
}

type TransactionCount struct {
Expand All @@ -39,4 +40,5 @@ type AllTransactionResult struct {
CreatedAt time.Time `pg:"created_at" sql:"-" json:"created_at,omitempty"`
Threshold int `pg:"threshold" json:"threshold"`
Pubkeys json.RawMessage `pg:"pubkeys" json:"pubkeys"`
SignedAt time.Time `pg:"signed_at" sql:"-" json:"signed_at,omitempty"`
}
13 changes: 13 additions & 0 deletions server/schema/update_schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,16 @@ BEGIN
ADD COLUMN title VARCHAR(255) DEFAULT '';
END IF;
END $$;

DO $$
BEGIN
-- Check and add new_column_name if it doesn't exist
IF NOT EXISTS (
SELECT 1
FROM information_schema.columns
WHERE table_name = 'transactions' AND column_name = 'signed_at'
) THEN
ALTER TABLE transactions
ADD COLUMN signed_at TIMESTAMP DEFAULT NULL;
END IF;
END $$;

0 comments on commit dd81a62

Please sign in to comment.