Small fixes and logout
This commit is contained in:
@@ -214,6 +214,17 @@ UniValue NSPV_broadcast_json(struct NSPV_broadcastresp *ptr,uint256 txid)
|
||||
return(result);
|
||||
}
|
||||
|
||||
UniValue NSPV_logout()
|
||||
{
|
||||
UniValue result(UniValue::VOBJ);
|
||||
fprintf(stderr,"scrub wif and privkey from NSPV memory\n");
|
||||
memset(NSPV_wifstr,0,sizeof(NSPV_wifstr));
|
||||
memset(&NSPV_key,0,sizeof(NSPV_key));
|
||||
NSPV_logintime = 0;
|
||||
result.push_back(Pair("result","success"));
|
||||
return(result);
|
||||
}
|
||||
|
||||
UniValue NSPV_login(char *wifstr)
|
||||
{
|
||||
UniValue result(UniValue::VOBJ); char coinaddr[64]; uint8_t data[128]; int32_t len,valid = 0;
|
||||
@@ -229,11 +240,14 @@ UniValue NSPV_login(char *wifstr)
|
||||
return(result);
|
||||
}
|
||||
memset(NSPV_wifstr,0,sizeof(NSPV_wifstr));
|
||||
strncpy(NSPV_wifstr,wifstr,sizeof(NSPV_wifstr)-1);
|
||||
NSPV_logintime = (uint32_t)time(NULL);
|
||||
if ( strcmp(NSPV_wifstr,wifstr) != 0 )
|
||||
{
|
||||
strncpy(NSPV_wifstr,wifstr,sizeof(NSPV_wifstr)-1);
|
||||
NSPV_key = DecodeSecret(wifstr);
|
||||
}
|
||||
result.push_back(Pair("result","success"));
|
||||
result.push_back(Pair("status","wif will expire in 777 seconds"));
|
||||
NSPV_key = DecodeSecret(wifstr);
|
||||
CPubKey pubkey = NSPV_key.GetPubKey();
|
||||
CKeyID vchAddress = pubkey.GetID();
|
||||
NSPV_address = EncodeDestination(vchAddress);
|
||||
|
||||
@@ -353,10 +353,7 @@ void komodo_nSPV(CNode *pto) // polling loop from SendMessages
|
||||
uint8_t msg[256]; int32_t i,len=0; uint32_t timestamp = (uint32_t)time(NULL);
|
||||
if ( NSPV_logintime != 0 && timestamp > NSPV_logintime+NSPV_AUTOLOGOUT )
|
||||
{
|
||||
fprintf(stderr,"scrub wif and privkey from NSPV memory\n");
|
||||
memset(NSPV_wifstr,0,sizeof(NSPV_wifstr));
|
||||
memset(&NSPV_key,0,sizeof(NSPV_key));
|
||||
NSPV_logintime = 0;
|
||||
NSPV_logout();
|
||||
}
|
||||
if ( (pto->nServices & NODE_NSPV) == 0 )
|
||||
return;
|
||||
|
||||
@@ -426,6 +426,7 @@ static const CRPCCommand vRPCCommands[] =
|
||||
{ "nSPV", "nspv_txproof", &nspv_txproof, true },
|
||||
{ "nSPV", "nspv_spend", &nspv_spend, true },
|
||||
{ "nSPV", "nspv_broadcast", &nspv_broadcast, true },
|
||||
{ "nSPV", "nspv_logout", &nspv_logout, true },
|
||||
|
||||
// rewards
|
||||
{ "rewards", "rewardslist", &rewardslist, true },
|
||||
|
||||
@@ -464,6 +464,7 @@ extern UniValue nspv_hdrsproof(const UniValue& params, bool fHelp);
|
||||
extern UniValue nspv_txproof(const UniValue& params, bool fHelp);
|
||||
extern UniValue nspv_spend(const UniValue& params, bool fHelp);
|
||||
extern UniValue nspv_broadcast(const UniValue& params, bool fHelp);
|
||||
extern UniValue nspv_logout(const UniValue& params, bool fHelp);
|
||||
|
||||
extern UniValue getblocksubsidy(const UniValue& params, bool fHelp);
|
||||
|
||||
|
||||
@@ -974,6 +974,7 @@ UniValue z_exportviewingkey(const UniValue& params, bool fHelp)
|
||||
|
||||
UniValue NSPV_getinfo_json();
|
||||
UniValue NSPV_login(char *wifstr);
|
||||
UniValue NSPV_logout();
|
||||
UniValue NSPV_addressutxos(char *coinaddr);
|
||||
UniValue NSPV_broadcast(char *hex);
|
||||
UniValue NSPV_spend(char *srcaddr,char *destaddr,int64_t satoshis);
|
||||
@@ -991,6 +992,13 @@ UniValue nspv_getinfo(const UniValue& params, bool fHelp)
|
||||
return(NSPV_getinfo_json());
|
||||
}
|
||||
|
||||
UniValue nspv_logout(const UniValue& params, bool fHelp)
|
||||
{
|
||||
if ( fHelp || params.size() != 0 )
|
||||
throw runtime_error("nspv_logout\n");
|
||||
return(NSPV_getinfo_logout());
|
||||
}
|
||||
|
||||
UniValue nspv_login(const UniValue& params, bool fHelp)
|
||||
{
|
||||
if ( fHelp || params.size() != 1 )
|
||||
@@ -1002,9 +1010,15 @@ UniValue nspv_listunspent(const UniValue& params, bool fHelp)
|
||||
{
|
||||
if ( fHelp || params.size() > 1 )
|
||||
throw runtime_error("nspv_listunspent address\n");
|
||||
if ( params.size() == 0 && NSPV_address.size() != 0 )
|
||||
return(NSPV_addressutxos((char *)NSPV_address.c_str()));
|
||||
return(NSPV_addressutxos((char *)params[0].get_str().c_str()));
|
||||
if ( params.size() == 0 )
|
||||
{
|
||||
if ( NSPV_address.size() != 0 )
|
||||
return(NSPV_addressutxos((char *)NSPV_address.c_str()));
|
||||
else throw runtime_error("nspv_listunspent address\n");
|
||||
}
|
||||
if ( params.size() == 1 )
|
||||
return(NSPV_addressutxos((char *)params[0].get_str().c_str()));
|
||||
else throw runtime_error("nspv_listunspent address\n");
|
||||
}
|
||||
|
||||
UniValue nspv_spentinfo(const UniValue& params, bool fHelp)
|
||||
|
||||
Reference in New Issue
Block a user