|
|
@ -10,8 +10,14 @@ object TransactionParsers { |
|
|
|
|
|
|
|
import CommonParsers._ |
|
|
|
|
|
|
|
val parseTransactionId = str("txid").map(TransactionId.from) |
|
|
|
val parseFromTxid = str("from_txid").map(TransactionId.from) |
|
|
|
val parseTransactionId = str("txid") |
|
|
|
.map(TransactionId.from) |
|
|
|
.map { _.getOrElse(throw new RuntimeException("corrupted txid")) } |
|
|
|
|
|
|
|
val parseFromTxid = str("from_txid") |
|
|
|
.map(TransactionId.from) |
|
|
|
.map { _.getOrElse(throw new RuntimeException("corrupted from_txid")) } |
|
|
|
|
|
|
|
val parseFromOutputIndex = get[Int]("from_output_index") |
|
|
|
val parseReceived = get[BigDecimal]("received") |
|
|
|
val parseSpent = get[BigDecimal]("spent") |
|
|
@ -19,16 +25,20 @@ object TransactionParsers { |
|
|
|
|
|
|
|
val parseIndex = get[Int]("index") |
|
|
|
val parseValue = get[BigDecimal]("value") |
|
|
|
val parseHexString = get[String]("hex_script").map(HexString.from) |
|
|
|
val parseHexString = get[String]("hex_script") |
|
|
|
.map(HexString.from) |
|
|
|
.map { _.getOrElse(throw new RuntimeException("corrupted hex_script")) } |
|
|
|
|
|
|
|
val parseTposOwnerAddress = str("tpos_owner_address") |
|
|
|
.map(Address.from) |
|
|
|
.map { _.getOrElse(throw new RuntimeException("corrupted tpos_owner_address")) } |
|
|
|
|
|
|
|
val parseTposOwnerAddress = str("tpos_owner_address").map(Address.from) |
|
|
|
val parseTposMerchantAddress = str("tpos_merchant_address").map(Address.from) |
|
|
|
val parseTposMerchantAddress = str("tpos_merchant_address") |
|
|
|
.map(Address.from) |
|
|
|
.map { _.getOrElse(throw new RuntimeException("corrupted tpos_merchant_address")) } |
|
|
|
|
|
|
|
val parseTransaction = (parseTransactionId ~ parseBlockhash ~ parseTime ~ parseSize).map { |
|
|
|
case txidMaybe ~ blockhash ~ time ~ size => |
|
|
|
for { |
|
|
|
txid <- txidMaybe |
|
|
|
} yield Transaction(txid, blockhash, time, size) |
|
|
|
case txid ~ blockhash ~ time ~ size => Transaction(txid, blockhash, time, size) |
|
|
|
} |
|
|
|
|
|
|
|
val parseTransactionWithValues = ( |
|
|
@ -39,18 +49,13 @@ object TransactionParsers { |
|
|
|
parseSent ~ |
|
|
|
parseReceived).map { |
|
|
|
|
|
|
|
case txidMaybe ~ blockhash ~ time ~ size ~ sent ~ received => |
|
|
|
for { |
|
|
|
txid <- txidMaybe |
|
|
|
} yield TransactionWithValues(txid, blockhash, time, size, sent, received) |
|
|
|
case txid ~ blockhash ~ time ~ size ~ sent ~ received => |
|
|
|
TransactionWithValues(txid, blockhash, time, size, sent, received) |
|
|
|
} |
|
|
|
|
|
|
|
val parseTransactionInput = (parseFromTxid ~ parseFromOutputIndex ~ parseIndex ~ parseValue ~ parseAddress) |
|
|
|
.map { case fromTxidMaybe ~ fromOutputIndex ~ index ~ value ~ addressMaybe => |
|
|
|
for { |
|
|
|
from <- fromTxidMaybe |
|
|
|
address <- addressMaybe |
|
|
|
} yield Transaction.Input(from, fromOutputIndex, index, value, address) |
|
|
|
.map { case fromTxid ~ fromOutputIndex ~ index ~ value ~ address => |
|
|
|
Transaction.Input(fromTxid, fromOutputIndex, index, value, address) |
|
|
|
} |
|
|
|
|
|
|
|
val parseTransactionOutput = ( |
|
|
@ -62,18 +67,14 @@ object TransactionParsers { |
|
|
|
parseTposOwnerAddress.? ~ |
|
|
|
parseTposMerchantAddress.?).map { |
|
|
|
|
|
|
|
case txidMaybe ~ index ~ value ~ addressMaybe ~ scriptMaybe ~ tposOwnerAddress ~ tposMerchantAddress => |
|
|
|
for { |
|
|
|
txid <- txidMaybe |
|
|
|
address <- addressMaybe |
|
|
|
script <- scriptMaybe |
|
|
|
} yield Transaction.Output(txid, index, value, address, script, tposOwnerAddress.flatten, tposMerchantAddress.flatten) |
|
|
|
case txid ~ index ~ value ~ address ~ script ~ tposOwnerAddress ~ tposMerchantAddress => |
|
|
|
Transaction.Output(txid, index, value, address, script, tposOwnerAddress, tposMerchantAddress) |
|
|
|
} |
|
|
|
|
|
|
|
val parseAddressTransactionDetails = (parseAddress ~ parseTransactionId ~ parseSent ~ parseReceived ~ parseTime).map { |
|
|
|
case address ~ txid ~ sent ~ received ~ time => AddressTransactionDetails( |
|
|
|
address.getOrElse(throw new RuntimeException("failed to retrieve address")), |
|
|
|
txid.getOrElse(throw new RuntimeException("failed to retrieve txid")), |
|
|
|
address, |
|
|
|
txid, |
|
|
|
time = time, |
|
|
|
sent = sent, |
|
|
|
received = received) |
|
|
|