mirror of
https://github.com/kvazar-network/kevacoin.git
synced 2025-01-13 16:48:08 +00:00
Changed HasNamespace to GetNamespace. Fixed BackedView error.
Started working on keva_put.
This commit is contained in:
parent
ef2c2789f5
commit
45fecd334e
@ -10,7 +10,7 @@
|
||||
bool CCoinsView::GetCoin(const COutPoint &outpoint, Coin &coin) const { return false; }
|
||||
uint256 CCoinsView::GetBestBlock() const { return uint256(); }
|
||||
std::vector<uint256> CCoinsView::GetHeadBlocks() const { return std::vector<uint256>(); }
|
||||
bool CCoinsView::HasNamespace(const valtype &nameSpace) const { return false; }
|
||||
bool CCoinsView::GetNamespace(const valtype &nameSpace, CKevaData &data) const { return false; }
|
||||
bool CCoinsView::GetName(const valtype &nameSpace, const valtype &key, CKevaData &data) const { return false; }
|
||||
bool CCoinsView::GetNamesForHeight(unsigned nHeight, std::set<valtype>& names) const { return false; }
|
||||
CNameIterator* CCoinsView::IterateNames() const { assert (false); }
|
||||
@ -29,9 +29,15 @@ bool CCoinsViewBacked::GetCoin(const COutPoint &outpoint, Coin &coin) const { re
|
||||
bool CCoinsViewBacked::HaveCoin(const COutPoint &outpoint) const { return base->HaveCoin(outpoint); }
|
||||
uint256 CCoinsViewBacked::GetBestBlock() const { return base->GetBestBlock(); }
|
||||
std::vector<uint256> CCoinsViewBacked::GetHeadBlocks() const { return base->GetHeadBlocks(); }
|
||||
bool CCoinsViewBacked::HasNamespace(const valtype &nameSpace) const { return false; }
|
||||
bool CCoinsViewBacked::GetName(const valtype &nameSpace, const valtype &key, CKevaData &data) const { return false; }
|
||||
bool CCoinsViewBacked::GetNamesForHeight(unsigned nHeight, std::set<valtype>& names) const { return false; }
|
||||
bool CCoinsViewBacked::GetNamespace(const valtype &nameSpace, CKevaData &data) const {
|
||||
return base->GetNamespace(nameSpace, data);
|
||||
}
|
||||
bool CCoinsViewBacked::GetName(const valtype &nameSpace, const valtype &key, CKevaData &data) const {
|
||||
return base->GetName(nameSpace, key, data);
|
||||
}
|
||||
bool CCoinsViewBacked::GetNamesForHeight(unsigned nHeight, std::set<valtype>& names) const {
|
||||
return base->GetNamesForHeight(nHeight, names);
|
||||
}
|
||||
CNameIterator* CCoinsViewBacked::IterateNames() const { return base->IterateNames(); }
|
||||
void CCoinsViewBacked::SetBackend(CCoinsView &viewIn) { base = &viewIn; }
|
||||
bool CCoinsViewBacked::BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlock, const CKevaCache &names) {
|
||||
@ -154,8 +160,11 @@ void CCoinsViewCache::SetBestBlock(const uint256 &hashBlockIn) {
|
||||
hashBlock = hashBlockIn;
|
||||
}
|
||||
|
||||
bool CCoinsViewCache::HasNamespace(const valtype &nameSpace) const {
|
||||
return cacheNames.hasNamespace(nameSpace);
|
||||
bool CCoinsViewCache::GetNamespace(const valtype &nameSpace, CKevaData &data) const {
|
||||
if (cacheNames.GetNamespace(nameSpace, data)) {
|
||||
return true;
|
||||
}
|
||||
return base->GetNamespace(nameSpace, data);
|
||||
}
|
||||
|
||||
bool CCoinsViewCache::GetName(const valtype &nameSpace, const valtype &key, CKevaData &data) const {
|
||||
|
@ -165,7 +165,7 @@ public:
|
||||
virtual std::vector<uint256> GetHeadBlocks() const;
|
||||
|
||||
// Check if a namespace exists.
|
||||
virtual bool HasNamespace(const valtype& nameSpace) const;
|
||||
virtual bool GetNamespace(const valtype& nameSpace, CKevaData& data) const;
|
||||
|
||||
// Get a name (if it exists)
|
||||
virtual bool GetName(const valtype& nameSpace, const valtype& key, CKevaData& data) const;
|
||||
@ -206,7 +206,7 @@ public:
|
||||
bool HaveCoin(const COutPoint &outpoint) const override;
|
||||
uint256 GetBestBlock() const override;
|
||||
std::vector<uint256> GetHeadBlocks() const override;
|
||||
bool HasNamespace(const valtype& nameSpace) const override;
|
||||
bool GetNamespace(const valtype& nameSpace, CKevaData& data) const override;
|
||||
bool GetName(const valtype& nameSpace, const valtype& key, CKevaData& data) const override;
|
||||
bool GetNamesForHeight(unsigned nHeight, std::set<valtype>& names) const override;
|
||||
CNameIterator* IterateNames() const override;
|
||||
@ -248,8 +248,8 @@ public:
|
||||
bool HaveCoin(const COutPoint &outpoint) const override;
|
||||
uint256 GetBestBlock() const override;
|
||||
void SetBestBlock(const uint256 &hashBlock);
|
||||
bool HasNamespace(const valtype &nameSpace) const override;
|
||||
bool GetName(const valtype &nameSpace, const valtype &key, CKevaData &data) const override;
|
||||
bool GetNamespace(const valtype &nameSpace, CKevaData& data) const override;
|
||||
bool GetName(const valtype &nameSpace, const valtype &key, CKevaData& data) const override;
|
||||
bool GetNamesForHeight(unsigned nHeight, std::set<valtype>& names) const override;
|
||||
CNameIterator* IterateNames() const override;
|
||||
bool BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlock, const CKevaCache &names) override;
|
||||
|
@ -194,10 +194,10 @@ CKevaCache::get(const valtype& nameSpace, const valtype& key, CKevaData& data) c
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CKevaCache::hasNamespace(const valtype& nameSpace) const
|
||||
bool
|
||||
CKevaCache::GetNamespace(const valtype& nameSpace, CKevaData& data) const
|
||||
{
|
||||
auto ni = namespaces.find(nameSpace);
|
||||
return (ni != namespaces.end());
|
||||
return get(nameSpace, ValtypeFromString(CKevaScript::KEVA_DISPLAY_NAME_KEY), data);
|
||||
}
|
||||
|
||||
void
|
||||
@ -215,8 +215,6 @@ CKevaCache::set(const valtype& nameSpace, const valtype& key, const CKevaData& d
|
||||
ei->second = data;
|
||||
else
|
||||
entries.insert (std::make_pair(name, data));
|
||||
|
||||
namespaces.insert(nameSpace);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -379,7 +379,6 @@ public:
|
||||
* by the unit tests.
|
||||
*/
|
||||
typedef std::map<std::tuple<valtype, valtype>, CKevaData, NameComparator> EntryMap;
|
||||
typedef std::set<valtype> NamespaceSet;
|
||||
|
||||
private:
|
||||
|
||||
@ -387,8 +386,6 @@ private:
|
||||
EntryMap entries;
|
||||
/** Deleted names. */
|
||||
std::set<valtype> deleted;
|
||||
/** Namespaces */
|
||||
NamespaceSet namespaces;
|
||||
|
||||
#if 0
|
||||
/**
|
||||
@ -455,7 +452,7 @@ public:
|
||||
in entries, and doesn't care about deleted data. */
|
||||
bool get(const valtype& nameSpace, const valtype& key, CKevaData& data) const;
|
||||
|
||||
bool hasNamespace(const valtype& nameSpace) const;
|
||||
bool GetNamespace(const valtype& nameSpace, CKevaData& data) const;
|
||||
|
||||
/* Insert (or update) a name. If it is marked as "deleted", this also
|
||||
removes the "deleted" mark. */
|
||||
|
@ -13,6 +13,7 @@
|
||||
#include <util.h>
|
||||
#include <ui_interface.h>
|
||||
#include <init.h>
|
||||
#include <script/keva.h>
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
@ -142,6 +143,10 @@ CNameIterator* CCoinsViewDB::IterateNames() const {
|
||||
return new CDbNameIterator(db);
|
||||
}
|
||||
|
||||
bool CCoinsViewDB::GetNamespace(const valtype &nameSpace, CKevaData &data) const {
|
||||
return db.Read(std::make_pair(DB_NAME, std::make_pair(nameSpace, CKevaScript::KEVA_DISPLAY_NAME_KEY)), data);
|
||||
}
|
||||
|
||||
bool CCoinsViewDB::GetName(const valtype &nameSpace, const valtype &key, CKevaData &data) const {
|
||||
return db.Read(std::make_pair(DB_NAME, std::make_pair(nameSpace, key)), data);
|
||||
}
|
||||
|
@ -76,6 +76,7 @@ public:
|
||||
bool HaveCoin(const COutPoint &outpoint) const override;
|
||||
uint256 GetBestBlock() const override;
|
||||
std::vector<uint256> GetHeadBlocks() const override;
|
||||
bool GetNamespace(const valtype &nameSpace, CKevaData &data) const override;
|
||||
bool GetName(const valtype &nameSpace, const valtype &key, CKevaData &data) const override;
|
||||
bool GetNamesForHeight(unsigned nHeight, std::set<valtype>& names) const override;
|
||||
CNameIterator* IterateNames() const override;
|
||||
|
@ -138,11 +138,6 @@ UniValue keva_put(const JSONRPCRequest& request)
|
||||
if (value.size () > MAX_VALUE_LENGTH)
|
||||
throw JSONRPCError (RPC_INVALID_PARAMETER, "the value is too long");
|
||||
|
||||
bool createNamespace = false;
|
||||
if (!request.params[3].isNull()) {
|
||||
createNamespace = request.params[3].get_bool();
|
||||
}
|
||||
|
||||
/* Reject updates to a name for which the mempool already has
|
||||
a pending update. This is not a hard rule enforced by network
|
||||
rules, but it is necessary with the current mempool implementation. */
|
||||
@ -157,52 +152,39 @@ UniValue keva_put(const JSONRPCRequest& request)
|
||||
CKevaData oldData;
|
||||
{
|
||||
LOCK (cs_main);
|
||||
if (!pcoinsTip->HasNamespace(nameSpace)) {
|
||||
if (!pcoinsTip->GetNamespace(nameSpace, oldData)) {
|
||||
throw JSONRPCError (RPC_TRANSACTION_ERROR,
|
||||
"this name can not be updated");
|
||||
}
|
||||
}
|
||||
|
||||
const COutPoint outp = oldData.getUpdateOutpoint ();
|
||||
const COutPoint outp = oldData.getUpdateOutpoint();
|
||||
const CTxIn txIn(outp);
|
||||
|
||||
/* No more locking required, similarly to name_new. */
|
||||
|
||||
EnsureWalletIsUnlocked (pwallet);
|
||||
EnsureWalletIsUnlocked(pwallet);
|
||||
|
||||
CReserveKey keyName(pwallet);
|
||||
CPubKey pubKeyReserve;
|
||||
const bool ok = keyName.GetReservedKey (pubKeyReserve, true);
|
||||
assert (ok);
|
||||
const bool ok = keyName.GetReservedKey(pubKeyReserve, true);
|
||||
assert(ok);
|
||||
bool usedKey = false;
|
||||
|
||||
CScript addrName;
|
||||
if (request.params.size () == 3)
|
||||
{
|
||||
keyName.ReturnKey ();
|
||||
const CTxDestination dest
|
||||
= DecodeDestination (request.params[2].get_str ());
|
||||
if (!IsValidDestination (dest))
|
||||
throw JSONRPCError (RPC_INVALID_ADDRESS_OR_KEY, "invalid address");
|
||||
usedKey = true;
|
||||
addrName = GetScriptForDestination(pubKeyReserve.GetID());
|
||||
|
||||
addrName = GetScriptForDestination (dest);
|
||||
}
|
||||
else
|
||||
{
|
||||
usedKey = true;
|
||||
addrName = GetScriptForDestination (pubKeyReserve.GetID ());
|
||||
}
|
||||
|
||||
const CScript nameScript
|
||||
= CKevaScript::buildKevaPut(addrName, nameSpace, key, value);
|
||||
const CScript kevaScript = CKevaScript::buildKevaPut(addrName, nameSpace, key, value);
|
||||
|
||||
CCoinControl coinControl;
|
||||
CWalletTx wtx;
|
||||
SendMoneyToScript(pwallet, nameScript, &txIn,
|
||||
SendMoneyToScript(pwallet, kevaScript, &txIn,
|
||||
KEVA_LOCKED_AMOUNT, false, wtx, coinControl);
|
||||
|
||||
if (usedKey)
|
||||
if (usedKey) {
|
||||
keyName.KeepKey ();
|
||||
}
|
||||
|
||||
return wtx.GetHash ().GetHex ();
|
||||
return wtx.GetHash().GetHex();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user