diff --git a/src/komodo_validation015.h b/src/komodo_validation015.h index a7913f3c3..2367453e0 100644 --- a/src/komodo_validation015.h +++ b/src/komodo_validation015.h @@ -54,7 +54,6 @@ }*/ #include -#include #include #define SATOSHIDEN ((uint64_t)100000000L) @@ -77,7 +76,7 @@ typedef union _bits256 bits256; struct sha256_vstate { uint64_t length; uint32_t state[8],curlen; uint8_t buf[64]; }; struct rmd160_vstate { uint64_t length; uint8_t buf[64]; uint32_t curlen, state[5]; }; int32_t KOMODO_TXINDEX = 1; -void ImportAddress(CWallet*, const CTxDestination& dest, const std::string& strLabel); +void ImportAddress(CWallet* const pwallet, const CBitcoinAddress& address, const std::string& strLabel); int32_t gettxout_scriptPubKey(int32_t height,uint8_t *scriptPubKey,int32_t maxsize,uint256 txid,int32_t n) { @@ -121,14 +120,13 @@ int32_t gettxout_scriptPubKey(int32_t height,uint8_t *scriptPubKey,int32_t maxsi int32_t komodo_importaddress(std::string addr) { - CTxDestination address; CWallet * const pwallet = vpwallets[0]; + CBitcoinAddress address(addr); CWallet * const pwallet = vpwallets[0]; if ( pwallet != 0 ) { LOCK2(cs_main, pwallet->cs_wallet); - address = DecodeDestination(addr); - if ( IsValidDestination(address) != 0 ) + if ( address.IsValid() != 0 ) { - isminetype mine = IsMine(*pwallet, address); + isminetype mine = IsMine(*pwallet, address.Get()); if ( (mine & ISMINE_SPENDABLE) != 0 || (mine & ISMINE_WATCH_ONLY) != 0 ) { //printf("komodo_importaddress %s already there\n",EncodeDestination(address).c_str()); @@ -136,12 +134,12 @@ int32_t komodo_importaddress(std::string addr) } else { - printf("komodo_importaddress %s\n",EncodeDestination(address).c_str()); + printf("komodo_importaddress %s\n",addr.c_str()); ImportAddress(pwallet, address, addr); return(1); } } - printf("%s -> komodo_importaddress.(%s) failed valid.%d\n",addr.c_str(),EncodeDestination(address).c_str(),IsValidDestination(address)); + printf("%s -> komodo_importaddress failed valid.%d\n",addr.c_str(),address.IsValid()); } return(-1); } @@ -737,7 +735,7 @@ void komodo_importpubkeys() { int32_t i,n,j,m,offset,val,dispflag = 0; std::string addr; char *ptr; offset = 2; - if ( strcmp(ASSETCHAINS_SYMBOL,"GAME") == 0 ) + if ( strcmp(ASSETCHAINS_SYMBOL,"HUSH") == 0 ) offset++; n = (int32_t)(sizeof(Notaries_elected1)/sizeof(*Notaries_elected1)); for (i=0; iMarkDirty(); + + if (!pwallet->HaveWatchOnly(script) && !pwallet->AddWatchOnly(script)) { + throw JSONRPCError(RPC_WALLET_ERROR, "Error adding address to wallet"); + } + + if (isRedeemScript) { + if (!pwallet->HaveCScript(script) && !pwallet->AddCScript(script)) { + throw JSONRPCError(RPC_WALLET_ERROR, "Error adding p2sh redeemScript to wallet"); + } + ImportAddress(pwallet, CBitcoinAddress(CScriptID(script)), strLabel); + } else { + CTxDestination destination; + if (ExtractDestination(script, destination)) { + pwallet->SetAddressBook(destination, strLabel, "receive"); + } + } +} + +void ImportAddress(CWallet* const pwallet, const CBitcoinAddress& address, const std::string& strLabel) +{ + CScript script = GetScriptForDestination(address.Get()); + ImportScript(pwallet, script, strLabel, false); + // add to address book or update label + if (address.IsValid()) + pwallet->SetAddressBook(address.Get(), strLabel, "receive"); +} + + UniValue importprivkey(const UniValue& params, bool fHelp) { if (!EnsureWalletIsAvailable(fHelp))