btctx

package
v0.0.0-...-5ed304f Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// opcodes
	OP_0           = 0x00
	OP_DATA_1      = 0x01
	OP_DATA_20     = 0x14
	OP_DATA_21     = 0x15
	OP_DATA_32     = 0x20
	OP_DATA_33     = 0x21
	OP_PUSHDATA1   = 0x4c
	OP_PUSHDATA2   = 0x4d
	OP_PUSHDATA4   = 0x4e
	OP_1           = 0x51
	OP_DUP         = 0x76
	OP_EQUAL       = 0x87
	OP_EQUALVERIFY = 0x88
	OP_HASH160     = 0xa9
	OP_CHECKSIG    = 0xac

	// tx flags
	TxFlagMarker         = 0x00
	WitnessFlag          = 0x01
	SIGHASH_ALL          = 0x1
	SIGHASH_NONE         = 0x2
	SIGHASH_SINGLE       = 0x3
	SIGHASH_ANYONECANPAY = 0x80
)

Variables

This section is empty.

Functions

func AddressToScript

func AddressToScript(addr string, p2pkhPrefix, p2shPrefix []byte, segwitEnabled bool) ([]byte, error)

func CalculateTxID

func CalculateTxID(tx string) string

func CompileCoinbaseScript

func CompileCoinbaseScript(blockHeight int32, extraNonce uint64) []byte

func CompileP2PK

func CompileP2PK(serializedPubKey []byte) []byte

func CompileP2PKH

func CompileP2PKH(pubKeyHash []byte) []byte

func CompileP2SH

func CompileP2SH(scriptHash []byte) []byte

func CompileP2TR

func CompileP2TR(scriptHash []byte) []byte

func CompileP2WPKH

func CompileP2WPKH(pubKeyHash []byte) []byte

func CompileP2WSH

func CompileP2WSH(scriptHash []byte) []byte

func EncodeOpCode

func EncodeOpCode(opCode int) []byte

func EncodeScriptData

func EncodeScriptData(data []byte) []byte

func GenerateScriptSig

func GenerateScriptSig(sig []byte, pub []byte) []byte

func GenerateTx

func GenerateTx(
	privKey *secp256k1.PrivateKey,
	baseTx *Transaction,
	inputs []*types.TxInput,
	outputs []*types.TxOutput,
	feePerByte uint64,
) ([]byte, error)

func PrivKeyToAddress

func PrivKeyToAddress(privKey *secp256k1.PrivateKey, version []byte) string

Types

type Transaction

type Transaction struct {
	PrefixP2PKH    []byte
	PrefixP2SH     []byte
	SegwitEnabled  bool
	Version        uint32
	VersionGroupID *uint32
	LockTime       uint32
	ExpiryHeight   *uint32
	Inputs         []*input
	Outputs        []*output
}

func GenerateRawTx

func GenerateRawTx(
	baseTx *Transaction,
	inputs []*types.TxInput,
	outputs []*types.TxOutput,
	fee uint64,
) (*Transaction, error)

func GenerateSignedTx

func GenerateSignedTx(
	privKey *secp256k1.PrivateKey,
	baseTx *Transaction,
	inputs []*types.TxInput,
	outputs []*types.TxOutput,
	fee uint64,
) (*Transaction, error)

func NewTransaction

func NewTransaction(
	version, lockTime uint32,
	prefixP2PKH, prefixP2SH []byte,
	segwitEnabled bool,
) *Transaction

func (*Transaction) AddInput

func (tx *Transaction) AddInput(hash string, index, sequence uint32, script []byte) error

func (*Transaction) AddOutput

func (tx *Transaction) AddOutput(script []byte, value uint64)

func (*Transaction) CalculateScriptSig

func (tx *Transaction) CalculateScriptSig(index uint32, script []byte) ([]byte, error)

func (*Transaction) Serialize

func (tx *Transaction) Serialize(extraPayload []byte) ([]byte, error)

func (*Transaction) SetExpiryHeight

func (tx *Transaction) SetExpiryHeight(expiryHeight uint32)

func (*Transaction) SetVersionGroupID

func (tx *Transaction) SetVersionGroupID(versionGroupID uint32)

func (*Transaction) SetVersionMask

func (tx *Transaction) SetVersionMask(versionMask uint32)

func (*Transaction) ShallowCopy

func (tx *Transaction) ShallowCopy() *Transaction

Jump to

Keyboard shortcuts

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