Documentation
¶
Index ¶
- Constants
- Variables
- func CalcTxSize(tx *wire.MsgTx) uint64
- func DecodeAddress(a string, addrParams *AddressParams, btcParams *chaincfg.Params) (btcutil.Address, error)
- func EncodeAddress(btcAddr btcutil.Address, addrParams *AddressParams) (string, error)
- func RecodeAddress(addr string, addrParams *AddressParams, btcParams *chaincfg.Params) (string, error)
- type AddressParams
- type Block
- type JoinSplit
- type Tx
Constants ¶
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 // LegacyFeeRate returns a standard 10 zats / byte. Prior to ZIP-0317, Zcash // used a standard tx fee of 1000 zats, regardless of tx size. We don't // handle fees correctly yet though, so just use a fee / byte that // guarantees a tx fee of > 1000 zats. A single input spending a p2pkh // output is 149 bytes, so 10 zats / byte should be sufficient for any tx. // // However, zcashd v5.5 begins making stricter fee requirements for both // relay and block inclusion. The release notes state that relay by default // still works with 1000 zat fee txns, but it may be adjusted by operators, // and it may need to be set to the higher ZIP 317 rate. For mining, there // is a small allowance on the number of "unpaid actions" allowed in a // block, so we should take care to pay the ZIP 317 "conventional" rate, // which is multiples of 5000 zats, and a minimum of 10000. To ensure we // have no unpaid actions in our (transparent) transactions, we need a // higher rate. For a 242 byte transaction, like a swap init, we can emulate // this with about 42 zats/byte. Even with 100 zats/byte, our typical redeem // of ~342 bytes would pay 34200 zats, which is only about a penny, so to // ensure our transactions are relayed and mined, we go with a high rate. LegacyFeeRate = 84 )
const ( VersionPreOverwinter = 2 VersionOverwinter = 3 VersionSapling = 4 VersionNU5 = 5 MaxExpiryHeight = 499999999 // https://zips.z.cash/zip-0203 )
Variables ¶
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}, } )
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 ¶
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 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 ¶
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 ¶
see https://zips.z.cash/protocol/protocol.pdf section 7.1
func NewTxFromMsgTx ¶
NewTxFromMsgTx creates a Tx embedding the MsgTx, and adding Zcash-specific fields.
func (*Tx) Bytes ¶
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 ¶
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.