Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: str4d <[email protected]>
  • Loading branch information
nuttycom and str4d committed May 16, 2024
1 parent 90888c6 commit 069ed75
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 13 deletions.
4 changes: 2 additions & 2 deletions qa/rpc-tests/converttex.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

class ConvertTEXTest(BitcoinTestFramework):
'''
Test that the `converttex` RPC method correctly converts transparent
Test that the `z_converttex` RPC method correctly converts transparent
addresses to ZIP 320 TEX addresses.
'''

Expand Down Expand Up @@ -48,7 +48,7 @@ def run_test(self):
];

for tv in test_vectors:
tex = node.converttex(tv[0])
tex = node.z_converttex(tv[0])
assert_equal(tex, tv[1])

if __name__ == '__main__':
Expand Down
6 changes: 3 additions & 3 deletions src/chainparams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ class CMainParams : public CChainParams {
keyConstants.bech32HRPs[SAPLING_EXTENDED_SPEND_KEY] = "secret-extended-key-main";
keyConstants.bech32HRPs[SAPLING_EXTENDED_FVK] = "zxviews";

keyConstants.bech32HRPs[TEX_ADDRESS] = "tex";
keyConstants.bech32mHRPs[TEX_ADDRESS] = "tex";
{
std::vector<std::string> ecc_addresses = {
"t3LmX1cxWPPPqL4TZHx42HU3U5ghbFjRiif",
Expand Down Expand Up @@ -463,7 +463,7 @@ class CTestNetParams : public CChainParams {
keyConstants.bech32HRPs[SAPLING_EXTENDED_SPEND_KEY] = "secret-extended-key-test";
keyConstants.bech32HRPs[SAPLING_EXTENDED_FVK] = "zxviewtestsapling";

keyConstants.bech32HRPs[TEX_ADDRESS] = "textest";
keyConstants.bech32mHRPs[TEX_ADDRESS] = "textest";

// Testnet funding streams
{
Expand Down Expand Up @@ -708,7 +708,7 @@ class CRegTestParams : public CChainParams {
keyConstants.bech32HRPs[SAPLING_EXTENDED_SPEND_KEY] = "secret-extended-key-regtest";
keyConstants.bech32HRPs[SAPLING_EXTENDED_FVK] = "zxviewregtestsapling";

keyConstants.bech32HRPs[TEX_ADDRESS] = "texregtest";
keyConstants.bech32mHRPs[TEX_ADDRESS] = "texregtest";

// The best chain should have at least this much work.
consensus.nMinimumChainWork = uint256S("0x00");
Expand Down
3 changes: 3 additions & 0 deletions src/chainparams.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ class CChainParams: public KeyConstants
const std::string& Bech32HRP(Bech32Type type) const {
return keyConstants.Bech32HRP(type);
}
const std::string& Bech32mHRP(Bech32mType type) const {
return keyConstants.Bech32mHRP(type);
}
const std::vector<SeedSpec6>& FixedSeeds() const { return vFixedSeeds; }
const CCheckpointData& Checkpoints() const { return checkpointData; }
/** Return the founder's reward address and script for a given block height */
Expand Down
9 changes: 8 additions & 1 deletion src/key_constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,20 @@ class KeyConstants
SAPLING_EXTENDED_SPEND_KEY,
SAPLING_EXTENDED_FVK,

MAX_BECH32_TYPES
};

enum Bech32mType {
TEX_ADDRESS,

MAX_BECH32_TYPES
MAX_BECH32M_TYPES
};

virtual std::string NetworkIDString() const =0;
virtual uint32_t BIP44CoinType() const =0;
virtual const std::vector<unsigned char>& Base58Prefix(Base58Type type) const =0;
virtual const std::string& Bech32HRP(Bech32Type type) const =0;
virtual const std::string& Bech32mHRP(Bech32mType type) const =0;
};

class CBaseKeyConstants : public KeyConstants {
Expand All @@ -49,11 +54,13 @@ class CBaseKeyConstants : public KeyConstants {
uint32_t bip44CoinType;
std::vector<unsigned char> base58Prefixes[KeyConstants::MAX_BASE58_TYPES];
std::string bech32HRPs[KeyConstants::MAX_BECH32_TYPES];
std::string bech32mHRPs[KeyConstants::MAX_BECH32M_TYPES];

std::string NetworkIDString() const { return strNetworkID; }
uint32_t BIP44CoinType() const { return bip44CoinType; }
const std::vector<unsigned char>& Base58Prefix(Base58Type type) const { return base58Prefixes[type]; }
const std::string& Bech32HRP(Bech32Type type) const { return bech32HRPs[type]; }
const std::string& Bech32mHRP(Bech32mType type) const { return bech32mHRPs[type]; }
};

#endif // ZCASH_KEY_CONSTANTS_H
4 changes: 2 additions & 2 deletions src/key_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -377,10 +377,10 @@ std::string KeyIO::EncodeTexAddress(const CKeyID& p2pkhAddr) const
// ConvertBits requires unsigned char, but CDataStream uses char
std::vector<unsigned char> seraddr(ss.begin(), ss.end());
std::vector<unsigned char> data;
// See calculation comment below
// See calculation comment above
data.reserve((seraddr.size() * 8 + 4) / 5);
ConvertBits<8, 5, true>([&](unsigned char c) { data.push_back(c); }, seraddr.begin(), seraddr.end());
return bech32::Encode(bech32::Encoding::BECH32M, keyConstants.Bech32HRP(KeyConstants::TEX_ADDRESS), data);
return bech32::Encode(bech32::Encoding::BECH32M, keyConstants.Bech32mHRP(KeyConstants::TEX_ADDRESS), data);
}

template<typename T1, typename T2>
Expand Down
2 changes: 1 addition & 1 deletion src/rpc/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ static const CRPCConvertTable rpcCvtTable =
{ "z_exportkey", {{s}, {}} },
{ "z_exportviewingkey", {{s}, {}} },
// rpcwallet
{ "converttex", {{s}, {}} },
{ "z_converttex", {{s}, {}} },
{ "getnewaddress", {{}, {s}} },
{ "getrawchangeaddress", {{}, {}} },
{ "sendtoaddress", {{s, o}, {s, s, o}} },
Expand Down
8 changes: 4 additions & 4 deletions src/wallet/rpcwallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,11 +215,11 @@ UniValue getnewaddress(const UniValue& params, bool fHelp)
return keyIO.EncodeDestination(keyID);
}

UniValue converttex(const UniValue& params, bool fHelp)
UniValue z_converttex(const UniValue& params, bool fHelp)
{
if (fHelp || params.size() < 1 || params.size() > 1)
throw runtime_error(
"converttex ( \"transparentaddress\" )\n"
"z_converttex ( \"transparentaddress\" )\n"
"\nConverts a transparent Zcash address to a TEX address.\n"

"\nArguments:\n"
Expand All @@ -229,7 +229,7 @@ UniValue converttex(const UniValue& params, bool fHelp)
"\"texaddress\" (string) The converted ZIP 320 (TEX) address\n"

"\nExamples:\n"
+ HelpExampleCli("converttex", "\"t1M72Sfpbz1BPpXFHz9m3CdqATR44Jvaydd\"")
+ HelpExampleCli("z_converttex", "\"t1M72Sfpbz1BPpXFHz9m3CdqATR44Jvaydd\"")
);

KeyIO keyIO(Params());
Expand Down Expand Up @@ -5994,7 +5994,7 @@ static const CRPCCommand commands[] =
{ "wallet", "dumpprivkey", &dumpprivkey, true },
{ "hidden", "dumpwallet", &dumpwallet, true },
{ "wallet", "encryptwallet", &encryptwallet, true },
{ "wallet", "converttex", &converttex, true },
{ "wallet", "z_converttex", &z_converttex, true },
{ "wallet", "getbalance", &getbalance, false },
{ "wallet", "getnewaddress", &getnewaddress, true },
{ "wallet", "getrawchangeaddress", &getrawchangeaddress, true },
Expand Down

0 comments on commit 069ed75

Please sign in to comment.