本文整理汇总了C++中CWallet::GenerateNewZKey方法的典型用法代码示例。如果您正苦于以下问题:C++ CWallet::GenerateNewZKey方法的具体用法?C++ CWallet::GenerateNewZKey怎么用?C++ CWallet::GenerateNewZKey使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CWallet
的用法示例。
在下文中一共展示了CWallet::GenerateNewZKey方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: meta
/**
* This test covers methods on CWallet
* GenerateNewZKey()
* AddZKey()
* LoadZKey()
* LoadZKeyMetadata()
*/
TEST(wallet_zkeys_tests, store_and_load_zkeys) {
SelectParams(CBaseChainParams::MAIN);
CWallet wallet;
// wallet should be empty
std::set<libzcash::PaymentAddress> addrs;
wallet.GetPaymentAddresses(addrs);
ASSERT_EQ(0, addrs.size());
// wallet should have one key
CZCPaymentAddress paymentAddress = wallet.GenerateNewZKey();
wallet.GetPaymentAddresses(addrs);
ASSERT_EQ(1, addrs.size());
// verify wallet has spending key for the address
auto addr = paymentAddress.Get();
ASSERT_TRUE(wallet.HaveSpendingKey(addr));
// manually add new spending key to wallet
auto sk = libzcash::SpendingKey::random();
ASSERT_TRUE(wallet.AddZKey(sk));
// verify wallet did add it
addr = sk.address();
ASSERT_TRUE(wallet.HaveSpendingKey(addr));
// verify spending key stored correctly
libzcash::SpendingKey keyOut;
wallet.GetSpendingKey(addr, keyOut);
ASSERT_EQ(sk, keyOut);
// verify there are two keys
wallet.GetPaymentAddresses(addrs);
ASSERT_EQ(2, addrs.size());
ASSERT_EQ(1, addrs.count(addr));
// Load a third key into the wallet
sk = libzcash::SpendingKey::random();
ASSERT_TRUE(wallet.LoadZKey(sk));
// attach metadata to this third key
addr = sk.address();
int64_t now = GetTime();
CKeyMetadata meta(now);
ASSERT_TRUE(wallet.LoadZKeyMetadata(addr, meta));
// check metadata is the same
CKeyMetadata m= wallet.mapZKeyMetadata[addr];
ASSERT_EQ(m.nCreateTime, now);
}