rename `network` variables and method names typed as NetworkKind to `network_kind`
This commit is contained in:
parent
fd3d50572c
commit
f04b94b13a
|
@ -135,7 +135,7 @@ impl Address {
|
|||
/// Returns the network for the address.
|
||||
pub fn network(&self) -> NetworkKind {
|
||||
match &self {
|
||||
Self::Transparent(address) => address.network(),
|
||||
Self::Transparent(address) => address.network_kind(),
|
||||
Self::Sapling { network, .. } | Self::Unified { network, .. } => *network,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ pub enum Address {
|
|||
/// P2SH (Pay to Script Hash) addresses
|
||||
PayToScriptHash {
|
||||
/// Production, test, or other network
|
||||
network: NetworkKind,
|
||||
network_kind: NetworkKind,
|
||||
/// 20 bytes specifying a script hash.
|
||||
script_hash: [u8; 20],
|
||||
},
|
||||
|
@ -41,7 +41,7 @@ pub enum Address {
|
|||
/// P2PKH (Pay to Public Key Hash) addresses
|
||||
PayToPublicKeyHash {
|
||||
/// Production, test, or other network
|
||||
network: NetworkKind,
|
||||
network_kind: NetworkKind,
|
||||
/// 20 bytes specifying a public key hash, which is a RIPEMD-160
|
||||
/// hash of a SHA-256 hash of a compressed ECDSA key encoding.
|
||||
pub_key_hash: [u8; 20],
|
||||
|
@ -54,17 +54,17 @@ impl fmt::Debug for Address {
|
|||
|
||||
match self {
|
||||
Address::PayToScriptHash {
|
||||
network,
|
||||
network_kind,
|
||||
script_hash,
|
||||
} => debug_struct
|
||||
.field("network", network)
|
||||
.field("network_kind", network_kind)
|
||||
.field("script_hash", &hex::encode(script_hash))
|
||||
.finish(),
|
||||
Address::PayToPublicKeyHash {
|
||||
network,
|
||||
network_kind,
|
||||
pub_key_hash,
|
||||
} => debug_struct
|
||||
.field("network", network)
|
||||
.field("network_kind", network_kind)
|
||||
.field("pub_key_hash", &hex::encode(pub_key_hash))
|
||||
.finish(),
|
||||
}
|
||||
|
@ -97,17 +97,17 @@ impl ZcashSerialize for Address {
|
|||
fn zcash_serialize<W: io::Write>(&self, mut writer: W) -> Result<(), io::Error> {
|
||||
match self {
|
||||
Address::PayToScriptHash {
|
||||
network,
|
||||
network_kind,
|
||||
script_hash,
|
||||
} => {
|
||||
writer.write_all(&network.b58_script_address_prefix())?;
|
||||
writer.write_all(&network_kind.b58_script_address_prefix())?;
|
||||
writer.write_all(script_hash)?
|
||||
}
|
||||
Address::PayToPublicKeyHash {
|
||||
network,
|
||||
network_kind,
|
||||
pub_key_hash,
|
||||
} => {
|
||||
writer.write_all(&network.b58_pubkey_address_prefix())?;
|
||||
writer.write_all(&network_kind.b58_pubkey_address_prefix())?;
|
||||
writer.write_all(pub_key_hash)?
|
||||
}
|
||||
}
|
||||
|
@ -127,25 +127,25 @@ impl ZcashDeserialize for Address {
|
|||
match version_bytes {
|
||||
zcash_primitives::constants::mainnet::B58_SCRIPT_ADDRESS_PREFIX => {
|
||||
Ok(Address::PayToScriptHash {
|
||||
network: NetworkKind::Mainnet,
|
||||
network_kind: NetworkKind::Mainnet,
|
||||
script_hash: hash_bytes,
|
||||
})
|
||||
}
|
||||
zcash_primitives::constants::testnet::B58_SCRIPT_ADDRESS_PREFIX => {
|
||||
Ok(Address::PayToScriptHash {
|
||||
network: NetworkKind::Testnet,
|
||||
network_kind: NetworkKind::Testnet,
|
||||
script_hash: hash_bytes,
|
||||
})
|
||||
}
|
||||
zcash_primitives::constants::mainnet::B58_PUBKEY_ADDRESS_PREFIX => {
|
||||
Ok(Address::PayToPublicKeyHash {
|
||||
network: NetworkKind::Mainnet,
|
||||
network_kind: NetworkKind::Mainnet,
|
||||
pub_key_hash: hash_bytes,
|
||||
})
|
||||
}
|
||||
zcash_primitives::constants::testnet::B58_PUBKEY_ADDRESS_PREFIX => {
|
||||
Ok(Address::PayToPublicKeyHash {
|
||||
network: NetworkKind::Testnet,
|
||||
network_kind: NetworkKind::Testnet,
|
||||
pub_key_hash: hash_bytes,
|
||||
})
|
||||
}
|
||||
|
@ -160,18 +160,18 @@ trait ToAddressWithNetwork {
|
|||
}
|
||||
|
||||
impl ToAddressWithNetwork for Script {
|
||||
fn to_address(&self, network: NetworkKind) -> Address {
|
||||
fn to_address(&self, network_kind: NetworkKind) -> Address {
|
||||
Address::PayToScriptHash {
|
||||
network,
|
||||
network_kind,
|
||||
script_hash: Address::hash_payload(self.as_raw_bytes()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ToAddressWithNetwork for PublicKey {
|
||||
fn to_address(&self, network: NetworkKind) -> Address {
|
||||
fn to_address(&self, network_kind: NetworkKind) -> Address {
|
||||
Address::PayToPublicKeyHash {
|
||||
network,
|
||||
network_kind,
|
||||
pub_key_hash: Address::hash_payload(&self.serialize()[..]),
|
||||
}
|
||||
}
|
||||
|
@ -179,26 +179,26 @@ impl ToAddressWithNetwork for PublicKey {
|
|||
|
||||
impl Address {
|
||||
/// Create an address for the given public key hash and network.
|
||||
pub fn from_pub_key_hash(network: NetworkKind, pub_key_hash: [u8; 20]) -> Self {
|
||||
pub fn from_pub_key_hash(network_kind: NetworkKind, pub_key_hash: [u8; 20]) -> Self {
|
||||
Self::PayToPublicKeyHash {
|
||||
network,
|
||||
network_kind,
|
||||
pub_key_hash,
|
||||
}
|
||||
}
|
||||
|
||||
/// Create an address for the given script hash and network.
|
||||
pub fn from_script_hash(network: NetworkKind, script_hash: [u8; 20]) -> Self {
|
||||
pub fn from_script_hash(network_kind: NetworkKind, script_hash: [u8; 20]) -> Self {
|
||||
Self::PayToScriptHash {
|
||||
network,
|
||||
network_kind,
|
||||
script_hash,
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the network kind for this address.
|
||||
pub fn network(&self) -> NetworkKind {
|
||||
pub fn network_kind(&self) -> NetworkKind {
|
||||
match self {
|
||||
Address::PayToScriptHash { network, .. } => *network,
|
||||
Address::PayToPublicKeyHash { network, .. } => *network,
|
||||
Address::PayToScriptHash { network_kind, .. } => *network_kind,
|
||||
Address::PayToPublicKeyHash { network_kind, .. } => *network_kind,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -338,7 +338,7 @@ mod tests {
|
|||
|
||||
assert_eq!(
|
||||
format!("{t_addr:?}"),
|
||||
"TransparentAddress { network: Mainnet, script_hash: \"7d46a730d31f97b1930d3368a967c309bd4d136a\" }"
|
||||
"TransparentAddress { network_kind: Mainnet, script_hash: \"7d46a730d31f97b1930d3368a967c309bd4d136a\" }"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -68,7 +68,7 @@ fn test_funding_stream_addresses() -> Result<(), Report> {
|
|||
let address =
|
||||
transparent::Address::from_str(address).expect("address should deserialize");
|
||||
assert_eq!(
|
||||
&address.network(),
|
||||
&address.network_kind(),
|
||||
network,
|
||||
"incorrect network for {receiver:?} funding stream address constant: {address}",
|
||||
);
|
||||
|
|
|
@ -231,7 +231,7 @@ impl ParameterSubsidy for Network {
|
|||
Network::Mainnet => NetworkUpgrade::Canopy
|
||||
.activation_height(self)
|
||||
.expect("canopy activation height should be available"),
|
||||
// TODO: Check what zcashd does here, consider adding a field to `NetworkParamters` to make this configurable.
|
||||
// TODO: Check what zcashd does here, consider adding a field to `NetworkParameters` to make this configurable.
|
||||
Network::Testnet(_params) => FIRST_HALVING_TESTNET,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -450,11 +450,11 @@ where
|
|||
// Prevent loss of miner funds due to an unsupported or incorrect address type.
|
||||
if let Some(miner_address) = mining_config.miner_address.clone() {
|
||||
assert_eq!(
|
||||
miner_address.network(),
|
||||
miner_address.network_kind(),
|
||||
network.kind(),
|
||||
"incorrect miner address config: {miner_address} \
|
||||
network.network {network} and miner address network {} must match",
|
||||
miner_address.network(),
|
||||
miner_address.network_kind(),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -502,7 +502,7 @@ fn address_variant(address: &transparent::Address) -> u8 {
|
|||
// Return smaller values for more common variants.
|
||||
//
|
||||
// (This probably doesn't matter, but it might help slightly with data compression.)
|
||||
match (address.network(), address) {
|
||||
match (address.network_kind(), address) {
|
||||
(Mainnet, PayToPublicKeyHash { .. }) => 0,
|
||||
(Mainnet, PayToScriptHash { .. }) => 1,
|
||||
// There's no way to distinguish between Regtest and Testnet for encoded transparent addresses,
|
||||
|
|
Loading…
Reference in New Issue