txsizes

package
v3.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 28, 2020 License: ISC Imports: 1 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// RedeemP2PKSigScriptSize is the worst case (largest) serialize size
	// of a transaction input script that redeems a compressed P2PK output.
	// It is calculated as:
	//
	//   - OP_DATA_73
	//   - 72 bytes DER signature + 1 byte sighash
	RedeemP2PKSigScriptSize = 1 + 73

	// RedeemP2PKHSigScriptSize is the worst case (largest) serialize size
	// of a transaction input script that redeems a compressed P2PKH output.
	// It is calculated as:
	//
	//   - OP_DATA_73
	//   - 72 bytes DER signature + 1 byte sighash
	//   - OP_DATA_33
	//   - 33 bytes serialized compressed pubkey
	RedeemP2PKHSigScriptSize = 1 + 73 + 1 + 33

	// RedeemP2SHSigScriptSize is the worst case (largest) serialize size
	// of a transaction input script that redeems a P2SH output.
	// It is calculated as:
	//
	//  - OP_DATA_73
	//  - 73-byte signature
	//  - OP_DATA_35
	//  - OP_DATA_33
	//  - 33 bytes serialized compressed pubkey
	//  - OP_CHECKSIG
	RedeemP2SHSigScriptSize = 1 + 73 + 1 + 1 + 33 + 1

	// RedeemP2PKHInputSize is the worst case (largest) serialize size of a
	// transaction input redeeming a compressed P2PKH output.  It is
	// calculated as:
	//
	//   - 32 bytes previous tx
	//   - 4 bytes output index
	//   - 1 byte tree
	//   - 8 bytes amount
	//   - 4 bytes block height
	//   - 4 bytes block index
	//   - 1 byte compact int encoding value 107
	//   - 107 bytes signature script
	//   - 4 bytes sequence
	RedeemP2PKHInputSize = 32 + 4 + 1 + 8 + 4 + 4 + 1 + RedeemP2PKHSigScriptSize + 4

	// P2PKHPkScriptSize is the size of a transaction output script that
	// pays to a compressed pubkey hash.  It is calculated as:
	//
	//   - OP_DUP
	//   - OP_HASH160
	//   - OP_DATA_20
	//   - 20 bytes pubkey hash
	//   - OP_EQUALVERIFY
	//   - OP_CHECKSIG
	P2PKHPkScriptSize = 1 + 1 + 1 + 20 + 1 + 1

	// P2SHPkScriptSize is the size of a transaction output script that
	// pays to a script hash.  It is calculated as:
	//
	//   - OP_HASH160
	//   - OP_DATA_20
	//   - 20 bytes script hash
	//   - OP_EQUAL
	P2SHPkScriptSize = 1 + 1 + 20 + 1

	// TicketCommitmentScriptSize is the size of a ticket purchase commitment
	// script. It is calculated as:
	//
	//   - OP_RETURN
	//   - OP_DATA_30
	//   - 20 bytes P2SH/P2PKH
	//   - 8 byte amount
	//   - 2 byte fee range limits
	TicketCommitmentScriptSize = 1 + 1 + 20 + 8 + 2

	// P2PKHOutputSize is the serialize size of a transaction output with a
	// P2PKH output script.  It is calculated as:
	//
	//   - 8 bytes output value
	//   - 2 bytes version
	//   - 1 byte compact int encoding value 25
	//   - 25 bytes P2PKH output script
	P2PKHOutputSize = 8 + 2 + 1 + 25
)

Worst case script and input/output size estimates.

Variables

This section is empty.

Functions

func EstimateInputSize

func EstimateInputSize(scriptSize int) int

EstimateInputSize returns the worst case serialize size estimate for a tx input

  • 32 bytes previous tx
  • 4 bytes output index
  • 1 byte tree
  • 8 bytes amount
  • 4 bytes block height
  • 4 bytes block index
  • the compact int representation of the script size
  • the supplied script size
  • 4 bytes sequence

func EstimateOutputSize

func EstimateOutputSize(scriptSize int) int

EstimateOutputSize returns the worst case serialize size estimate for a tx output

  • 8 bytes amount
  • 2 bytes version
  • the compact int representation of the script size
  • the supplied script size

func EstimateSerializeSize

func EstimateSerializeSize(scriptSizes []int, txOuts []*wire.TxOut, changeScriptSize int) int

EstimateSerializeSize returns a worst case serialize size estimate for a signed transaction that spends a number of outputs and contains each transaction output from txOuts. The estimated size is incremented for an additional change output if changeScriptSize is greater than 0. Passing 0 does not add a change output.

func EstimateSerializeSizeFromScriptSizes

func EstimateSerializeSizeFromScriptSizes(inputSizes []int, outputSizes []int, changeScriptSize int) int

EstimateSerializeSizeFromScriptSizes returns a worst case serialize size estimate for a signed transaction that spends len(inputSizes) previous outputs and pays to len(outputSizes) outputs with scripts of the provided worst-case sizes. The estimated size is incremented for an additional change output if changeScriptSize is greater than 0. Passing 0 does not add a change output.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL