You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
46 lines
1.1 KiB
46 lines
1.1 KiB
package com.xsn.explorer.models
|
|
|
|
case class Transaction(
|
|
id: TransactionId,
|
|
blockhash: Blockhash,
|
|
time: Long,
|
|
size: Size,
|
|
inputs: List[Transaction.Input],
|
|
outputs: List[Transaction.Output])
|
|
|
|
object Transaction {
|
|
|
|
case class Input(
|
|
index: Int,
|
|
value: Option[BigDecimal],
|
|
address: Option[Address])
|
|
|
|
case class Output(
|
|
index: Int,
|
|
value: BigDecimal,
|
|
address: Address,
|
|
tposOwnerAddress: Option[Address],
|
|
tposMerchantAddress: Option[Address])
|
|
|
|
def fromRPC(tx: rpc.Transaction): Transaction = {
|
|
val inputs = tx.vin.zipWithIndex.map { case (vin, index) =>
|
|
Transaction.Input(index, vin.value, vin.address)
|
|
}
|
|
|
|
val outputs = tx.vout.flatMap { vout =>
|
|
val tposAddresses = vout.scriptPubKey.flatMap(_.getTPoSAddresses)
|
|
for {
|
|
address <- vout.address
|
|
} yield Transaction.Output(vout.n, vout.value, address, tposAddresses.map(_._1), tposAddresses.map(_._2))
|
|
}
|
|
|
|
Transaction(
|
|
id = tx.id,
|
|
blockhash = tx.blockhash,
|
|
time = tx.time,
|
|
size = tx.size,
|
|
inputs = inputs,
|
|
outputs = outputs
|
|
)
|
|
}
|
|
}
|
|
|