Skip to content

Commit

Permalink
no merge because unused anyway
Browse files Browse the repository at this point in the history
  • Loading branch information
benny-conn committed Oct 5, 2023
1 parent ad582d6 commit 2158fa8
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 24 deletions.
4 changes: 2 additions & 2 deletions docker/postgres/DOCKERFILE
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM postgres:14
FROM postgres:15

RUN apt-get update
RUN apt-get -y install postgresql-14-cron
RUN apt-get -y install postgresql-15-cron

ENV POSTGRES_HOST_AUTH_METHOD trust
ENV POSTGRES_USER postgres
Expand Down
22 changes: 0 additions & 22 deletions service/persist/postgres/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ type WalletRepository struct {
db *sql.DB
queries *db.Queries

insertStmt *sql.Stmt
getByIDStmt *sql.Stmt
getByChainAddressStmt *sql.Stmt
getByUserIDStmt *sql.Stmt
Expand All @@ -26,9 +25,6 @@ func NewWalletRepository(db *sql.DB, queries *db.Queries) *WalletRepository {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
defer cancel()

insertStmt, err := db.PrepareContext(ctx, `MERGE INTO wallets (USING (VALUES ($1,$2,$3,$4,$5,$6,false)) as new (ID,VERSION,ADDRESS,CHAIN,L1_CHAIN,WALLET_TYPE,DELETED) ON (new.ADDRESS = wallets.ADDRESS AND new.CHAIN = wallets.CHAIN and wallets.DELETED = false) or (new.ADDRESS = wallets.ADDRESS and new.L1_CHAIN = wallets.L1_CHAIN and wallets.DELETED = false) WHEN NOT MATCHED THEN INSERT VALUES (ID,VERSION,ADDRESS,CHAIN,L1_CHAIN,WALLET_TYPE,DELETED)`)
checkNoErr(err)

getByIDStmt, err := db.PrepareContext(ctx, `SELECT ID,VERSION,CREATED_AT,LAST_UPDATED,ADDRESS,WALLET_TYPE,CHAIN,L1_CHAIN FROM wallets WHERE ID = $1 AND DELETED = FALSE;`)
checkNoErr(err)

Expand All @@ -44,7 +40,6 @@ func NewWalletRepository(db *sql.DB, queries *db.Queries) *WalletRepository {
getByIDStmt: getByIDStmt,
getByChainAddressStmt: getByChainAddressStmt,
getByUserIDStmt: getByUserIDStmt,
insertStmt: insertStmt,
}
}

Expand Down Expand Up @@ -102,20 +97,3 @@ func (w *WalletRepository) GetByUserID(ctx context.Context, userID persist.DBID)

return wallets, nil
}

// Insert inserts a wallet by its address and chain
func (w *WalletRepository) Insert(ctx context.Context, chainAddress persist.ChainAddress, walletType persist.WalletType) (persist.DBID, error) {

_, err := w.insertStmt.ExecContext(ctx, persist.GenerateID(), 0, chainAddress.Address(), chainAddress.Chain(), chainAddress.Chain().L1Chain(), walletType)
if err != nil {
return "", err
}

// rather than using the ID generated above, we must retrieve it because in the case of conflict the ID above would be inaccurate.
wa, err := w.GetByChainAddress(ctx, chainAddress)
if err != nil {
return "", err
}

return wa.ID, nil
}

0 comments on commit 2158fa8

Please sign in to comment.