feat: added tables
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
package org.ccoin.database
|
||||
|
||||
import org.jetbrains.exposed.sql.Table
|
||||
import org.jetbrains.exposed.sql.javatime.timestamp
|
||||
import java.math.BigDecimal
|
||||
|
||||
object Tables {
|
||||
object Wallets : Table("wallets") {
|
||||
val address = varchar("address", 64) // Format random_word:random_6_digits
|
||||
val balance = decimal("balance", 20, 8).default(BigDecimal.ZERO)
|
||||
val label = varchar("label", 255).nullable()
|
||||
val createdAt = long("created_at")
|
||||
val lastActivity = long("last_activity").nullable()
|
||||
|
||||
override val primaryKey = PrimaryKey(address)
|
||||
|
||||
init {
|
||||
index(false, createdAt)
|
||||
index(false, lastActivity)
|
||||
}
|
||||
}
|
||||
|
||||
object Transactions : Table("transactions") {
|
||||
val hash = varchar("hash", 64)
|
||||
val fromAddress = varchar("from_address", 64).nullable()
|
||||
val toAddress = varchar("to_address", 64)
|
||||
val amount = decimal("amount", 20, 8)
|
||||
val fee = decimal("fee", 20, 8).default(BigDecimal.ZERO)
|
||||
val memo = text("memo").nullable()
|
||||
val blockHash = varchar("block_hash", 64).nullable()
|
||||
val timestamp = long("timestamp")
|
||||
val status = varchar("status", 20).default("pending")
|
||||
val confirmations = integer("confirmations").default(0)
|
||||
|
||||
override val primaryKey = PrimaryKey(hash)
|
||||
|
||||
init {
|
||||
index(false, fromAddress)
|
||||
index(false, toAddress)
|
||||
index(false, blockHash)
|
||||
index(false, timestamp)
|
||||
index(false, status)
|
||||
}
|
||||
}
|
||||
|
||||
object Blocks : Table("blocks") {
|
||||
val hash = varchar("hash", 64)
|
||||
val previousHash = varchar("previous_hash", 64).nullable()
|
||||
val merkleRoot = varchar("merkle_root", 64)
|
||||
val timestamp = long("timestamp")
|
||||
val difficulty = integer("difficulty")
|
||||
val nonce = long("nonce")
|
||||
val minerAddress = varchar("miner_address", 64)
|
||||
val reward = decimal("reward", 20, 8)
|
||||
val height = integer("height").autoIncrement()
|
||||
val transactionCount = integer("transaction_count").default(0)
|
||||
val confirmations = integer("confirmations").default(0)
|
||||
|
||||
override val primaryKey = PrimaryKey(hash)
|
||||
|
||||
init {
|
||||
index(false, height)
|
||||
index(false, minerAddress)
|
||||
index(false, timestamp)
|
||||
index(false, previousHash)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user