mirror of
https://github.com/kvazar-network/kevacoin.git
synced 2025-03-12 13:41:52 +00:00
Base58 encoding for namespace (prefix 2, to be fixed to N)
Segwit P2SH-P2WPKH. redeemScript = 0x0014{20-byte keyhash} scriptPubKey = OP_HASH160 hash160(redeemScript) OP_EQUAL
This commit is contained in:
parent
760b8b838d
commit
8292712a86
@ -70,7 +70,7 @@ bool Solver(const CScript& scriptPubKey, txnouttype& typeRet, std::vector<std::v
|
|||||||
|
|
||||||
int witnessversion;
|
int witnessversion;
|
||||||
std::vector<unsigned char> witnessprogram;
|
std::vector<unsigned char> witnessprogram;
|
||||||
if (scriptPubKey.IsWitnessProgram(witnessversion, witnessprogram)) {
|
if (script1.IsWitnessProgram(witnessversion, witnessprogram)) {
|
||||||
if (witnessversion == 0 && witnessprogram.size() == 20) {
|
if (witnessversion == 0 && witnessprogram.size() == 20) {
|
||||||
typeRet = TX_WITNESS_V0_KEYHASH;
|
typeRet = TX_WITNESS_V0_KEYHASH;
|
||||||
vSolutionsRet.push_back(witnessprogram);
|
vSolutionsRet.push_back(witnessprogram);
|
||||||
|
@ -21,7 +21,7 @@
|
|||||||
|
|
||||||
#include <univalue.h>
|
#include <univalue.h>
|
||||||
|
|
||||||
const unsigned char NAMESPACE_PREFIX = 0x35; // N
|
const unsigned char NAMESPACE_PREFIX = 21; // 2 in base58
|
||||||
|
|
||||||
|
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
@ -72,13 +72,17 @@ UniValue keva_namespace(const JSONRPCRequest& request)
|
|||||||
CKeyID keyId = pubKey.GetID();
|
CKeyID keyId = pubKey.GetID();
|
||||||
|
|
||||||
// The namespace name is: Hash160(Hash160(keyId) || displayName)
|
// The namespace name is: Hash160(Hash160(keyId) || displayName)
|
||||||
|
// JWU TODO: double check this! How can node verify this!!!???
|
||||||
valtype toHash = ToByteVector(Hash160(ToByteVector(keyId)));
|
valtype toHash = ToByteVector(Hash160(ToByteVector(keyId)));
|
||||||
toHash.insert(toHash.end(), displayName.begin(), displayName.end());
|
toHash.insert(toHash.end(), displayName.begin(), displayName.end());
|
||||||
valtype namespaceHashVal = ToByteVector(Hash160(toHash));
|
valtype namespaceHashVal = ToByteVector(Hash160(toHash));
|
||||||
namespaceHashVal.insert(namespaceHashVal.begin(), NAMESPACE_PREFIX); // Append N
|
namespaceHashVal.insert(namespaceHashVal.begin(), NAMESPACE_PREFIX);
|
||||||
const std::string namespaceHash = EncodeBase64(ValtypeToString(namespaceHashVal));
|
const std::string namespaceHash = EncodeBase58(namespaceHashVal);
|
||||||
|
|
||||||
const CScript addrName = GetScriptForDestination(keyId);
|
//const CScript addrName = GetScriptForDestination(keyId);
|
||||||
|
CScript redeemScript = GetScriptForDestination(WitnessV0KeyHash(keyId));
|
||||||
|
CScriptID scriptHash = CScriptID(redeemScript);
|
||||||
|
CScript addrName = GetScriptForDestination(scriptHash);
|
||||||
const CScript newScript = CKevaScript::buildKevaNamespace(addrName, namespaceHashVal, displayName);
|
const CScript newScript = CKevaScript::buildKevaNamespace(addrName, namespaceHashVal, displayName);
|
||||||
|
|
||||||
CCoinControl coinControl;
|
CCoinControl coinControl;
|
||||||
@ -158,7 +162,7 @@ UniValue keva_list_namespaces(const JSONRPCRequest& request)
|
|||||||
}
|
}
|
||||||
|
|
||||||
const valtype nameSpace = kevaOp.getOpNamespace();
|
const valtype nameSpace = kevaOp.getOpNamespace();
|
||||||
const std::string nameSpaceStr = EncodeBase64(ValtypeToString(nameSpace));
|
const std::string nameSpaceStr = EncodeBase58(nameSpace);
|
||||||
const CBlockIndex* pindex;
|
const CBlockIndex* pindex;
|
||||||
const int depth = tx.GetDepthInMainChain(pindex);
|
const int depth = tx.GetDepthInMainChain(pindex);
|
||||||
if (depth <= 0) {
|
if (depth <= 0) {
|
||||||
@ -212,8 +216,11 @@ UniValue keva_put(const JSONRPCRequest& request)
|
|||||||
|
|
||||||
ObserveSafeMode ();
|
ObserveSafeMode ();
|
||||||
|
|
||||||
const std::string namespaceStr = request.params[0].get_str ();
|
const std::string namespaceStr = request.params[0].get_str();
|
||||||
const valtype nameSpace = ValtypeFromString(DecodeBase64(namespaceStr));
|
valtype nameSpace;
|
||||||
|
if (!DecodeBase58(namespaceStr, nameSpace)) {
|
||||||
|
throw JSONRPCError (RPC_INVALID_PARAMETER, "failed to decode namespace");
|
||||||
|
}
|
||||||
if (nameSpace.size () > MAX_NAMESPACE_LENGTH)
|
if (nameSpace.size () > MAX_NAMESPACE_LENGTH)
|
||||||
throw JSONRPCError (RPC_INVALID_PARAMETER, "the namespace is too long");
|
throw JSONRPCError (RPC_INVALID_PARAMETER, "the namespace is too long");
|
||||||
|
|
||||||
@ -307,7 +314,10 @@ UniValue keva_get(const JSONRPCRequest& request)
|
|||||||
ObserveSafeMode ();
|
ObserveSafeMode ();
|
||||||
|
|
||||||
const std::string namespaceStr = request.params[0].get_str ();
|
const std::string namespaceStr = request.params[0].get_str ();
|
||||||
const valtype nameSpace = ValtypeFromString(DecodeBase64(namespaceStr));
|
valtype nameSpace;
|
||||||
|
if (!DecodeBase58(namespaceStr, nameSpace)) {
|
||||||
|
throw JSONRPCError (RPC_INVALID_PARAMETER, "failed to decode namespace");
|
||||||
|
}
|
||||||
if (nameSpace.size () > MAX_NAMESPACE_LENGTH)
|
if (nameSpace.size () > MAX_NAMESPACE_LENGTH)
|
||||||
throw JSONRPCError (RPC_INVALID_PARAMETER, "the namespace is too long");
|
throw JSONRPCError (RPC_INVALID_PARAMETER, "the namespace is too long");
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user