-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Beksultan
committed
Oct 30, 2023
1 parent
decdb67
commit 0fb5166
Showing
5 changed files
with
89 additions
and
10 deletions.
There are no files selected for viewing
61 changes: 61 additions & 0 deletions
61
src/main/kotlin/io/openfuture/chain/core/repository/jdbc/UTransactionsJdbcRepository.kt
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,61 @@ | ||
package io.openfuture.chain.core.repository.jdbc | ||
|
||
import io.openfuture.chain.core.model.entity.transaction.payload.TransferTransactionPayload | ||
import io.openfuture.chain.core.model.entity.transaction.unconfirmed.UnconfirmedTransferTransaction | ||
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource | ||
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations | ||
import org.springframework.jdbc.support.GeneratedKeyHolder | ||
import org.springframework.stereotype.Repository | ||
|
||
|
||
interface UTransactionsJdbcRepository { | ||
fun save(utransaction: UnconfirmedTransferTransaction): UnconfirmedTransferTransaction | ||
} | ||
|
||
@Repository | ||
class UTransactionsJdbcRepositoryImpl( | ||
private val namedParameterJdbcOperations: NamedParameterJdbcOperations | ||
) : UTransactionsJdbcRepository { | ||
|
||
override fun save(utransaction: UnconfirmedTransferTransaction): UnconfirmedTransferTransaction { | ||
val generatedKeyHolder = GeneratedKeyHolder() | ||
val sqlParameterSource = MapSqlParameterSource() | ||
|
||
sqlParameterSource.addValue("timestamp", utransaction.timestamp) | ||
sqlParameterSource.addValue("fee", utransaction.fee) | ||
sqlParameterSource.addValue("senderAddress", utransaction.senderAddress) | ||
sqlParameterSource.addValue("hash", utransaction.hash) | ||
sqlParameterSource.addValue("signature", utransaction.signature) | ||
sqlParameterSource.addValue("publicKey", utransaction.publicKey) | ||
|
||
namedParameterJdbcOperations.update( | ||
"INSERT INTO U_TRANSACTIONS(TIMESTAMP, FEE, SENDER_ADDRESS, HASH, SIGNATURE, SENDER_KEY) " + | ||
"VALUES (:timestamp, :fee, :senderAddress, :hash, :signature, :publicKey)", | ||
sqlParameterSource, generatedKeyHolder | ||
) | ||
|
||
val id = generatedKeyHolder.key.toLong() | ||
|
||
saveUTransferTransaction(utransaction.getPayload(), id) | ||
|
||
utransaction.id = id | ||
return utransaction | ||
} | ||
|
||
private fun saveUTransferTransaction(t: TransferTransactionPayload, id: Long) { | ||
val sqlParameterSource = MapSqlParameterSource() | ||
|
||
sqlParameterSource.addValue("id", id) | ||
sqlParameterSource.addValue("amount", t.amount) | ||
sqlParameterSource.addValue("address", t.recipientAddress) | ||
sqlParameterSource.addValue("data", t.data) | ||
|
||
namedParameterJdbcOperations.update( | ||
"insert into U_TRANSACTIONS(ID, AMOUNT, RECIPIENT_ADDRESS, DATA) values (:id, amount, address, data)", | ||
sqlParameterSource | ||
) | ||
|
||
} | ||
|
||
|
||
} |
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
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
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
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