zcash

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2024 License: GPL-3.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const Version int32 = 4

Version of Zcash transactions supported by the multichain.

Variables

View Source
var (

	// MainNetParams defines the mainnet configuration.
	MainNetParams = Params{
		Params: &chaincfg.MainNetParams,

		P2PKHPrefix: []byte{0x1C, 0xB8},
		P2SHPrefix:  []byte{0x1C, 0xBD},
		Upgrades: []ParamsUpgrade{
			{0, []byte{0x00, 0x00, 0x00, 0x00}},
			{347500, []byte{0x19, 0x1B, 0xA8, 0x5B}},
			{419200, []byte{0xBB, 0x09, 0xB8, 0x76}},
			{653600, []byte{0x60, 0x0E, 0xB4, 0x2B}},
			{903000, []byte{0x0B, 0x23, 0xB9, 0xF5}},
			{1046400, []byte{0xA6, 0x75, 0xFF, 0xE9}},
			{1687104, []byte{0xB4, 0xD0, 0xD6, 0xC2}},
		},
	}

	// TestNet3Params defines the testnet configuration.
	TestNet3Params = Params{
		Params: &chaincfg.TestNet3Params,

		P2PKHPrefix: []byte{0x1D, 0x25},
		P2SHPrefix:  []byte{0x1C, 0xBA},
		Upgrades: []ParamsUpgrade{
			{0, []byte{0x00, 0x00, 0x00, 0x00}},
			{207500, []byte{0x19, 0x1B, 0xA8, 0x5B}},
			{280000, []byte{0xBB, 0x09, 0xB8, 0x76}},
			{584000, []byte{0x60, 0x0E, 0xB4, 0x2B}},
			{903800, []byte{0x0B, 0x23, 0xB9, 0xF5}},
			{1028500, []byte{0xA6, 0x75, 0xFF, 0xE9}},
			{1842420, []byte{0xB4, 0xD0, 0xD6, 0xC2}},
		},
	}

	// RegressionNetParams defines a devet/regnet configuration.
	RegressionNetParams = Params{
		Params: &chaincfg.RegressionNetParams,

		P2PKHPrefix: []byte{0x1D, 0x25},
		P2SHPrefix:  []byte{0x1C, 0xBA},
		Upgrades: []ParamsUpgrade{
			{0, []byte{0x00, 0x00, 0x00, 0x00}},
			{10, []byte{0x19, 0x1B, 0xA8, 0x5B}},
			{20, []byte{0xBB, 0x09, 0xB8, 0x76}},
			{30, []byte{0x60, 0x0E, 0xB4, 0x2B}},
			{40, []byte{0x0B, 0x23, 0xB9, 0xF5}},
			{50, []byte{0xA6, 0x75, 0xFF, 0xE9}},
			{60, []byte{0xB4, 0xD0, 0xD6, 0xC2}},
		},
	}
)
View Source
var NewClient = bitcoin.NewClient

NewClient re-exports bitcoin.Client

Functions

func NewTxBuilder

func NewTxBuilder(params *Params, expiryHeight uint32) utxo.TxBuilder

NewTxBuilder returns an implementation the transaction builder interface from the Bitcoin Compat API, and exposes the functionality to build simple Zcash transactions.

Types

type Address

type Address interface {
	btcutil.Address
	BitcoinAddress() btcutil.Address
}

An Address represents a Zcash address.

type AddressDecoder

type AddressDecoder struct {
	// contains filtered or unexported fields
}

AddressDecoder encapsulates the chain specific configurations and implements the address.Decoder interface

func NewAddressDecoder

func NewAddressDecoder(params *Params) AddressDecoder

NewAddressDecoder constructs a new AddressDecoder with the chain specific configurations

func (AddressDecoder) DecodeAddress

func (decoder AddressDecoder) DecodeAddress(addr address.Address) (address.RawAddress, error)

DecodeAddress implements the address.Decoder interface

type AddressEncodeDecoder

type AddressEncodeDecoder struct {
	AddressEncoder
	AddressDecoder
}

AddressEncodeDecoder implements the address.EncodeDecoder interface

func NewAddressEncodeDecoder

func NewAddressEncodeDecoder(params *Params) AddressEncodeDecoder

NewAddressEncodeDecoder constructs a new AddressEncodeDecoder with the chain specific configurations

type AddressEncoder

type AddressEncoder struct {
	// contains filtered or unexported fields
}

AddressEncoder encapsulates the chain specific configurations and implements the address.Encoder interface

func NewAddressEncoder

func NewAddressEncoder(params *Params) AddressEncoder

NewAddressEncoder constructs a new AddressEncoder with the chain specific configurations

func (AddressEncoder) EncodeAddress

func (encoder AddressEncoder) EncodeAddress(rawAddr address.RawAddress) (address.Address, error)

EncodeAddress implements the address.Encoder interface

type AddressPubKeyHash

type AddressPubKeyHash struct {
	*btcutil.AddressPubKeyHash
	// contains filtered or unexported fields
}

AddressPubKeyHash represents an address for P2PKH transactions for Zcash that is compatible with the Bitcoin Compat API.

func NewAddressPubKeyHash

func NewAddressPubKeyHash(pkh []byte, params *Params) (AddressPubKeyHash, error)

NewAddressPubKeyHash returns a new AddressPubKeyHash that is compatible with the Bitcoin Compat API.

func (AddressPubKeyHash) BitcoinAddress

func (addr AddressPubKeyHash) BitcoinAddress() btcutil.Address

BitcoinAddress returns the address as if it was a Bitcoin address.

func (AddressPubKeyHash) EncodeAddress

func (addr AddressPubKeyHash) EncodeAddress() string

EncodeAddress returns the string encoding of the payment address associated with the Address value. See the comment on String for how this method differs from String.

func (AddressPubKeyHash) IsForNet

func (addr AddressPubKeyHash) IsForNet(params *chaincfg.Params) bool

IsForNet returns whether or not the address is associated with the passed bitcoin network.

func (AddressPubKeyHash) ScriptAddress

func (addr AddressPubKeyHash) ScriptAddress() []byte

ScriptAddress returns the raw bytes of the address to be used when inserting the address into a txout's script.

func (AddressPubKeyHash) String

func (addr AddressPubKeyHash) String() string

String returns the string encoding of the transaction output destination.

Please note that String differs subtly from EncodeAddress: String will return the value as a string without any conversion, while EncodeAddress may convert destination types (for example, converting pubkeys to P2PKH addresses) before encoding as a payment address string.

type AddressScriptHash

type AddressScriptHash struct {
	*btcutil.AddressScriptHash
	// contains filtered or unexported fields
}

AddressScriptHash represents an address for P2SH transactions for Zcash that is compatible with the Bitcoin Compat API.

func NewAddressScriptHash

func NewAddressScriptHash(script []byte, params *Params) (AddressScriptHash, error)

NewAddressScriptHash returns a new AddressScriptHash that is compatible with the Bitcoin Compat API.

func NewAddressScriptHashFromHash

func NewAddressScriptHashFromHash(scriptHash []byte, params *Params) (AddressScriptHash, error)

NewAddressScriptHashFromHash returns a new AddressScriptHash that is compatible with the Bitcoin Compat API.

func (AddressScriptHash) BitcoinAddress

func (addr AddressScriptHash) BitcoinAddress() btcutil.Address

BitcoinAddress returns the address as if it was a Bitcoin address.

func (AddressScriptHash) EncodeAddress

func (addr AddressScriptHash) EncodeAddress() string

EncodeAddress returns the string encoding of the payment address associated with the Address value. See the comment on String for how this method differs from String.

func (AddressScriptHash) IsForNet

func (addr AddressScriptHash) IsForNet(params *chaincfg.Params) bool

IsForNet returns whether or not the address is associated with the passed bitcoin network.

func (AddressScriptHash) ScriptAddress

func (addr AddressScriptHash) ScriptAddress() []byte

ScriptAddress returns the raw bytes of the address to be used when inserting the address into a txout's script.

func (AddressScriptHash) String

func (addr AddressScriptHash) String() string

String returns the string encoding of the transaction output destination.

Please note that String differs subtly from EncodeAddress: String will return the value as a string without any conversion, while EncodeAddress may convert destination types (for example, converting pubkeys to P2PKH addresses) before encoding as a payment address string.

type Client

type Client = bitcoin.Client

Client re-exports bitcoin.Client.

type ClientOptions

type ClientOptions = bitcoin.ClientOptions

ClientOptions are used to parameterise the behaviour of the Client.

func DefaultClientOptions

func DefaultClientOptions() ClientOptions

DefaultClientOptions returns ClientOptions with the default settings. These settings are valid for use with the default local deployment of the multichain. In production, the host, user, and password should be changed.

type GasEstimator

type GasEstimator struct {
	// contains filtered or unexported fields
}

A GasEstimator returns the SATs-per-byte that is needed in order to confirm transactions with an estimated maximum delay of one block. In distributed networks that collectively build, sign, and submit transactions, it is important that all nodes in the network have reached consensus on the SATs-per-byte.

func NewGasEstimator

func NewGasEstimator(client Client, numBlocks int64, fallbackGas pack.U256) GasEstimator

NewGasEstimator returns a simple gas estimator that always returns the given number of SATs-per-byte.

func (GasEstimator) EstimateGas

func (gasEstimator GasEstimator) EstimateGas(ctx context.Context) (pack.U256, pack.U256, error)

EstimateGas returns the number of SATs-per-byte (for both price and cap) that is needed in order to confirm transactions with an estimated maximum delay of `numBlocks` block. It is the responsibility of the caller to know the number of bytes in their transaction. This method calls the `estimatesmartfee` RPC call to the node, which based on a conservative (considering longer history) strategy returns the estimated BTC per kilobyte of data in the transaction. An error will be returned if the bitcoin node hasn't observed enough blocks to make an estimate for the provided target `numBlocks`.

type Params

type Params struct {
	// TODO: We do not actually need to embed the entire chaincfg params object.
	*chaincfg.Params

	P2SHPrefix  []byte
	P2PKHPrefix []byte
	Upgrades    []ParamsUpgrade
}

Params signifies the chain specific parameters of the Zcash network.

type ParamsUpgrade

type ParamsUpgrade struct {
	ActivationHeight uint32
	BranchID         []byte
}

ParamsUpgrade ...

type Tx

type Tx struct {
	// contains filtered or unexported fields
}

Tx represents a simple Zcash transaction that implements the Bitcoin Compat API.

func (*Tx) Hash

func (tx *Tx) Hash() (pack.Bytes, error)

Hash returns the transaction hash of the given underlying transaction.

func (*Tx) Inputs

func (tx *Tx) Inputs() ([]utxo.Input, error)

Inputs returns the UTXO inputs in the underlying transaction.

func (*Tx) Outputs

func (tx *Tx) Outputs() ([]utxo.Output, error)

Outputs returns the UTXO outputs in the underlying transaction.

func (*Tx) Serialize

func (tx *Tx) Serialize() (pack.Bytes, error)

Serialize serializes the UTXO transaction to bytes.

func (*Tx) Sighashes

func (tx *Tx) Sighashes() ([]pack.Bytes32, error)

Sighashes returns the digests that must be signed before the transaction can be submitted by the client.

func (*Tx) Sign

func (tx *Tx) Sign(signatures []pack.Bytes65, pubKey pack.Bytes) error

Sign consumes a list of signatures, and adds them to the list of UTXOs in the underlying transactions.

type TxBuilder

type TxBuilder struct {
	// contains filtered or unexported fields
}

The TxBuilder is an implementation of a UTXO-compatible transaction builder for Bitcoin.

func (TxBuilder) BuildTx

func (txBuilder TxBuilder) BuildTx(inputs []utxo.Input, recipients []utxo.Recipient) (utxo.Tx, error)

BuildTx returns a simple Zcash transaction that consumes the funds from the given outputs, and sends the to the given recipients. The difference in the sum value of the inputs and the sum value of the recipients is paid as a fee to the Zcash network.

It is assumed that the required signature scripts require the SIGHASH_ALL signatures and the serialized public key:

builder := txscript.NewScriptBuilder()
builder.AddData(append(signature.Serialize(), byte(txscript.SigHashAll|SighashForkID)))
builder.AddData(serializedPubKey)

Outputs produced for recipients will use P2PKH, or P2SH scripts as the pubkey script, based on the format of the recipient address.

Jump to

Keyboard shortcuts

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