mirror of
https://github.com/bitcoin-s/bitcoin-s.git
synced 2025-03-03 18:47:38 +01:00
Make tx bytes functions lazy vals (#2180)
This commit is contained in:
parent
9787e89403
commit
c104bf11fb
4 changed files with 6 additions and 6 deletions
|
@ -138,7 +138,7 @@ object Transaction extends Factory[Transaction] {
|
||||||
sealed abstract class NonWitnessTransaction extends Transaction {
|
sealed abstract class NonWitnessTransaction extends Transaction {
|
||||||
override def weight: Long = byteSize * 4
|
override def weight: Long = byteSize * 4
|
||||||
|
|
||||||
override def bytes: ByteVector = {
|
override lazy val bytes: ByteVector = {
|
||||||
val versionBytes = version.bytes.reverse
|
val versionBytes = version.bytes.reverse
|
||||||
val inputBytes = BytesUtil.writeCmpctSizeUInt(inputs)
|
val inputBytes = BytesUtil.writeCmpctSizeUInt(inputs)
|
||||||
val outputBytes = BytesUtil.writeCmpctSizeUInt(outputs)
|
val outputBytes = BytesUtil.writeCmpctSizeUInt(outputs)
|
||||||
|
@ -235,7 +235,7 @@ case class WitnessTransaction(
|
||||||
* Functionality inside of Bitcoin Core:
|
* Functionality inside of Bitcoin Core:
|
||||||
* [[https://github.com/bitcoin/bitcoin/blob/e8cfe1ee2d01c493b758a67ad14707dca15792ea/src/primitives/transaction.h#L282-L287s]]
|
* [[https://github.com/bitcoin/bitcoin/blob/e8cfe1ee2d01c493b758a67ad14707dca15792ea/src/primitives/transaction.h#L282-L287s]]
|
||||||
*/
|
*/
|
||||||
override def bytes: ByteVector = {
|
override lazy val bytes: ByteVector = {
|
||||||
val versionBytes = version.bytes.reverse
|
val versionBytes = version.bytes.reverse
|
||||||
val inputBytes = BytesUtil.writeCmpctSizeUInt(inputs)
|
val inputBytes = BytesUtil.writeCmpctSizeUInt(inputs)
|
||||||
val outputBytes = BytesUtil.writeCmpctSizeUInt(outputs)
|
val outputBytes = BytesUtil.writeCmpctSizeUInt(outputs)
|
||||||
|
|
|
@ -16,7 +16,7 @@ sealed abstract class TransactionInput extends NetworkElement {
|
||||||
|
|
||||||
def scriptSignature: ScriptSignature
|
def scriptSignature: ScriptSignature
|
||||||
def sequence: UInt32
|
def sequence: UInt32
|
||||||
override def bytes = RawTransactionInputParser.write(this)
|
override lazy val bytes: ByteVector = RawTransactionInputParser.write(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
case object EmptyTransactionInput extends TransactionInput {
|
case object EmptyTransactionInput extends TransactionInput {
|
||||||
|
|
|
@ -10,9 +10,9 @@ case class TransactionOutput(value: CurrencyUnit, scriptPubKey: ScriptPubKey)
|
||||||
extends NetworkElement {
|
extends NetworkElement {
|
||||||
|
|
||||||
//https://bitcoin.org/en/developer-reference#txout
|
//https://bitcoin.org/en/developer-reference#txout
|
||||||
override lazy val byteSize = scriptPubKey.byteSize + 8
|
override lazy val byteSize: Long = scriptPubKey.byteSize + 8
|
||||||
|
|
||||||
override def bytes = RawTransactionOutputParser.write(this)
|
override lazy val bytes: ByteVector = RawTransactionOutputParser.write(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
final object EmptyTransactionOutput
|
final object EmptyTransactionOutput
|
||||||
|
|
|
@ -17,7 +17,7 @@ sealed abstract class TransactionWitness
|
||||||
val witnesses: Vector[ScriptWitness]
|
val witnesses: Vector[ScriptWitness]
|
||||||
override protected val wrapped: Vector[ScriptWitness] = witnesses
|
override protected val wrapped: Vector[ScriptWitness] = witnesses
|
||||||
|
|
||||||
override def bytes: ByteVector = {
|
override lazy val bytes: ByteVector = {
|
||||||
RawTransactionWitnessParser.write(this)
|
RawTransactionWitnessParser.write(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue