bitcoin

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Feb 29, 2024 License: Apache-2.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ChainBitcoin  = 1
	ChainLitecoin = 5

	ValuePrecision = 8
	ValueSatoshi   = 100000000

	MaxUnspentUtxo = 512

	TimeLockMinimum = time.Hour * 1
	TimeLockMaximum = time.Hour * 24 * 365

	ScriptPubKeyTypeWitnessKeyHash    = "witness_v0_keyhash"
	ScriptPubKeyTypeWitnessScriptHash = "witness_v0_scripthash"
	SigHashType                       = txscript.SigHashAll | txscript.SigHashAnyOneCanPay

	InputTypeP2WPKHAccoutant             = 1
	InputTypeP2WSHMultisigHolderSigner   = 2
	InputTypeP2WSHMultisigObserverSigner = 3

	MaxTransactionSequence = 0xffffffff
	MaxStandardTxWeight    = 300000
)

Variables

This section is empty.

Functions

func BuildInsufficientInputError added in v0.11.0

func BuildInsufficientInputError(cat, inSatoshi, outSatoshi string) error

func CanonicalSignatureDER added in v0.6.1

func CanonicalSignatureDER(sig []byte) ([]byte, error)

func CheckDerivation added in v0.5.0

func CheckDerivation(public string, chainCode []byte, maxRange uint32) error

func CheckFinalization

func CheckFinalization(num uint64, coinbase bool) bool

func CheckMultisigHolderSignerScript

func CheckMultisigHolderSignerScript(script []byte) bool

func CheckTransactionPartiallySignedBy added in v0.5.0

func CheckTransactionPartiallySignedBy(raw, public string) bool

func DeriveBIP32 added in v0.4.1

func DeriveBIP32(public string, chainCode []byte, children ...uint32) (string, string, error)

func EncodeAddress

func EncodeAddress(script []byte, chain byte) (string, error)

func EstimateAvgFee added in v0.12.0

func EstimateAvgFee(chain byte, rpc string) (int64, error)

func ExtractPkScriptAddr added in v0.8.0

func ExtractPkScriptAddr(pkScript []byte, chain byte) (string, error)

func HashMessageForSignature

func HashMessageForSignature(msg string, chain byte) []byte

func IsInsufficientInputError

func IsInsufficientInputError(err error) bool

func MarshalWiredTransaction added in v0.5.0

func MarshalWiredTransaction(msgTx *wire.MsgTx, encoding wire.MessageEncoding, chain byte) ([]byte, error)

func NetConfig added in v0.9.17

func NetConfig(chain byte) *chaincfg.Params

func ParseAddress

func ParseAddress(addr string, chain byte) ([]byte, error)

func ParseSatoshi

func ParseSatoshi(amount string) int64

func ParseSequence

func ParseSequence(lock time.Duration, chain byte) int64

func RPCGetBlockAverageFeePerBytes added in v0.12.0

func RPCGetBlockAverageFeePerBytes(chain byte, rpc string) (*big.Int, error)

func RPCGetBlockHash

func RPCGetBlockHash(rpc string, num int64) (string, error)

func RPCGetBlockHeight

func RPCGetBlockHeight(rpc string) (int64, error)

func RPCGetMempoolAverageFeePerBytes added in v0.12.0

func RPCGetMempoolAverageFeePerBytes(rpc string) (*big.Int, error)

func RPCGetTransactionOutput

func RPCGetTransactionOutput(chain byte, rpc, hash string, index int64) (*RPCTransaction, *Output, error)

func RPCGetTransactionSender

func RPCGetTransactionSender(chain byte, rpc string, tx *RPCTransaction) (string, error)

func RPCSendRawTransaction

func RPCSendRawTransaction(rpc, raw string) (string, error)

func SpendSignedTransaction added in v0.5.0

func SpendSignedTransaction(raw string, feeInputs []*Input, accountant string, chain byte) (*wire.MsgTx, error)

func ValueDust

func ValueDust(chain byte) int64

func VerifyHolderKey

func VerifyHolderKey(public string) error

func VerifySignatureDER

func VerifySignatureDER(public string, msg, sig []byte) error

func WriteBytes added in v0.11.0

func WriteBytes(enc *common.Encoder, b []byte)

Types

type Input

type Input struct {
	TransactionHash string
	Index           uint32
	Satoshi         int64
	Script          []byte
	Sequence        uint32
	RouteBackup     bool
}

type MemPoolTransaction added in v0.12.0

type MemPoolTransaction struct {
	Fees struct {
		Base float64 `json:"base"`
	} `json:"fees"`
	VSize int64 `json:"vsize"`
}

type Output

type Output struct {
	Address  string
	Satoshi  int64
	Height   uint64
	Coinbase bool
}

type PartiallySignedTransaction

type PartiallySignedTransaction struct {
	*psbt.Packet
}

func BuildPartiallySignedTransaction

func BuildPartiallySignedTransaction(mainInputs []*Input, outputs []*Output, rid []byte, chain byte) (*PartiallySignedTransaction, error)

func SignPartiallySignedTransaction added in v0.8.0

func SignPartiallySignedTransaction(raw []byte, signer *secp256k1.PrivateKey) *PartiallySignedTransaction

func UnmarshalPartiallySignedTransaction

func UnmarshalPartiallySignedTransaction(b []byte) (*PartiallySignedTransaction, error)

func (*PartiallySignedTransaction) EstimateVirtualSize added in v0.12.0

func (psbt *PartiallySignedTransaction) EstimateVirtualSize() int

func (*PartiallySignedTransaction) Hash

func (raw *PartiallySignedTransaction) Hash() string

func (*PartiallySignedTransaction) IsRecoveryTransaction added in v0.8.0

func (psbt *PartiallySignedTransaction) IsRecoveryTransaction() bool

func (*PartiallySignedTransaction) Marshal

func (raw *PartiallySignedTransaction) Marshal() []byte

func (*PartiallySignedTransaction) SigHash

func (psbt *PartiallySignedTransaction) SigHash(idx int) []byte

func (*PartiallySignedTransaction) SignedTransaction added in v0.5.0

func (psbt *PartiallySignedTransaction) SignedTransaction(holder, signer, observer string) (*wire.MsgTx, error)

type RPCBlock

type RPCBlock struct {
	Hash          string   `json:"hash"`
	Height        uint64   `json:"height"`
	Tx            []string `json:"tx"`
	Confirmations int      `json:"confirmations"`
}

func RPCGetBlock

func RPCGetBlock(rpc, hash string) (*RPCBlock, error)

type RPCBlockWithTransactions

type RPCBlockWithTransactions struct {
	Hash   string            `json:"hash"`
	Height uint64            `json:"height"`
	Tx     []*RPCTransaction `json:"tx"`
}

func RPCGetBlockWithTransactions

func RPCGetBlockWithTransactions(chain byte, rpc, hash string) (*RPCBlockWithTransactions, error)

type RPCTransaction

type RPCTransaction struct {
	TxId      string    `json:"txid"`
	Vin       []*rpcIn  `json:"vin"`
	Vout      []*rpcOut `json:"vout"`
	BlockHash string    `json:"blockhash"`
	Hex       string    `json:"hex"`
	Fee       float64   `json:"fee"`
	VSize     int64     `json:"vsize"`
}

func RPCGetRawMempool

func RPCGetRawMempool(chain byte, rpc string) ([]*RPCTransaction, error)

func RPCGetRawMempoolWithTransactions added in v0.12.0

func RPCGetRawMempoolWithTransactions(rpc string) ([]*RPCTransaction, error)

func RPCGetTransaction

func RPCGetTransaction(chain byte, rpc, hash string) (*RPCTransaction, error)

type WitnessScriptAccount

type WitnessScriptAccount struct {
	Sequence uint32
	Script   []byte
	Address  string
}

func BuildWitnessScriptAccount

func BuildWitnessScriptAccount(holder, signer, observer string, lock time.Duration, chain byte) (*WitnessScriptAccount, error)

thresh(2,pk(HOLDER),pk(SIGNER),and(pk(OBSERVER),older(12960))) thresh(2,pk(HOLDER),s:pk(SIGNER),sj:and_v(v:pk(OBSERVER),n:older(12960)))

<HOLDER> OP_CHECKSIG OP_SWAP <SIGNER> OP_CHECKSIG OP_ADD OP_SWAP OP_SIZE OP_0NOTEQUAL OP_IF <OBSERVER> OP_CHECKSIGVERIFY <a032> OP_CHECKSEQUENCEVERIFY OP_0NOTEQUAL OP_ENDIF OP_ADD 2 OP_EQUAL

func UnmarshalWitnessScriptAccount added in v0.5.0

func UnmarshalWitnessScriptAccount(extra []byte) (*WitnessScriptAccount, error)

func (*WitnessScriptAccount) Marshal added in v0.5.0

func (wsa *WitnessScriptAccount) Marshal() []byte

Jump to

Keyboard shortcuts

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