zec

package
v0.5.7 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2022 License: BlueOak-1.0.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MinimumTxOverhead
	// 4 header + 4 nVersionGroup + 1 varint input count + 1 varint output count
	// + 4 lockTime + 4 nExpiryHeight + 8 valueBalanceSapling + 1 varint nSpendsSapling
	// + 1 varint nOutputsSapling + 1 varint nJoinSplit
	MinimumTxOverhead = 29

	InitTxSizeBase = MinimumTxOverhead + btc.P2PKHOutputSize + btc.P2SHOutputSize // 29 + 34 + 32 = 95
	InitTxSize     = InitTxSizeBase + btc.RedeemP2PKHInputSize                    // 95 + 149 = 244
)
View Source
const (
	VersionPreOverwinter = 2
	VersionOverwinter    = 3
	VersionSapling       = 4
	VersionNU5           = 5
	MaxExpiryHeight      = 499999999 // https://zips.z.cash/zip-0203

)

Variables

View Source
var (
	UnitInfo = dex.UnitInfo{
		AtomicUnit: "Zats",
		Conventional: dex.Denomination{
			Unit:             "ZEC",
			ConversionFactor: 1e8,
		},
	}

	// MainNetParams are the clone parameters for mainnet. ZCash,
	// like Decred, uses two bytes for their address IDs. We will convert
	// between address types on the fly and use these spoof parameters
	// internally.
	MainNetParams = btc.ReadCloneParams(&btc.CloneParams{
		ScriptHashAddrID: 0xBD,
		PubKeyHashAddrID: 0xB8,
		CoinbaseMaturity: 100,
		Net:              0x24e92764,
	})
	// TestNet4Params are the clone parameters for testnet.
	TestNet4Params = btc.ReadCloneParams(&btc.CloneParams{
		PubKeyHashAddrID: 0x25,
		ScriptHashAddrID: 0xBA,
		CoinbaseMaturity: 100,
		Net:              0xfa1af9bf,
	})
	// RegressionNetParams are the clone parameters for simnet.
	RegressionNetParams = btc.ReadCloneParams(&btc.CloneParams{
		PubKeyHashAddrID: 0x25,
		ScriptHashAddrID: 0xBA,
		CoinbaseMaturity: 100,
		Net:              0xaae83f5f,
	})

	// MainNetAddressParams are used for string address parsing. We use a
	// spoofed address internally, since ZCash uses a two-byte address ID
	// instead of a 1-byte ID.
	MainNetAddressParams = &AddressParams{
		ScriptHashAddrID: [2]byte{0x1C, 0xBD},
		PubKeyHashAddrID: [2]byte{0x1C, 0xB8},
	}

	// TestNet4AddressParams are used for string address parsing.
	TestNet4AddressParams = &AddressParams{
		ScriptHashAddrID: [2]byte{0x1C, 0xBA},
		PubKeyHashAddrID: [2]byte{0x1D, 0x25},
	}

	// RegressionNetAddressParams are used for string address parsing.
	RegressionNetAddressParams = &AddressParams{
		ScriptHashAddrID: [2]byte{0x1C, 0xBA},
		PubKeyHashAddrID: [2]byte{0x1D, 0x25},
	}
)
View Source
var (
	// Little-endian encoded CONSENSUS_BRANCH_IDs.
	// https://zcash.readthedocs.io/en/latest/rtd_pages/nu_dev_guide.html#canopy
	ConsensusBranchNU5 = [4]byte{0xB4, 0xD0, 0xD6, 0xC2} // 1687104, testnet: 1842420

)

Functions

func CalcTxSize

func CalcTxSize(tx *wire.MsgTx) uint64

CalcTxSize calculates the size of a ZCash transparent transaction. CalcTxSize won't return accurate results for shielded or blended transactions.

func DecodeAddress

func DecodeAddress(a string, addrParams *AddressParams, btcParams *chaincfg.Params) (btcutil.Address, error)

DecodeAddress decodes an address string into an internal btc address. ZCash uses a double SHA-256 checksum but with a 2-byte address ID, so a little customization is needed. TODO: There also appears to be a bech32 encoding and something called a "unified payment address", but for our use of this function client-side, we will never generate those addresses. Do we need to revisit before NU5?

func EncodeAddress

func EncodeAddress(btcAddr btcutil.Address, addrParams *AddressParams) (string, error)

EncodeAddress converts a btcutil.Address from the BTC backend into a ZCash address string.

func RecodeAddress

func RecodeAddress(addr string, addrParams *AddressParams, btcParams *chaincfg.Params) (string, error)

RecodeAddress converts an internal btc address to a ZCash address string.

Types

type AddressParams

type AddressParams struct {
	PubKeyHashAddrID [2]byte
	ScriptHashAddrID [2]byte
}

type Block

type Block struct {
	wire.MsgBlock
	// Transactions and MsgBlock.Transactions should both be populated. Each
	// *Tx.MsgTx will be the same as the *MsgTx in MsgBlock.Transactions.
	Transactions         []*Tx
	HashBlockCommitments [32]byte // Using NU5 name
	Nonce                [32]byte // Bitcoin uses uint32
	Solution             []byte   // length 1344 on main and testnet, 36 on regtest
}

Block extends a wire.MsgBlock to specify ZCash specific fields, or in the case of the Nonce, a type-variant.

func DeserializeBlock

func DeserializeBlock(b []byte) (*Block, error)

DeserializeBlock deserializes the ZCash-encoded block.

type JoinSplit

type JoinSplit struct {
	Old, New uint64
}

JoinSplit is only the new and old fields of a vJoinSplit.

type Tx

type Tx struct {
	*wire.MsgTx
	ExpiryHeight        uint32
	NSpendsSapling      uint64
	NOutputsSapling     uint64
	ValueBalanceSapling int64
	NActionsOrchard     uint64
	SizeProofsOrchard   uint64
	NJoinSplit          uint64
	VJoinSplit          []*JoinSplit
	ValueBalanceOrchard int64
}

Tx is a ZCash-adapted MsgTx. Tx will decode any version transaction, but will not save most data for shielded transactions. Tx can only produce tx hashes for unshielded transactions. Tx can only create signature hashes for unshielded version 5 transactions.

func DeserializeTx

func DeserializeTx(b []byte) (*Tx, error)

see https://zips.z.cash/protocol/protocol.pdf section 7.1

func NewTxFromMsgTx

func NewTxFromMsgTx(tx *wire.MsgTx, expiryHeight uint32) *Tx

NewTxFromMsgTx creates a Tx embedding the MsgTx, and adding ZCash-specific fields.

func (*Tx) Bytes

func (tx *Tx) Bytes() (_ []byte, err error)

Bytes encodes the receiver to w using the bitcoin protocol encoding. This is part of the Message interface implementation. See Serialize for encoding transactions to be stored to disk, such as in a database, as opposed to encoding transactions for the wire. msg.Version must be 4 or 5.

func (*Tx) SerializeSize

func (tx *Tx) SerializeSize() uint64

SerializeSize is the size of the transaction when serialized.

func (*Tx) SignatureDigest

func (tx *Tx) SignatureDigest(vin int, hashType txscript.SigHashType, vals []int64, prevScripts [][]byte) (_ [32]byte, err error)

SignatureDigest produces a hash of tx data suitable for signing. SignatureDigest only works correctly for unshielded version 5 transactions.

func (*Tx) TxHash

func (tx *Tx) TxHash() chainhash.Hash

TxHash generates the Hash for the transaction.

func (*Tx) ZecDecode

func (tx *Tx) ZecDecode(r io.Reader) (err error)

ZecDecode reads the serialized transaction from the reader and populates the *Tx's fields.

Jump to

Keyboard shortcuts

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