diff --git a/qa/rpc-tests/onboard.py b/qa/rpc-tests/onboard.py index 61c7f73589..7477aaacfc 100755 --- a/qa/rpc-tests/onboard.py +++ b/qa/rpc-tests/onboard.py @@ -180,7 +180,8 @@ def run_test (self): kycfile0_plain=self.initfile(os.path.join(self.options.tmpdir,"kycfile0_plain.dat")) self.nodes[0].readkycfile(kycfile0, kycfile0_plain) - self.nodes[0].onboarduser(kycfile0) + #Old registeraddresss script (version 0) + self.nodes[0].onboarduser(kycfile0, 0) time.sleep(5) self.nodes[0].generate(101) time.sleep(5) diff --git a/qa/rpc-tests/onboard_cit.py b/qa/rpc-tests/onboard_cit.py index ab833c9889..fa8200f611 100755 --- a/qa/rpc-tests/onboard_cit.py +++ b/qa/rpc-tests/onboard_cit.py @@ -257,7 +257,8 @@ def run_test (self): print("onboard node 0 \n") print("read kycfile0 node 0 \n") self.nodes[0].readkycfile(kycfile0, kycfile0_plain) - self.nodes[0].onboarduser(kycfile0) + #Old registeraddresss script (version 0) + self.nodes[0].onboarduser(kycfile0, 0) print("generate block \n") self.nodes[0].generate(101) print("sync all \n") diff --git a/qa/rpc-tests/onboardmanual_cit.py b/qa/rpc-tests/onboardmanual_cit.py index 8979bb2371..c5c74a3264 100755 --- a/qa/rpc-tests/onboardmanual_cit.py +++ b/qa/rpc-tests/onboardmanual_cit.py @@ -384,6 +384,41 @@ def run_test (self): self.nodes[0].generate(101) self.sync_all() + valkyc=self.nodes[0].validatekycfile(kycfile_multisig) + print(valkyc) + assert(valkyc["iswhitelisted"] == True) + + #Blacklist + try: + self.nodes[0].blacklistuser(kycfile_multisig) + except JSONRPCException as e: + print(e.error['message']) + assert(False) + + self.nodes[0].generate(101) + self.sync_all() + + valkyc=self.nodes[0].validatekycfile(kycfile_multisig) + print(valkyc) + assert(valkyc["iswhitelisted"] == False) + + #Onboard again using registeraddresss script version 0 + try: + self.nodes[0].onboarduser(kycfile_multisig, 0) + except JSONRPCException as e: + print(e.error['message']) + assert(False) + + self.nodes[0].generate(101) + self.sync_all() + + valkyc=self.nodes[0].validatekycfile(kycfile_multisig) + print(valkyc) + assert(valkyc["iswhitelisted"] == True) + + os.remove(kycfile_multisig) + + #Test invalid parameters try: @@ -438,12 +473,6 @@ def run_test (self): assert("Invalid pubkey in multisiglist: " in message) - valkyc=self.nodes[0].validatekycfile(kycfile_multisig) - print(valkyc) - assert(valkyc["iswhitelisted"] == True) - - os.remove(kycfile_multisig) - onboardAddress1=self.nodes[1].validateaddress(self.nodes[1].getnewaddress()) onboardAddress2=self.nodes[1].validateaddress(self.nodes[1].getnewaddress()) onboardAddress3=self.nodes[1].validateaddress(self.nodes[1].getnewaddress()) diff --git a/src/policy/kycfile.cpp b/src/policy/kycfile.cpp index 31139947e0..a6a2e2f8e3 100644 --- a/src/policy/kycfile.cpp +++ b/src/policy/kycfile.cpp @@ -329,7 +329,7 @@ bool CKYCFile::is_empty(){ return true; } -bool CKYCFile::getOnboardingScript(CScript& script, bool fBlacklist){ +bool CKYCFile::getOnboardingScript(CScript& script, bool fBlacklist, int nVersion){ uint256 contract = chainActive.Tip() ? chainActive.Tip()->hashContract : GetContractHash(); if(!contract.IsNull() && Params().ContractInKYCFile()){ if(!_fContractHash_parsed) @@ -349,6 +349,7 @@ bool CKYCFile::getOnboardingScript(CScript& script, bool fBlacklist){ COnboardingScript obScript; + if(nVersion >=0) obScript.ScriptVersion(nVersion); obScript.SetDeregister(fBlacklist); // Lookup the KYC public key assigned to the user from the whitelist diff --git a/src/policy/kycfile.h b/src/policy/kycfile.h index 225d7fd5f2..fae7cf1d2d 100644 --- a/src/policy/kycfile.h +++ b/src/policy/kycfile.h @@ -50,7 +50,7 @@ class CKYCFile{ const std::stringstream& getStream() const {return _decryptedStream;} - bool getOnboardingScript(CScript& script, bool fBlacklist=false); + bool getOnboardingScript(CScript& script, bool fBlacklist=false, int nVersion=-1); bool is_whitelisted(); diff --git a/src/policy/whitelist.cpp b/src/policy/whitelist.cpp index 554239b61b..db1358037d 100644 --- a/src/policy/whitelist.cpp +++ b/src/policy/whitelist.cpp @@ -346,7 +346,7 @@ bool CWhiteList::RegisterDecryptedAddresses(const txnouttype& whichType, const s void CWhiteList::add(CRegisterAddressData* d){ CTxDestination dest = d->GetDest(); - if(dest != _noDest) CPolicyList::add_sorted(dest); + if(!(dest == _noDest)) CPolicyList::add_sorted(dest); } void CWhiteList::remove(CRegisterAddressData* d){ diff --git a/src/rpc/client.cpp b/src/rpc/client.cpp index 13f425249f..6671678e80 100644 --- a/src/rpc/client.cpp +++ b/src/rpc/client.cpp @@ -31,6 +31,7 @@ class CRPCConvertParam */ static const CRPCConvertParam vRPCConvertParams[] = { + { "onboarduser", 1, "scriptversion"}, { "topupkycpubkeys", 0, "nkeys" }, { "whitelistkycpubkeys", 0, "kycpubkeys" }, { "setmocktime", 0, "timestamp" }, diff --git a/src/script/registeraddressscript.cpp b/src/script/registeraddressscript.cpp index 39cdee4319..3eadef3034 100644 --- a/src/script/registeraddressscript.cpp +++ b/src/script/registeraddressscript.cpp @@ -119,10 +119,11 @@ bool CRegisterAddressScript::Append(const pubKeyPair& p){ if(_whitelistType != RA_PUBLICKEY && _whitelistType != RA_ONBOARDING) return false; - if(!Params().ContractInTx()){ - if(!Consensus::CheckValidTweakedAddress(p.first, p.second)) + if(!Params().ContractInTx() &! Consensus::CheckValidTweakedAddress(p.first, p.second)) return false; + if(!Params().ContractInTx() || _nScriptVersion == 0){ + CBitcoinAddress addr(p.first); if(!addr.IsValid()) @@ -169,11 +170,11 @@ bool CRegisterAddressScript::Append(const uint8_t nMultisig, const CTxDestinatio if(_whitelistType != RA_MULTISIG && _whitelistType != RA_ONBOARDING) return false; - if (!Params().ContractInTx()){ - - if(!(Consensus::CheckValidTweakedAddress(keyID, keys, nMultisig))) + if(!Params().ContractInTx() &! Consensus::CheckValidTweakedAddress(keyID, keys, nMultisig)) return false; + if (!Params().ContractInTx() || _nScriptVersion == 0){ + unsigned int nAppend=0; if(Append(AddrType::MULTI)) ++nAppend; AppendChar((unsigned char)nMultisig); diff --git a/src/script/registeraddressscript.h b/src/script/registeraddressscript.h index 5efc28a56b..2a19dc15b1 100644 --- a/src/script/registeraddressscript.h +++ b/src/script/registeraddressscript.h @@ -58,11 +58,11 @@ class CRegisterAddressScript { return _nScriptVersion; } - void AppendChar(const unsigned char& c){ _payload.push_back(c); } + std::size_t getPayloadSize() { return _payload.size(); } virtual void clear(){_payload.clear(); _encrypted.clear(); ((CScript*)this)->clear();} diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index fe094d08ad..f502bf62ce 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -803,13 +803,14 @@ static void SendOnboardTx(const CScript& script, CWalletTx& wtxNew){ } UniValue onboarduser(const JSONRPCRequest& request){ - if (request.fHelp || request.params.size() != 1) + if (request.fHelp || request.params.size() < 1 || request.params.size() > 2) throw runtime_error( "onboarduser \"filename\" \n" "Read in derived keys and tweaked addresses from kyc file (see dumpkycfile, createkycfile) into the address whitelist. Assign a KYC public key to the user if using encrypted whitelist.\n" "\nArguments:\n" - "1. \"filename\" (string, required) The kyc file name\n" + "1. \"filename\" (string, required) The kyc file name\n" + "2. \"scriptversion\" (integer, optional) The registeraddress script version (default = latest)\n" "\nExamples:\n" + HelpExampleCli("onboarduser", "\"my filename\"") @@ -821,10 +822,16 @@ UniValue onboarduser(const JSONRPCRequest& request){ EnsureWalletIsUnlocked(); CKYCFile file; + file.read(request.params[0].get_str().c_str()); + int nVersion=-1; + if(request.params.size() > 1){ + nVersion = request.params[1].get_int(); + } + CScript script; - if(!file.getOnboardingScript(script)) + if(!file.getOnboardingScript(script, false, nVersion)) throw JSONRPCError(RPC_INVALID_PARAMETER, "Cannot generate onboarding script"); CWalletTx wtx; @@ -6039,7 +6046,7 @@ static const CRPCCommand commands[] = { "wallet", "dumpkycfile", &dumpkycfile, true, {"filename"} }, { "wallet", "readkycfile", &readkycfile, true, {"filename", "outfilename", "onboardpubkey"} }, { "wallet", "validatekycfile", &validatekycfile, true, {"filename"} }, - { "wallet", "onboarduser", &onboarduser, false, {"filename"} }, + { "wallet", "onboarduser", &onboarduser, false, {"filename", "scriptversion"} }, { "wallet", "blacklistuser", &blacklistuser, false, {"filename"} }, { "wallet", "topupkycpubkeys", &topupkycpubkeys, false, {"nkeys"} }, { "wallet", "removekycpubkey", &removekycpubkey, false, {"kycpubkey"} },