allow you to send from an unclaimed wallet

This commit is contained in:
jed
2012-06-10 07:18:23 -07:00
parent 0f0e567829
commit c37cf4001d
5 changed files with 273 additions and 126 deletions

View File

@@ -275,10 +275,10 @@ Json::Value RPCServer::getMasterGenerator(const uint256& uLedger, const NewcoinA
// - Make sure the source account can pay.
// --> naRegularSeed : To find the generator
// --> naSrcAccountID : Account we want the public and private regular keys to.
// --> naVerifyGenerator : If provided, the found master public generator must match.
// <-- naAccountPublic : Regular public key for naSrcAccountID
// <-- naAccountPrivate : Regular private key for naSrcAccountID
// <-- saSrcBalance: Balance minus fee.
// --> naVerifyGenerator : If provided, the found master public generator must match.
Json::Value RPCServer::authorize(const uint256& uLedger,
const NewcoinAddress& naRegularSeed, const NewcoinAddress& naSrcAccountID,
NewcoinAddress& naAccountPublic, NewcoinAddress& naAccountPrivate,
@@ -291,19 +291,21 @@ Json::Value RPCServer::authorize(const uint256& uLedger,
{
return RPCError(rpcSRC_MISSING);
}
// Source must have been claimed.
if (!asSrc->bHaveAuthorizedKey())
{
return RPCError(rpcSRC_UNCLAIMED);
}
NewcoinAddress naMasterGenerator;
Json::Value obj = getMasterGenerator(uLedger, naRegularSeed, naMasterGenerator);
if(asSrc->bHaveAuthorizedKey())
{
Json::Value obj = getMasterGenerator(uLedger, naRegularSeed, naMasterGenerator);
if (!obj.empty())
return obj;
if (!obj.empty())
return obj;
}else
{
// Try the seed as a master seed.
naMasterGenerator.setFamilyGenerator(naRegularSeed);
}
// If naVerifyGenerator is provided, make sure it is the master generator.
if (naVerifyGenerator.isValid() && naMasterGenerator != naVerifyGenerator)
@@ -330,7 +332,7 @@ Json::Value RPCServer::authorize(const uint256& uLedger,
naAccountPublic.setAccountPublic(naGenerator, iIndex);
naAccountPrivate.setAccountPrivate(naGenerator, naRegularSeed, iIndex);
if (asSrc->getAuthorizedKey().getAccountID() != naAccountPublic.getAccountID())
if (asSrc->bHaveAuthorizedKey() && (asSrc->getAuthorizedKey().getAccountID() != naAccountPublic.getAccountID()))
{
std::cerr << "iIndex: " << iIndex << std::endl;
std::cerr << "sfAuthorizedKey: " << strHex(asSrc->getAuthorizedKey().getAccountID()) << std::endl;
@@ -350,6 +352,7 @@ Json::Value RPCServer::authorize(const uint256& uLedger,
saSrcBalance -= saFee;
}
Json::Value obj;
return obj;
}
@@ -426,13 +429,13 @@ Json::Value RPCServer::doAccountEmailSet(Json::Value &params)
return RPCError(rpcSRC_ACT_MALFORMED);
}
NewcoinAddress naMasterGenerator;
NewcoinAddress naVerifyGenerator;
NewcoinAddress naAccountPublic;
NewcoinAddress naAccountPrivate;
AccountState::pointer asSrc;
STAmount saSrcBalance;
Json::Value obj = authorize(uLedger, naSeed, naSrcAccountID, naAccountPublic, naAccountPrivate,
saSrcBalance, theConfig.FEE_DEFAULT, asSrc, naMasterGenerator);
saSrcBalance, theConfig.FEE_DEFAULT, asSrc, naVerifyGenerator);
if (!obj.empty())
return obj;
@@ -634,13 +637,13 @@ Json::Value RPCServer::doAccountMessageSet(Json::Value& params) {
return RPCError(rpcPUBLIC_MALFORMED);
}
NewcoinAddress naMasterGenerator;
NewcoinAddress naVerifyGenerator;
NewcoinAddress naAccountPublic;
NewcoinAddress naAccountPrivate;
AccountState::pointer asSrc;
STAmount saSrcBalance;
Json::Value obj = authorize(uLedger, naSeed, naSrcAccountID, naAccountPublic, naAccountPrivate,
saSrcBalance, theConfig.FEE_DEFAULT, asSrc, naMasterGenerator);
saSrcBalance, theConfig.FEE_DEFAULT, asSrc, naVerifyGenerator);
if (!obj.empty())
return obj;
@@ -1177,13 +1180,13 @@ Json::Value RPCServer::doSend(Json::Value& params)
bool bCreate = !asDst;
STAmount saFee = bCreate ? theConfig.FEE_ACCOUNT_CREATE : theConfig.FEE_DEFAULT;
NewcoinAddress naMasterGenerator;
NewcoinAddress naVerifyGenerator;
NewcoinAddress naAccountPublic;
NewcoinAddress naAccountPrivate;
AccountState::pointer asSrc;
STAmount saSrcBalance;
Json::Value obj = authorize(uLedger, naSeed, naSrcAccountID, naAccountPublic, naAccountPrivate,
saSrcBalance, saFee, asSrc, naMasterGenerator);
saSrcBalance, saFee, asSrc, naVerifyGenerator);
if (!obj.empty())
return obj;
@@ -1764,7 +1767,7 @@ Json::Value RPCServer::doWalletClaim(Json::Value& params)
std::vector<unsigned char> vucGeneratorCipher = naRegular0Private.accountPrivateEncrypt(naRegular0Public, naMasterGenerator.getFamilyGenerator());
std::vector<unsigned char> vucGeneratorSig;
// Prove that we have the corrisponding private key to the generator id. So, we can get the generator id.
// Prove that we have the corresponding private key to the generator id. So, we can get the generator id.
// XXX Check result.
naRegular0Private.accountPrivateSign(Serializer::getSHA512Half(vucGeneratorCipher), vucGeneratorSig);