-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: migrate wallet nonsecret storage to quill (#1290)
Signed-off-by: Pat Losoponkul <[email protected]>
- Loading branch information
patlo-iog
authored
Aug 19, 2024
1 parent
2f09550
commit 525b3bc
Showing
7 changed files
with
169 additions
and
217 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
180 changes: 34 additions & 146 deletions
180
...c/main/scala/org/hyperledger/identus/agent/walletapi/sql/JdbcWalletNonSecretStorage.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
118 changes: 118 additions & 0 deletions
118
.../wallet-api/src/main/scala/org/hyperledger/identus/agent/walletapi/sql/model/Wallet.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
package org.hyperledger.identus.agent.walletapi.sql.model | ||
|
||
import io.getquill.* | ||
import io.getquill.context.json.PostgresJsonExtensions | ||
import io.getquill.doobie.DoobieContext | ||
import org.hyperledger.identus.agent.walletapi.model | ||
import org.hyperledger.identus.event.notification.EventNotificationConfig | ||
import org.hyperledger.identus.shared.models.WalletId | ||
|
||
import java.net.URL | ||
import java.time.Instant | ||
import java.util.UUID | ||
|
||
final case class Wallet( | ||
walletId: WalletId, | ||
name: String, | ||
createdAt: Instant, | ||
updatedAt: Instant, | ||
seedDigest: Array[Byte] | ||
) | ||
|
||
object Wallet { | ||
def from(wallet: model.Wallet, seedDigest: Array[Byte]): Wallet = { | ||
Wallet( | ||
walletId = wallet.id, | ||
name = wallet.name, | ||
createdAt = wallet.createdAt, | ||
updatedAt = wallet.updatedAt, | ||
seedDigest = seedDigest | ||
) | ||
} | ||
|
||
extension (wallet: Wallet) { | ||
def toModel: model.Wallet = | ||
model.Wallet( | ||
id = wallet.walletId, | ||
name = wallet.name, | ||
createdAt = wallet.createdAt, | ||
updatedAt = wallet.updatedAt | ||
) | ||
} | ||
} | ||
|
||
object WalletSql extends DoobieContext.Postgres(SnakeCase) { | ||
|
||
def insert(wallet: Wallet) = run { | ||
quote( | ||
query[Wallet] | ||
.insertValue(lift(wallet)) | ||
).returning(w => w) | ||
} | ||
|
||
def findByIds(walletIds: Seq[WalletId]) = run { | ||
quote(query[Wallet].filter(p => liftQuery(walletIds.map(_.toUUID)).contains(p.walletId))) | ||
} | ||
|
||
def findBySeed(seedDigest: Array[Byte]) = run { | ||
quote(query[Wallet].filter(_.seedDigest == lift(seedDigest)).take(1)) | ||
} | ||
|
||
def lookupCount() = run { quote(query[Wallet].size) } | ||
|
||
def lookup(offset: Int, limit: Int) = run { | ||
quote(query[Wallet].drop(lift(offset)).take(lift(limit))) | ||
} | ||
} | ||
|
||
final case class WalletNotification( | ||
id: UUID, | ||
walletId: WalletId, | ||
url: URL, | ||
customHeaders: JsonValue[Map[String, String]], | ||
createdAt: Instant, | ||
) | ||
|
||
object WalletNotification { | ||
def from(notification: EventNotificationConfig): WalletNotification = { | ||
WalletNotification( | ||
id = notification.id, | ||
walletId = notification.walletId, | ||
url = notification.url, | ||
customHeaders = JsonValue(notification.customHeaders), | ||
createdAt = notification.createdAt, | ||
) | ||
} | ||
|
||
extension (notification: WalletNotification) { | ||
def toModel: EventNotificationConfig = | ||
EventNotificationConfig( | ||
id = notification.id, | ||
walletId = notification.walletId, | ||
url = notification.url, | ||
customHeaders = notification.customHeaders.value, | ||
createdAt = notification.createdAt, | ||
) | ||
} | ||
} | ||
|
||
object WalletNotificationSql extends DoobieContext.Postgres(SnakeCase), PostgresJsonExtensions { | ||
def insert(notification: WalletNotification) = run { | ||
quote( | ||
query[WalletNotification] | ||
.insertValue(lift(notification)) | ||
) | ||
} | ||
|
||
def lookupCount() = run { | ||
quote(query[WalletNotification].size) | ||
} | ||
|
||
def lookup() = run { | ||
quote(query[WalletNotification]) | ||
} | ||
|
||
def delete(id: UUID) = run { | ||
quote(query[WalletNotification].filter(_.id == lift(id)).delete) | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...wallet-api/src/main/scala/org/hyperledger/identus/agent/walletapi/sql/model/package.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package org.hyperledger.identus.agent.walletapi.sql | ||
|
||
import io.getquill.MappedEncoding | ||
import org.hyperledger.identus.shared.models.WalletId | ||
|
||
import java.net.{URI, URL} | ||
import java.util.UUID | ||
|
||
package object model { | ||
given MappedEncoding[WalletId, UUID] = MappedEncoding[WalletId, UUID](_.toUUID) | ||
given MappedEncoding[UUID, WalletId] = MappedEncoding[UUID, WalletId](WalletId.fromUUID) | ||
|
||
given MappedEncoding[URL, String] = MappedEncoding[URL, String](_.toString) | ||
given MappedEncoding[String, URL] = MappedEncoding[String, URL](URI(_).toURL) | ||
} |
Oops, something went wrong.