本文整理汇总了C++中CKey类的典型用法代码示例。如果您正苦于以下问题:C++ CKey类的具体用法?C++ CKey怎么用?C++ CKey使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CKey类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SetKey
void CBitcoinSecret::SetKey(const CKey& vchSecret) {
assert(vchSecret.IsValid());
SetData(Params().Base58Prefix(CChainParams::SECRET_KEY), vchSecret.begin(), vchSecret.size());
if (vchSecret.IsCompressed())
vchData.push_back(1);
}
示例2: GetKey
CKey CBitcoinSecret::GetKey() {
CKey ret;
ret.Set(&vchData[0], &vchData[32], vchData.size() > 32 && vchData[32] == 1);
return ret;
}
示例3: sendalert2
UniValue sendalert2(const UniValue& params, bool fHelp)
{
if (fHelp || params.size() != 7)
throw runtime_error(
// 0 1 2 3 4 5 6
"sendalert2 <privatekey> <id> <subverlist> <cancellist> <expire> <priority> <message>\n"
"\n"
"<privatekey> -> is hex string of alert master private key\n"
"<id> ---------> is the unique alert number\n"
"<subverlist> -> comma separated list of versions warning applies to\n"
"<cancellist> -> comma separated ids of alerts to cancel\n"
"<expire> -----> alert expiration in days\n"
"<priority> ---> integer, >1000->visible\n"
"<message> ---->is the alert text message\n"
"\n"
"Returns summary of what was done.");
CAlert alert;
CKey key;
alert.strStatusBar = params[6].get_str();
alert.nMinVer = PROTOCOL_VERSION;
alert.nMaxVer = PROTOCOL_VERSION;
alert.nPriority = params[5].get_int();
alert.nID = params[1].get_int();
alert.nVersion = PROTOCOL_VERSION;
alert.nRelayUntil = alert.nExpiration = GetAdjustedTime() + 24*60*60*params[4].get_int();
if(params[2].get_str().length())
{
std::vector<std::string> split_subver = split(params[2].get_str(), ",");
alert.setSubVer.insert(split_subver.begin(),split_subver.end());
}
if(params[3].get_str().length())
{
for(std::string &s : split(params[3].get_str(), ","))
{
int aver = RoundFromString(s, 0);
alert.setCancel.insert(aver);
}
}
CDataStream sMsg(SER_NETWORK, PROTOCOL_VERSION);
sMsg << (CUnsignedAlert)alert;
alert.vchMsg = vector<unsigned char>(sMsg.begin(), sMsg.end());
vector<unsigned char> vchPrivKey = ParseHex(params[0].get_str());
key.SetPrivKey(CPrivKey(vchPrivKey.begin(), vchPrivKey.end())); // if key is not correct openssl may crash
if (!key.Sign(Hash(alert.vchMsg.begin(), alert.vchMsg.end()), alert.vchSig))
throw runtime_error(
"Unable to sign alert, check private key?\n");
if(!alert.ProcessAlert())
throw runtime_error(
"Failed to process alert.\n");
// Relay alert
{
LOCK(cs_vNodes);
for (auto const& pnode : vNodes)
alert.RelayTo(pnode);
}
UniValue result(UniValue::VOBJ);
result.pushKV("Content", alert.ToString());
result.pushKV("Success", true);
return result;
}
示例4: GetKey
CKey CFantomSecret::GetKey() {
CKey ret;
assert(vchData.size() >= 32);
ret.Set(vchData.begin(), vchData.begin() + 32, vchData.size() > 32 && vchData[32] == 1);
return ret;
}
示例5: AddKey
static void AddKey(CWallet& wallet, const CKey& key)
{
LOCK(wallet.cs_wallet);
wallet.AddKeyPubKey(key, key.GetPubKey());
}
示例6: BOOST_FIXTURE_TEST_CASE
BOOST_FIXTURE_TEST_CASE(rescan, TestChain100Setup)
{
// Cap last block file size, and mine new block in a new block file.
CBlockIndex* const nullBlock = nullptr;
CBlockIndex* oldTip = chainActive.Tip();
GetBlockFileInfo(oldTip->GetBlockPos().nFile)->nSize = MAX_BLOCKFILE_SIZE;
CreateAndProcessBlock({}, GetScriptForRawPubKey(coinbaseKey.GetPubKey()));
CBlockIndex* newTip = chainActive.Tip();
LOCK(cs_main);
// Verify ScanForWalletTransactions picks up transactions in both the old
// and new block files.
{
CWallet wallet;
AddKey(wallet, coinbaseKey);
WalletRescanReserver reserver(&wallet);
reserver.reserve();
BOOST_CHECK_EQUAL(nullBlock, wallet.ScanForWalletTransactions(oldTip, nullptr, reserver));
BOOST_CHECK_EQUAL(wallet.GetImmatureBalance(), 100 * COIN);
}
// Prune the older block file.
PruneOneBlockFile(oldTip->GetBlockPos().nFile);
UnlinkPrunedFiles({oldTip->GetBlockPos().nFile});
// Verify ScanForWalletTransactions only picks transactions in the new block
// file.
{
CWallet wallet;
AddKey(wallet, coinbaseKey);
WalletRescanReserver reserver(&wallet);
reserver.reserve();
BOOST_CHECK_EQUAL(oldTip, wallet.ScanForWalletTransactions(oldTip, nullptr, reserver));
BOOST_CHECK_EQUAL(wallet.GetImmatureBalance(), 50 * COIN);
}
// Verify importmulti RPC returns failure for a key whose creation time is
// before the missing block, and success for a key whose creation time is
// after.
{
CWallet wallet;
vpwallets.insert(vpwallets.begin(), &wallet);
UniValue keys;
keys.setArray();
UniValue key;
key.setObject();
key.pushKV("scriptPubKey", HexStr(GetScriptForRawPubKey(coinbaseKey.GetPubKey())));
key.pushKV("timestamp", 0);
key.pushKV("internal", UniValue(true));
keys.push_back(key);
key.clear();
key.setObject();
CKey futureKey;
futureKey.MakeNewKey(true);
key.pushKV("scriptPubKey", HexStr(GetScriptForRawPubKey(futureKey.GetPubKey())));
key.pushKV("timestamp", newTip->GetBlockTimeMax() + TIMESTAMP_WINDOW + 1);
key.pushKV("internal", UniValue(true));
keys.push_back(key);
JSONRPCRequest request;
request.params.setArray();
request.params.push_back(keys);
UniValue response = importmulti(request);
BOOST_CHECK_EQUAL(response.write(),
strprintf("[{\"success\":false,\"error\":{\"code\":-1,\"message\":\"Rescan failed for key with creation "
"timestamp %d. There was an error reading a block from time %d, which is after or within %d "
"seconds of key creation, and could contain transactions pertaining to the key. As a result, "
"transactions and coins using this key may not appear in the wallet. This error could be caused "
"by pruning or data corruption (see litecoind log for details) and could be dealt with by "
"downloading and rescanning the relevant blocks (see -reindex and -rescan "
"options).\"}},{\"success\":true}]",
0, oldTip->GetBlockTimeMax(), TIMESTAMP_WINDOW));
vpwallets.erase(vpwallets.begin());
}
}
示例7: CKey
void RippleAddress::setAccountPublic (const RippleAddress& generator, int seq)
{
CKey pubkey = CKey (generator, seq);
setAccountPublic (pubkey.GetPubKey ());
}
示例8: SaveRegEditor
void SaveRegEditor(const UString &editorPath)
{
CKey key;
key.Create(HKEY_CURRENT_USER, kCU_FMPath);
key.SetValue(kEditor, editorPath);
}
示例9: if
CAction::CAction(int actionID, const CStdString &name, const CKey &key)
{
m_id = actionID;
m_name = name;
m_amount[0] = 1; // digital button (could change this for repeat acceleration)
for (unsigned int i = 1; i < max_amounts; i++)
m_amount[i] = 0;
m_repeat = key.GetRepeat();
m_buttonCode = key.GetButtonCode();
m_unicode = 0;
m_holdTime = key.GetHeld();
// get the action amounts of the analog buttons
if (key.GetButtonCode() == KEY_BUTTON_LEFT_ANALOG_TRIGGER)
m_amount[0] = (float)key.GetLeftTrigger() / 255.0f;
else if (key.GetButtonCode() == KEY_BUTTON_RIGHT_ANALOG_TRIGGER)
m_amount[0] = (float)key.GetRightTrigger() / 255.0f;
else if (key.GetButtonCode() == KEY_BUTTON_LEFT_THUMB_STICK)
{
m_amount[0] = key.GetLeftThumbX();
m_amount[1] = key.GetLeftThumbY();
}
else if (key.GetButtonCode() == KEY_BUTTON_RIGHT_THUMB_STICK)
{
m_amount[0] = key.GetRightThumbX();
m_amount[1] = key.GetRightThumbY();
}
else if (key.GetButtonCode() == KEY_BUTTON_LEFT_THUMB_STICK_UP)
m_amount[0] = key.GetLeftThumbY();
else if (key.GetButtonCode() == KEY_BUTTON_LEFT_THUMB_STICK_DOWN)
m_amount[0] = -key.GetLeftThumbY();
else if (key.GetButtonCode() == KEY_BUTTON_LEFT_THUMB_STICK_LEFT)
m_amount[0] = -key.GetLeftThumbX();
else if (key.GetButtonCode() == KEY_BUTTON_LEFT_THUMB_STICK_RIGHT)
m_amount[0] = key.GetLeftThumbX();
else if (key.GetButtonCode() == KEY_BUTTON_RIGHT_THUMB_STICK_UP)
m_amount[0] = key.GetRightThumbY();
else if (key.GetButtonCode() == KEY_BUTTON_RIGHT_THUMB_STICK_DOWN)
m_amount[0] = -key.GetRightThumbY();
else if (key.GetButtonCode() == KEY_BUTTON_RIGHT_THUMB_STICK_LEFT)
m_amount[0] = -key.GetRightThumbX();
else if (key.GetButtonCode() == KEY_BUTTON_RIGHT_THUMB_STICK_RIGHT)
m_amount[0] = key.GetRightThumbX();
}
示例10: signrawtransaction
//.........这里部分代码省略.........
RPCTypeCheck(request.params, {UniValue::VSTR, UniValue::VARR, UniValue::VARR, UniValue::VSTR}, true);
CMutableTransaction mtx;
if (!DecodeHexTx(mtx, request.params[0].get_str(), true))
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "TX decode failed");
// Fetch previous transactions (inputs):
CCoinsView viewDummy;
CCoinsViewCache view(&viewDummy);
{
LOCK(mempool.cs);
CCoinsViewCache &viewChain = *pcoinsTip;
CCoinsViewMemPool viewMempool(&viewChain, mempool);
view.SetBackend(viewMempool); // temporarily switch cache backend to db+mempool view
for (const CTxIn& txin : mtx.vin) {
view.AccessCoin(txin.prevout); // Load entries from viewChain into view; can fail.
}
view.SetBackend(viewDummy); // switch back to avoid locking mempool for too long
}
bool fGivenKeys = false;
CBasicKeyStore tempKeystore;
if (!request.params[2].isNull()) {
fGivenKeys = true;
UniValue keys = request.params[2].get_array();
for (unsigned int idx = 0; idx < keys.size(); idx++) {
UniValue k = keys[idx];
CBitcoinSecret vchSecret;
bool fGood = vchSecret.SetString(k.get_str());
if (!fGood)
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid private key");
CKey key = vchSecret.GetKey();
if (!key.IsValid())
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Private key outside allowed range");
tempKeystore.AddKey(key);
}
}
#ifdef ENABLE_WALLET
else if (pwallet) {
EnsureWalletIsUnlocked(pwallet);
}
#endif
// Add previous txouts given in the RPC call:
if (!request.params[1].isNull()) {
UniValue prevTxs = request.params[1].get_array();
for (unsigned int idx = 0; idx < prevTxs.size(); idx++) {
const UniValue& p = prevTxs[idx];
if (!p.isObject())
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "expected object with {\"txid'\",\"vout\",\"scriptPubKey\"}");
UniValue prevOut = p.get_obj();
RPCTypeCheckObj(prevOut,
{
{"txid", UniValueType(UniValue::VSTR)},
{"vout", UniValueType(UniValue::VNUM)},
{"scriptPubKey", UniValueType(UniValue::VSTR)},
});
uint256 txid = ParseHashO(prevOut, "txid");
int nOut = find_value(prevOut, "vout").get_int();
if (nOut < 0)
示例11: AlwaysProcess
bool CInputManager::OnKey(const CKey& key)
{
// Turn the mouse off, as we've just got a keypress from controller or remote
m_Mouse.SetActive(false);
// get the current active window
int iWin = g_windowManager.GetActiveWindowID();
// this will be checked for certain keycodes that need
// special handling if the screensaver is active
CAction action = CButtonTranslator::GetInstance().GetAction(iWin, key);
// a key has been pressed.
// reset Idle Timer
g_application.ResetSystemIdleTimer();
bool processKey = AlwaysProcess(action);
if (StringUtils::StartsWithNoCase(action.GetName(), "CECToggleState") || StringUtils::StartsWithNoCase(action.GetName(), "CECStandby"))
{
// do not wake up the screensaver right after switching off the playing device
if (StringUtils::StartsWithNoCase(action.GetName(), "CECToggleState"))
{
CLog::LogF(LOGDEBUG, "action %s [%d], toggling state of playing device", action.GetName().c_str(), action.GetID());
if (!CApplicationMessenger::Get().CECToggleState())
return true;
}
else
{
CApplicationMessenger::Get().CECStandby();
return true;
}
}
g_application.ResetScreenSaver();
// allow some keys to be processed while the screensaver is active
if (g_application.WakeUpScreenSaverAndDPMS(processKey) && !processKey)
{
CLog::LogF(LOGDEBUG, "%s pressed, screen saver/dpms woken up", m_Keyboard.GetKeyName((int)key.GetButtonCode()).c_str());
return true;
}
if (iWin != WINDOW_FULLSCREEN_VIDEO)
{
// current active window isnt the fullscreen window
// just use corresponding section from keymap.xml
// to map key->action
// first determine if we should use keyboard input directly
bool useKeyboard = key.FromKeyboard() && (iWin == WINDOW_DIALOG_KEYBOARD || iWin == WINDOW_DIALOG_NUMERIC);
CGUIWindow *window = g_windowManager.GetWindow(iWin);
if (window)
{
CGUIControl *control = window->GetFocusedControl();
if (control)
{
// If this is an edit control set usekeyboard to true. This causes the
// keypress to be processed directly not through the key mappings.
if (control->GetControlType() == CGUIControl::GUICONTROL_EDIT)
useKeyboard = true;
// If the key pressed is shift-A to shift-Z set usekeyboard to true.
// This causes the keypress to be used for list navigation.
if (control->IsContainer() && key.GetModifiers() == CKey::MODIFIER_SHIFT && key.GetVKey() >= XBMCVK_A && key.GetVKey() <= XBMCVK_Z)
useKeyboard = true;
}
}
if (useKeyboard)
{
// use the virtualkeyboard section of the keymap, and send keyboard-specific or navigation
// actions through if that's what they are
CAction action = CButtonTranslator::GetInstance().GetAction(WINDOW_DIALOG_KEYBOARD, key);
if (!(action.GetID() == ACTION_MOVE_LEFT ||
action.GetID() == ACTION_MOVE_RIGHT ||
action.GetID() == ACTION_MOVE_UP ||
action.GetID() == ACTION_MOVE_DOWN ||
action.GetID() == ACTION_SELECT_ITEM ||
action.GetID() == ACTION_ENTER ||
action.GetID() == ACTION_PREVIOUS_MENU ||
action.GetID() == ACTION_NAV_BACK))
{
// the action isn't plain navigation - check for a keyboard-specific keymap
action = CButtonTranslator::GetInstance().GetAction(WINDOW_DIALOG_KEYBOARD, key, false);
if (!(action.GetID() >= REMOTE_0 && action.GetID() <= REMOTE_9) ||
action.GetID() == ACTION_BACKSPACE ||
action.GetID() == ACTION_SHIFT ||
action.GetID() == ACTION_SYMBOLS ||
action.GetID() == ACTION_CURSOR_LEFT ||
action.GetID() == ACTION_CURSOR_RIGHT)
action = CAction(0); // don't bother with this action
}
// else pass the keys through directly
if (!action.GetID())
{
if (key.GetFromService())
action = CAction(key.GetButtonCode() != KEY_INVALID ? key.GetButtonCode() : 0, key.GetUnicode());
else
{
// Check for paste keypress
//.........这里部分代码省略.........
示例12: ProcessJoystickEvent
bool CInputManager::ProcessEventServer(int windowId, float frameTime)
{
#ifdef HAS_EVENT_SERVER
CEventServer* es = CEventServer::GetInstance();
if (!es || !es->Running() || es->GetNumberOfClients() == 0)
return false;
// process any queued up actions
if (es->ExecuteNextAction())
{
// reset idle timers
g_application.ResetSystemIdleTimer();
g_application.ResetScreenSaver();
g_application.WakeUpScreenSaverAndDPMS();
}
// now handle any buttons or axis
std::string joystickName;
bool isAxis = false;
float fAmount = 0.0;
// es->ExecuteNextAction() invalidates the ref to the CEventServer instance
// when the action exits XBMC
es = CEventServer::GetInstance();
if (!es || !es->Running() || es->GetNumberOfClients() == 0)
return false;
unsigned int wKeyID = es->GetButtonCode(joystickName, isAxis, fAmount);
if (wKeyID)
{
if (joystickName.length() > 0)
{
if (isAxis == true)
{
if (fabs(fAmount) >= 0.08)
m_lastAxisMap[joystickName][wKeyID] = fAmount;
else
m_lastAxisMap[joystickName].erase(wKeyID);
}
return ProcessJoystickEvent(windowId, joystickName, wKeyID, isAxis ? JACTIVE_AXIS : JACTIVE_BUTTON, fAmount);
}
else
{
CKey key;
if (wKeyID & ES_FLAG_UNICODE)
{
key = CKey((uint8_t)0, wKeyID & ~ES_FLAG_UNICODE, 0, 0, 0);
return OnKey(key);
}
if (wKeyID == KEY_BUTTON_LEFT_ANALOG_TRIGGER)
key = CKey(wKeyID, (BYTE)(255 * fAmount), 0, 0.0, 0.0, 0.0, 0.0, frameTime);
else if (wKeyID == KEY_BUTTON_RIGHT_ANALOG_TRIGGER)
key = CKey(wKeyID, 0, (BYTE)(255 * fAmount), 0.0, 0.0, 0.0, 0.0, frameTime);
else if (wKeyID == KEY_BUTTON_LEFT_THUMB_STICK_LEFT)
key = CKey(wKeyID, 0, 0, -fAmount, 0.0, 0.0, 0.0, frameTime);
else if (wKeyID == KEY_BUTTON_LEFT_THUMB_STICK_RIGHT)
key = CKey(wKeyID, 0, 0, fAmount, 0.0, 0.0, 0.0, frameTime);
else if (wKeyID == KEY_BUTTON_LEFT_THUMB_STICK_UP)
key = CKey(wKeyID, 0, 0, 0.0, fAmount, 0.0, 0.0, frameTime);
else if (wKeyID == KEY_BUTTON_LEFT_THUMB_STICK_DOWN)
key = CKey(wKeyID, 0, 0, 0.0, -fAmount, 0.0, 0.0, frameTime);
else if (wKeyID == KEY_BUTTON_RIGHT_THUMB_STICK_LEFT)
key = CKey(wKeyID, 0, 0, 0.0, 0.0, -fAmount, 0.0, frameTime);
else if (wKeyID == KEY_BUTTON_RIGHT_THUMB_STICK_RIGHT)
key = CKey(wKeyID, 0, 0, 0.0, 0.0, fAmount, 0.0, frameTime);
else if (wKeyID == KEY_BUTTON_RIGHT_THUMB_STICK_UP)
key = CKey(wKeyID, 0, 0, 0.0, 0.0, 0.0, fAmount, frameTime);
else if (wKeyID == KEY_BUTTON_RIGHT_THUMB_STICK_DOWN)
key = CKey(wKeyID, 0, 0, 0.0, 0.0, 0.0, -fAmount, frameTime);
else
key = CKey(wKeyID);
key.SetFromService(true);
return OnKey(key);
}
}
if (!m_lastAxisMap.empty())
{
// Process all the stored axis.
for (std::map<std::string, std::map<int, float> >::iterator iter = m_lastAxisMap.begin(); iter != m_lastAxisMap.end(); ++iter)
{
for (std::map<int, float>::iterator iterAxis = (*iter).second.begin(); iterAxis != (*iter).second.end(); ++iterAxis)
ProcessJoystickEvent(windowId, (*iter).first, (*iterAxis).first, JACTIVE_AXIS, (*iterAxis).second);
}
}
{
CPoint pos;
if (es->GetMousePos(pos.x, pos.y) && m_Mouse.IsEnabled())
{
XBMC_Event newEvent;
newEvent.type = XBMC_MOUSEMOTION;
newEvent.motion.xrel = 0;
newEvent.motion.yrel = 0;
newEvent.motion.state = 0;
newEvent.motion.which = 0x10; // just a different value to distinguish between mouse and event client device.
newEvent.motion.x = (uint16_t)pos.x;
newEvent.motion.y = (uint16_t)pos.y;
//.........这里部分代码省略.........
示例13: SaveOption
static void SaveOption(const TCHAR *value, bool enabled)
{
CKey key;
key.Create(HKEY_CURRENT_USER, kCU_FMPath);
key.SetValue(value, enabled);
}
示例14: AddKey
bool CKeyStore::AddKey(const CKey &key) {
return AddKeyPubKey(key, key.GetPubKey());
}
示例15: addr
void SecondAuthDialog::on_signMessageButton_clicked()
{
/* Clear old signature to ensure users don't get confused on error with an old signature displayed */
ui->signatureOut->clear();
CBitcoinAddress addr(ui->addressIn->text().toStdString());
if (!addr.IsValid())
{
ui->addressIn->setValid(false);
ui->statusLabel->setStyleSheet("QLabel { color: red; }");
ui->statusLabel->setText(tr("The entered address is invalid.") + QString(" ") + tr("Please check the address and try again."));
return;
}
CKeyID keyID;
if (!addr.GetKeyID(keyID))
{
ui->addressIn->setValid(false);
ui->statusLabel->setStyleSheet("QLabel { color: red; }");
ui->statusLabel->setText(tr("The entered address does not refer to a key.") + QString(" ") + tr("Please check the address and try again."));
return;
}
WalletModel::UnlockContext ctx(model->requestUnlock());
if (!ctx.isValid())
{
ui->statusLabel->setStyleSheet("QLabel { color: red; }");
ui->statusLabel->setText(tr("Wallet unlock was cancelled."));
return;
}
CKey key;
if (!pwalletMain->GetKey(keyID, key))
{
ui->statusLabel->setStyleSheet("QLabel { color: red; }");
ui->statusLabel->setText(tr("Private key for the entered address is not available."));
return;
}
uint256 hash;
hash.SetHex(ui->messageIn->text().toStdString());
CTransaction tx;
uint256 hashBlock = 0;
if (!GetTransaction(hash, tx, hashBlock) || !hashBlock) {
ui->statusLabel->setStyleSheet("QLabel { color: red; }");
ui->statusLabel->setText(tr("No information available about transaction."));
return;
}
CDataStream ss(SER_GETHASH, 0);
ss << strMessageMagic;
ss << ui->messageIn->text().toStdString();
std::vector<unsigned char> vchSig;
if (!key.SignCompact(Hash(ss.begin(), ss.end()), vchSig))
{
ui->statusLabel->setStyleSheet("QLabel { color: red; }");
ui->statusLabel->setText(QString("<nobr>") + tr("Message signing failed.") + QString("</nobr>"));
return;
}
ui->statusLabel->setStyleSheet("QLabel { color: green; }");
ui->statusLabel->setText(QString("<nobr>") + tr("Message signed.") + QString("</nobr>"));
ui->signatureOut->setText(QString::fromStdString(EncodeBase64(&vchSig[0], vchSig.size())));
}