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