Browse Source

server: Remove the TPoS addresses from the Transaction.Output

The addresses are useless and the whole contract will be stored instead.
master
Alexis Hernandez 6 years ago
parent
commit
9d2edf8314
  1. 16
      server/app/com/xsn/explorer/data/anorm/dao/TransactionOutputPostgresDAO.scala
  2. 11
      server/app/com/xsn/explorer/data/anorm/parsers/TransactionParsers.scala
  3. 9
      server/app/com/xsn/explorer/models/persisted/Transaction.scala
  4. 14
      server/test/com/xsn/explorer/data/TransactionPostgresDataHandlerSpec.scala
  5. 3
      server/test/com/xsn/explorer/helpers/DataGenerator.scala
  6. 8
      server/test/controllers/AddressesControllerSpec.scala

16
server/app/com/xsn/explorer/data/anorm/dao/TransactionOutputPostgresDAO.scala

@ -15,7 +15,7 @@ class TransactionOutputPostgresDAO {
def getUnspentOutputs(address: Address)(implicit conn: Connection): List[Transaction.Output] = { def getUnspentOutputs(address: Address)(implicit conn: Connection): List[Transaction.Output] = {
SQL( SQL(
""" """
|SELECT txid, index, value, address, hex_script, tpos_owner_address, tpos_merchant_address |SELECT txid, index, value, address, hex_script
|FROM transaction_outputs |FROM transaction_outputs
|WHERE address = {address} AND |WHERE address = {address} AND
| spent_on IS NULL AND | spent_on IS NULL AND
@ -39,17 +39,15 @@ class TransactionOutputPostgresDAO {
'index -> output.index: NamedParameter, 'index -> output.index: NamedParameter,
'value -> output.value: NamedParameter, 'value -> output.value: NamedParameter,
'address -> output.address.string: NamedParameter, 'address -> output.address.string: NamedParameter,
'hex_script -> output.script.string: NamedParameter, 'hex_script -> output.script.string: NamedParameter)
'tpos_owner_address -> output.tposOwnerAddress.map(_.string): NamedParameter,
'tpos_merchant_address -> output.tposMerchantAddress.map(_.string): NamedParameter)
} }
val batch = BatchSql( val batch = BatchSql(
""" """
|INSERT INTO transaction_outputs |INSERT INTO transaction_outputs
| (txid, index, value, address, hex_script, tpos_owner_address, tpos_merchant_address) | (txid, index, value, address, hex_script)
|VALUES |VALUES
| ({txid}, {index}, {value}, {address}, {hex_script}, {tpos_owner_address}, {tpos_merchant_address}) | ({txid}, {index}, {value}, {address}, {hex_script})
""".stripMargin, """.stripMargin,
params.head, params.head,
params.tail: _* params.tail: _*
@ -69,7 +67,7 @@ class TransactionOutputPostgresDAO {
""" """
|DELETE FROM transaction_outputs |DELETE FROM transaction_outputs
|WHERE txid = {txid} |WHERE txid = {txid}
|RETURNING txid, index, hex_script, value, address, tpos_owner_address, tpos_merchant_address |RETURNING txid, index, hex_script, value, address
""".stripMargin """.stripMargin
).on( ).on(
'txid -> txid.string 'txid -> txid.string
@ -81,7 +79,7 @@ class TransactionOutputPostgresDAO {
def getOutputs(txid: TransactionId)(implicit conn: Connection): List[Transaction.Output] = { def getOutputs(txid: TransactionId)(implicit conn: Connection): List[Transaction.Output] = {
SQL( SQL(
""" """
|SELECT txid, index, hex_script, value, address, tpos_owner_address, tpos_merchant_address |SELECT txid, index, hex_script, value, address
|FROM transaction_outputs |FROM transaction_outputs
|WHERE txid = {txid} |WHERE txid = {txid}
""".stripMargin """.stripMargin
@ -93,7 +91,7 @@ class TransactionOutputPostgresDAO {
def getOutputs(txid: TransactionId, address: Address)(implicit conn: Connection): List[Transaction.Output] = { def getOutputs(txid: TransactionId, address: Address)(implicit conn: Connection): List[Transaction.Output] = {
SQL( SQL(
""" """
|SELECT txid, index, hex_script, value, address, tpos_owner_address, tpos_merchant_address |SELECT txid, index, hex_script, value, address
|FROM transaction_outputs |FROM transaction_outputs
|WHERE txid = {txid} AND |WHERE txid = {txid} AND
| address = {address} | address = {address}

11
server/app/com/xsn/explorer/data/anorm/parsers/TransactionParsers.scala

@ -17,9 +17,6 @@ object TransactionParsers {
val parseValue = get[BigDecimal]("value") val parseValue = get[BigDecimal]("value")
val parseHexScript = parseHexString("hex_script") val parseHexScript = parseHexString("hex_script")
val parseTposOwnerAddress = parseAddress("tpos_owner_address")
val parseTposMerchantAddress = parseAddress("tpos_merchant_address")
val parseTransaction = (parseTransactionId() ~ parseBlockhash() ~ parseTime ~ parseSize).map { val parseTransaction = (parseTransactionId() ~ parseBlockhash() ~ parseTime ~ parseSize).map {
case txid ~ blockhash ~ time ~ size => Transaction(txid, blockhash, time, size) case txid ~ blockhash ~ time ~ size => Transaction(txid, blockhash, time, size)
} }
@ -46,12 +43,10 @@ object TransactionParsers {
parseIndex ~ parseIndex ~
parseValue ~ parseValue ~
parseAddress() ~ parseAddress() ~
parseHexScript ~ parseHexScript).map {
parseTposOwnerAddress.? ~
parseTposMerchantAddress.?).map {
case txid ~ index ~ value ~ address ~ script ~ tposOwnerAddress ~ tposMerchantAddress => case txid ~ index ~ value ~ address ~ script =>
Transaction.Output(txid, index, value, address, script, tposOwnerAddress, tposMerchantAddress) Transaction.Output(txid, index, value, address, script)
} }
val parseAddressTransactionDetails = (parseAddress() ~ parseTransactionId() ~ parseSent ~ parseReceived ~ parseTime).map { val parseAddressTransactionDetails = (parseAddress() ~ parseTransactionId() ~ parseSent ~ parseReceived ~ parseTime).map {

9
server/app/com/xsn/explorer/models/persisted/Transaction.scala

@ -27,9 +27,7 @@ object Transaction {
index: Int, index: Int,
value: BigDecimal, value: BigDecimal,
address: Address, address: Address,
script: HexString, script: HexString)
tposOwnerAddress: Option[Address],
tposMerchantAddress: Option[Address])
case class HasIO( case class HasIO(
transaction: Transaction, transaction: Transaction,
@ -63,7 +61,6 @@ object Transaction {
} }
val outputs = tx.vout.flatMap { vout => val outputs = tx.vout.flatMap { vout =>
val contract = vout.scriptPubKey.flatMap(_.getTPoSContractDetails)
val scriptMaybe = vout.scriptPubKey.map(_.hex) val scriptMaybe = vout.scriptPubKey.map(_.hex)
for { for {
address <- vout.address address <- vout.address
@ -73,9 +70,7 @@ object Transaction {
vout.n, vout.n,
vout.value, vout.value,
address, address,
script, script)
tposOwnerAddress = contract.map(_.owner),
tposMerchantAddress = contract.map(_.merchant))
} }
val transaction = Transaction( val transaction = Transaction(

14
server/test/com/xsn/explorer/data/TransactionPostgresDataHandlerSpec.scala

@ -80,9 +80,7 @@ class TransactionPostgresDataHandlerSpec extends PostgresDataHandlerSpec with Be
txid = createTransactionId("67aa0bd8b9297ca6ee25a1e5c2e3a8dbbcc1e20eab76b6d1bdf9d69f8a5356b8"), txid = createTransactionId("67aa0bd8b9297ca6ee25a1e5c2e3a8dbbcc1e20eab76b6d1bdf9d69f8a5356b8"),
index = 0, index = 0,
value = BigDecimal(76500000), value = BigDecimal(76500000),
script = HexString.from("2103e8c52f2c5155771492907095753a43ce776e1fa7c5e769a67a9f3db4467ec029ac").get, script = HexString.from("2103e8c52f2c5155771492907095753a43ce776e1fa7c5e769a67a9f3db4467ec029ac").get
tposMerchantAddress = None,
tposOwnerAddress = None
) )
val result = dataHandler.getUnspentOutputs(expected.address).get val result = dataHandler.getUnspentOutputs(expected.address).get
@ -201,14 +199,13 @@ class TransactionPostgresDataHandlerSpec extends PostgresDataHandlerSpec with Be
) )
val outputs = List( val outputs = List(
Transaction.Output(randomTransactionId, 0, BigDecimal(50), randomAddress, randomHexString(), None, None), Transaction.Output(randomTransactionId, 0, BigDecimal(50), randomAddress, randomHexString()),
Transaction.Output( Transaction.Output(
randomTransactionId, randomTransactionId,
1, 1,
BigDecimal(250), BigDecimal(250),
randomAddress, randomAddress,
HexString.from("00").get, HexString.from("00").get)
None, None)
) )
val transactions = List.fill(4)(randomTransactionId).zip(List(321L, 320L, 319L, 319L)).map { case (txid, time) => val transactions = List.fill(4)(randomTransactionId).zip(List(321L, 320L, 319L, 319L)).map { case (txid, time) =>
@ -299,14 +296,13 @@ class TransactionPostgresDataHandlerSpec extends PostgresDataHandlerSpec with Be
val newTxid = randomTransactionId val newTxid = randomTransactionId
val outputs = List( val outputs = List(
Transaction.Output(newTxid, 0, BigDecimal(50), randomAddress, randomHexString(), None, None), Transaction.Output(newTxid, 0, BigDecimal(50), randomAddress, randomHexString()),
Transaction.Output( Transaction.Output(
newTxid, newTxid,
1, 1,
BigDecimal(250), BigDecimal(250),
randomAddress, randomAddress,
randomHexString(), randomHexString())
None, None)
) )
val transaction = Transaction.HasIO( val transaction = Transaction.HasIO(

3
server/test/com/xsn/explorer/helpers/DataGenerator.scala

@ -70,8 +70,7 @@ trait DataGenerator {
index = nextInt(100), index = nextInt(100),
value = nextInt(1000000), value = nextInt(1000000),
address = randomAddress, address = randomAddress,
script = randomHexString(8), script = randomHexString(8))
None, None)
} }
def randomOutputs(n: Int = nextInt(5) + 1) : List[Transaction.Output] = { def randomOutputs(n: Int = nextInt(5) + 1) : List[Transaction.Output] = {

8
server/test/controllers/AddressesControllerSpec.scala

@ -31,18 +31,14 @@ class AddressesControllerSpec extends MyAPISpec {
index = 0, index = 0,
value = BigDecimal("1500000000000").fromSatoshis, value = BigDecimal("1500000000000").fromSatoshis,
script = HexString.from("76a914285b6f1ccacea0059ff5393cb4eb2f0569e2b3e988ac").get, script = HexString.from("76a914285b6f1ccacea0059ff5393cb4eb2f0569e2b3e988ac").get,
txid = createTransactionId("ea837f2011974b6a1a2fa077dc33684932c514a4ec6febc10e1a19ebe1336539"), txid = createTransactionId("ea837f2011974b6a1a2fa077dc33684932c514a4ec6febc10e1a19ebe1336539")
tposMerchantAddress = None,
tposOwnerAddress = None
), ),
Transaction.Output( Transaction.Output(
address = createAddress("XeNEPsgeWqNbrEGEN5vqv4wYcC3qQrqNyp"), address = createAddress("XeNEPsgeWqNbrEGEN5vqv4wYcC3qQrqNyp"),
index = 3, index = 3,
value = BigDecimal("2250000000").fromSatoshis, value = BigDecimal("2250000000").fromSatoshis,
script = HexString.from("76a914285b6f1ccacea0059ff5393cb4eb2f0569e2b3e988ac").get, script = HexString.from("76a914285b6f1ccacea0059ff5393cb4eb2f0569e2b3e988ac").get,
txid = createTransactionId("96a06b802d1c15818a42aa9b46dd2e236cde746000d35f74d3eb940ab9d5694d"), txid = createTransactionId("96a06b802d1c15818a42aa9b46dd2e236cde746000d35f74d3eb940ab9d5694d")
tposMerchantAddress = None,
tposOwnerAddress = None
) )
) )

Loading…
Cancel
Save