Skip to content

Commit

Permalink
Sprint
Browse files Browse the repository at this point in the history
  • Loading branch information
Beksultan committed Aug 8, 2024
1 parent 0fb5166 commit 38f9dda
Show file tree
Hide file tree
Showing 45 changed files with 463 additions and 197 deletions.
4 changes: 3 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ dependencies {
// Kotlin
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
implementation("org.jetbrains.kotlin:kotlin-reflect")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.2")

implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
implementation('com.fasterxml.jackson.datatype:jackson-datatype-jsr310')

Expand All @@ -39,7 +41,7 @@ dependencies {
// DB
implementation('org.flywaydb:flyway-core')
implementation('com.h2database:h2:2.1.210')

implementation 'org.postgresql:postgresql:42.3.8'

// Utils
implementation('commons-net:commons-net:3.6')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional

@Service
@Transactional(readOnly = true)
@Transactional
class DefaultEpochService(
private val blockManager: BlockManager,
private val properties: ConsensusProperties
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,23 @@ abstract class Block(

return ByteUtils.toHexString(HashUtils.doubleSha256(bytes))
}

fun generateHashForTransaction(timestamp: Long,
fee: Long, amount: Long,
senderAddress: String,
recipientAddress: String): String {
val bytes = ByteBuffer.allocate(SIZE_BYTES + SIZE_BYTES + SIZE_BYTES +
senderAddress.toByteArray().size + recipientAddress.toByteArray().size)
.putLong(timestamp)
.putLong(fee)
.put(senderAddress.toByteArray())
.putLong(amount)
.put(recipientAddress.toByteArray())
.array()

return ByteUtils.toHexString(HashUtils.doubleSha256(bytes))
}

}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional

@Service
@Transactional(readOnly = true)
@Transactional
class DefaultBlockManager(
private val repository: BlockRepository<Block>,
private val genesisBlockService: GenesisBlockService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import org.springframework.beans.factory.annotation.Autowired
import org.springframework.data.domain.Page
import org.springframework.transaction.annotation.Transactional

@Transactional(readOnly = true)
@Transactional
abstract class DefaultBlockService<T : Block>(
private val repository: BlockRepository<T>
) : BlockService<T> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional

@Service
@Transactional(readOnly = true)
@Transactional
class DefaultGenesisBlockService(
private val repository: GenesisBlockRepository,
private val stateManager: StateManager,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import org.springframework.transaction.annotation.Transactional
import kotlin.math.max

@Service
@Transactional(readOnly = true)
@Transactional
class DefaultMainBlockService(
private val repository: MainBlockRepository,
private val stateManager: StateManager,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import org.slf4j.Logger
import org.slf4j.LoggerFactory
import org.springframework.transaction.annotation.Transactional

@Transactional(readOnly = true)
@Transactional
abstract class BlockValidator {

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional

@Service
@Transactional(readOnly = true)
@Transactional
class MainBlockValidator(
private val consensusProperties: ConsensusProperties,
private val stateManager: StateManager,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional

@Service
@Transactional(readOnly = true)
@Transactional
class DefaultReceiptService(
private val repository: ReceiptRepository
) : ReceiptService {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional

@Service
@Transactional(readOnly = true)
@Transactional
class DefaultAccountStateService(
private val repository: AccountStateRepository,
private val statePool: StatePool
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional

@Service
@Transactional(readOnly = true)
@Transactional
class DefaultDelegateStateService(
private val repository: DelegateStateRepository,
private val consensusProperties: ConsensusProperties,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional

@Service
@Transactional(readOnly = true)
@Transactional
class DefaultStateManager(
private val repository: StateRepository<State>,
private val accountStateService: AccountStateService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import io.openfuture.chain.core.repository.StateRepository
import io.openfuture.chain.core.service.StateService
import org.springframework.transaction.annotation.Transactional

@Transactional(readOnly = true)
@Transactional
abstract class DefaultStateService<T : State>(
private val repository: StateRepository<T>
) : StateService<T> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional

@Service
@Transactional(readOnly = true)
@Transactional
class DefaultTransactionManager(
private val repository: TransactionRepository<Transaction>,
private val uRepository: UTransactionRepository<UnconfirmedTransaction>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional

@Service
@Transactional(readOnly = true)
@Transactional
class DefaultDelegateTransactionService(
private val repository: DelegateTransactionRepository,
private val consensusProperties: ConsensusProperties
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import io.openfuture.chain.core.service.ExternalTransactionService
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.transaction.annotation.Transactional

@Transactional(readOnly = true)
@Transactional
abstract class DefaultExternalTransactionService<T : Transaction>(
private val repository: TransactionRepository<T>
) : DefaultTransactionService<T>(repository), ExternalTransactionService<T> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional

@Service
@Transactional(readOnly = true)
@Transactional
class DefaultRewardTransactionService(
private val repository: RewardTransactionRepository,
private val consensusProperties: ConsensusProperties,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import org.springframework.beans.factory.annotation.Autowired
import org.springframework.data.domain.Page
import org.springframework.transaction.annotation.Transactional

@Transactional(readOnly = true)
@Transactional
abstract class DefaultTransactionService<T : Transaction>(
private val repository: TransactionRepository<T>
) : TransactionService<T> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional

@Service
@Transactional(readOnly = true)
@Transactional
class DefaultTransferTransactionService(
private val repository: TransferTransactionRepository,
private val contractService: ContractService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional

@Service
@Transactional(readOnly = true)
@Transactional
class DefaultVoteTransactionService(
private val repository: VoteTransactionRepository,
private val consensusProperties: ConsensusProperties
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional

@Service
@Transactional(readOnly = true)
@Transactional
class DefaultUDelegateTransactionService(
uRepository: UDelegateTransactionRepository,
jdbcRepository: UTransactionsJdbcRepository
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import io.openfuture.chain.rpc.domain.base.PageRequest
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.transaction.annotation.Transactional

@Transactional(readOnly = true)
@Transactional
abstract class DefaultUTransactionService<uT : UnconfirmedTransaction>(
private val uRepository: UTransactionRepository<uT>,
private val jdbcRepository: UTransactionsJdbcRepository
Expand Down Expand Up @@ -66,6 +66,7 @@ abstract class DefaultUTransactionService<uT : UnconfirmedTransaction>(

@BlockchainSynchronized
@Transactional
@Synchronized
override fun add(uTx: uT, unconfirmedBalance: Long): uT {
BlockchainLock.writeLock.lock()
try {
Expand Down Expand Up @@ -95,18 +96,27 @@ abstract class DefaultUTransactionService<uT : UnconfirmedTransaction>(
else -> throw IllegalStateException("Wrong type")
}

val findOneByHash = uRepository.findOneByHash(uTx.hash)
if (null != findOneByHash) {
print("Tried to save duplicate")
}

val savedUtx = uRepository.saveAndFlush(uTx)
networkService.broadcast(savedUtx.toMessage())
return savedUtx

//

return if (uTx is UnconfirmedTransferTransaction) {
val savedUtx = jdbcRepository.save(uTx)
networkService.broadcast(savedUtx.toMessage())
uTx.id = savedUtx.id
return uTx
} else {
val savedUtx = uRepository.saveAndFlush(uTx)
networkService.broadcast(savedUtx.toMessage())
savedUtx
}
// return if (uTx is UnconfirmedTransferTransaction) {
// val savedUtx = jdbcRepository.save(uTx)
// networkService.broadcast(savedUtx.toMessage())
// uTx.id = savedUtx.id
// return uTx
// } else {
// val savedUtx = uRepository.saveAndFlush(uTx)
// networkService.broadcast(savedUtx.toMessage())
// savedUtx
// }

} finally {
BlockchainLock.writeLock.unlock()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional

@Service
@Transactional(readOnly = true)
@Transactional
class DefaultUTransferTransactionService(
uRepository: UTransferTransactionRepository,
jdbcRepository: UTransactionsJdbcRepository
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional

@Service
@Transactional(readOnly = true)
@Transactional
class DefaultUVoteTransactionService(
private val uRepository: UVoteTransactionRepository,
jdbcRepository: UTransactionsJdbcRepository
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional

@Service
@Transactional(readOnly = true)
@Transactional
class DelegateTransactionValidator(
private val consensusProperties: ConsensusProperties,
private val uRepository: UDelegateTransactionRepository
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional

@Service
@Transactional(readOnly = true)
@Transactional
class RewardTransactionValidator : TransactionValidator() {

fun check(): Array<TransactionValidateHandler> = arrayOf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import org.slf4j.LoggerFactory
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.transaction.annotation.Transactional

@Transactional(readOnly = true)
@Transactional
abstract class TransactionValidator {

@Autowired private lateinit var cryptoService: CryptoService
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional

@Service
@Transactional(readOnly = true)
@Transactional
class TransferTransactionValidator(
private val contractService: ContractService
) : TransactionValidator() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional

@Service
@Transactional(readOnly = true)
@Transactional
class VoteTransactionValidator(
private val consensusProperties: ConsensusProperties,
private val uRepository: UVoteTransactionRepository
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ class ChannelsHolder(
.minus(regularAddresses)
val addresses = regularAddresses.plus(bootAddresses).shuffled()
for (address in addresses) {
log.info("$addresses")
val connected = connectionService.connect(address, Consumer {
greet(it)
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import io.openfuture.chain.core.exception.ValidationException
import io.openfuture.chain.rpc.domain.ExceptionResponse
import io.openfuture.chain.rpc.domain.ValidationErrorResponse
import org.apache.commons.lang3.StringUtils.EMPTY
import org.h2.jdbc.JdbcSQLIntegrityConstraintViolationException
import org.springframework.http.HttpStatus.BAD_REQUEST
import org.springframework.http.HttpStatus.NOT_FOUND
import org.springframework.web.bind.MethodArgumentNotValidException
Expand Down Expand Up @@ -66,8 +65,8 @@ class ExceptionRestControllerAdvice {
}

@ResponseStatus(BAD_REQUEST)
@ExceptionHandler(JdbcSQLIntegrityConstraintViolationException::class)
fun handleJdbcSQLIntegrityConstraintViolationException(ex: JdbcSQLIntegrityConstraintViolationException): ExceptionResponse {
@ExceptionHandler(org.hibernate.exception.ConstraintViolationException::class)
fun handleJdbcSQLIntegrityConstraintViolationException(ex: org.hibernate.exception.ConstraintViolationException): ExceptionResponse {
return ExceptionResponse(BAD_REQUEST.value(), ex.message)
}

Expand Down
Loading

0 comments on commit 38f9dda

Please sign in to comment.