Implement doWalletAdd().

This commit is contained in:
Arthur Britto
2012-06-01 23:32:27 -07:00
parent 2e61af4318
commit affe4445bd
3 changed files with 45 additions and 50 deletions

View File

@@ -12,7 +12,7 @@ LedgerEntryFormat LedgerFormats[]=
{ S_FIELD(Balance), STI_AMOUNT, SOE_REQUIRED, 0 }, { S_FIELD(Balance), STI_AMOUNT, SOE_REQUIRED, 0 },
{ S_FIELD(LastReceive), STI_UINT32, SOE_REQUIRED, 0 }, { S_FIELD(LastReceive), STI_UINT32, SOE_REQUIRED, 0 },
{ S_FIELD(LastTxn), STI_UINT32, SOE_REQUIRED, 0 }, { S_FIELD(LastTxn), STI_UINT32, SOE_REQUIRED, 0 },
{ S_FIELD(AuthorizedKey), STI_HASH160, SOE_IFFLAG, 1 }, { S_FIELD(AuthorizedKey), STI_ACCOUNT, SOE_IFFLAG, 1 },
{ S_FIELD(EmailHash), STI_HASH128, SOE_IFFLAG, 2 }, { S_FIELD(EmailHash), STI_HASH128, SOE_IFFLAG, 2 },
{ S_FIELD(WalletLocator), STI_HASH256, SOE_IFFLAG, 4 }, { S_FIELD(WalletLocator), STI_HASH256, SOE_IFFLAG, 4 },
{ S_FIELD(MessageKey), STI_VL, SOE_IFFLAG, 8 }, { S_FIELD(MessageKey), STI_VL, SOE_IFFLAG, 8 },

View File

@@ -272,9 +272,7 @@ TransactionEngineResult TransactionEngine::applyTransaction(const SerializedTran
// without going to disk. Each transaction also notes a source account id. This is used to verify that the signing key is // without going to disk. Each transaction also notes a source account id. This is used to verify that the signing key is
// associated with the account. // associated with the account.
// XXX This could be a lot cleaner to prevent unnecessary copying. // XXX This could be a lot cleaner to prevent unnecessary copying.
NewcoinAddress naSigningPubKey; NewcoinAddress naSigningPubKey = NewcoinAddress::createAccountPublic(txn.peekSigningPubKey());
naSigningPubKey.setAccountPublic(txn.peekSigningPubKey());
// Consistency: really signed. // Consistency: really signed.
if (!txn.checkSign(naSigningPubKey)) if (!txn.checkSign(naSigningPubKey))
@@ -385,7 +383,7 @@ TransactionEngineResult TransactionEngine::applyTransaction(const SerializedTran
return tenUNCLAIMED; return tenUNCLAIMED;
} }
else if (naSigningPubKey.getAccountID() != sleSrc->getIFieldH160(sfAuthorizedKey)) else if (naSigningPubKey.getAccountID() != sleSrc->getIValueFieldAccount(sfAuthorizedKey).getAccountID())
{ {
std::cerr << "applyTransaction: Not authorized to use account." << std::endl; std::cerr << "applyTransaction: Not authorized to use account." << std::endl;
@@ -555,10 +553,7 @@ TransactionEngineResult TransactionEngine::doClaim(const SerializedTransaction&
std::vector<unsigned char> vucCipher = txn.getITFieldVL(sfGenerator); std::vector<unsigned char> vucCipher = txn.getITFieldVL(sfGenerator);
std::vector<unsigned char> vucPubKey = txn.getITFieldVL(sfPubKey); std::vector<unsigned char> vucPubKey = txn.getITFieldVL(sfPubKey);
std::vector<unsigned char> vucSignature = txn.getITFieldVL(sfSignature); std::vector<unsigned char> vucSignature = txn.getITFieldVL(sfSignature);
NewcoinAddress naAccountPublic = NewcoinAddress::createAccountPublic(vucPubKey);
NewcoinAddress naAccountPublic;
naAccountPublic.setAccountPublic(vucPubKey);
if (!naAccountPublic.accountPublicVerify(Serializer::getSHA512Half(vucCipher), vucSignature)) if (!naAccountPublic.accountPublicVerify(Serializer::getSHA512Half(vucCipher), vucSignature))
{ {
@@ -919,61 +914,59 @@ TransactionEngineResult TransactionEngine::doWalletAdd(const SerializedTransacti
{ {
std::cerr << "WalletAdd>" << std::endl; std::cerr << "WalletAdd>" << std::endl;
SLE::pointer sleDst = accounts[0].second; std::vector<unsigned char> vucPubKey = txn.getITFieldVL(sfPubKey);
std::vector<unsigned char> vucSignature = txn.getITFieldVL(sfSignature);
uint160 uAuthKeyID = txn.getITFieldAccount(sfAuthorizedKey);
NewcoinAddress naMasterPubKey = NewcoinAddress::createAccountPublic(vucPubKey);
uint160 uDstAccountID = naMasterPubKey.getAccountID();
if (!naMasterPubKey.accountPublicVerify(Serializer::getSHA512Half(uAuthKeyID.begin(), uAuthKeyID.size()), vucSignature))
{
std::cerr << "WalletAdd: unauthorized: bad signature " << std::endl;
return tenBAD_ADD_AUTH;
}
LedgerStateParms qry = lepNONE;
SLE::pointer sleDst = mLedger->getAccountRoot(qry, uDstAccountID);
std::cerr << str(boost::format("WalletAdd: %s") % sleDst->getFullText()) << std::endl; std::cerr << str(boost::format("WalletAdd: %s") % sleDst->getFullText()) << std::endl;
// Verify not already claimed. if (sleDst)
if (sleDst->getIFieldPresent(sfAuthorizedKey))
{ {
std::cerr << "WalletAdd: source already claimed" << std::endl; std::cerr << "WalletAdd: account already created" << std::endl;
return terCLAIMED; return tenCREATED;
} }
// SLE::pointer sleSrc = accounts[0].second;
// Generator ID is based on regular account #0 public key. STAmount saAmount = txn.getITFieldAmount(sfAmount);
// Verify that submitter knows the private key for the generator. STAmount saSrcBalance = sleSrc->getIValueFieldAmount(sfBalance);
// Otherwise, people could deny access to generators.
//
std::vector<unsigned char> vucCipher = txn.getITFieldVL(sfGenerator); if (saSrcBalance < saAmount)
std::vector<unsigned char> vucPubKey = txn.getITFieldVL(sfPubKey);
std::vector<unsigned char> vucSignature = txn.getITFieldVL(sfSignature);
NewcoinAddress naAccountPublic;
naAccountPublic.setAccountPublic(vucPubKey);
if (!naAccountPublic.accountPublicVerify(Serializer::getSHA512Half(vucCipher), vucSignature))
{ {
std::cerr << "WalletAdd: bad signature unauthorized generator claim" << std::endl; std::cerr
<< str(boost::format("WalletAdd: Delay transaction: insufficent balance: balance=%s amount=%s")
% saSrcBalance
% saAmount)
<< std::endl;
return tenBAD_GEN_AUTH; return terUNFUNDED;
} }
// // Deduct initial balance from source account.
// Verify generator not already in use. sleSrc->setIFieldAmount(sfBalance, saSrcBalance-saAmount);
//
uint160 hGeneratorID = naAccountPublic.getAccountID(); // Create the account.
sleDst = boost::make_shared<SerializedLedgerEntry>(ltACCOUNT_ROOT);
LedgerStateParms qry = lepNONE; sleDst->setIndex(Ledger::getAccountRootIndex(uDstAccountID));
SLE::pointer sleGen = mLedger->getGenerator(qry, hGeneratorID); sleDst->setIFieldAccount(sfAccount, uDstAccountID);
if (sleGen) sleDst->setIFieldU32(sfSequence, 1);
{ sleDst->setIFieldAmount(sfBalance, saAmount);
// Generator is already in use. Regular passphrases limited to one wallet. sleDst->setIFieldAccount(sfAuthorizedKey, uAuthKeyID);
std::cerr << "WalletAdd: generator already in use" << std::endl;
return tenGEN_IN_USE; accounts.push_back(std::make_pair(taaCREATE, sleDst));
}
//
// Claim the account.
//
// Set the public key needed to use the account.
sleDst->setIFieldH160(sfAuthorizedKey, hGeneratorID);
std::cerr << "WalletAdd<" << std::endl; std::cerr << "WalletAdd<" << std::endl;

View File

@@ -19,10 +19,12 @@ enum TransactionEngineResult
tenDST_NEEDED, // Destination not specified. tenDST_NEEDED, // Destination not specified.
tenDST_IS_SRC, // Destination may not be source. tenDST_IS_SRC, // Destination may not be source.
tenBAD_GEN_AUTH, // Not authorized to claim generator. tenBAD_GEN_AUTH, // Not authorized to claim generator.
tenBAD_ADD_AUTH, // Not authorized to add account.
// Invalid: Ledger won't allow. // Invalid: Ledger won't allow.
tenUNCLAIMED = -200, // Can not use an unclaimed account. tenUNCLAIMED = -200, // Can not use an unclaimed account.
tenBAD_AUTH, // Transaction's public key is not authorized. tenBAD_AUTH, // Transaction's public key is not authorized.
tenCREATED, // Can't add an already created account.
// Other // Other
tenFAILED = -100, // Something broke horribly tenFAILED = -100, // Something broke horribly
@@ -51,7 +53,7 @@ enum TransactionEngineResult
terPAST_LEDGER, // The transaction expired and can't be applied terPAST_LEDGER, // The transaction expired and can't be applied
terPAST_SEQ, // This sequence number has already past terPAST_SEQ, // This sequence number has already past
terPRE_SEQ, // Missing/inapplicable prior transaction terPRE_SEQ, // Missing/inapplicable prior transaction
terUNFUNDED, // Source account had insufficient balance for transactin terUNFUNDED, // Source account had insufficient balance for transaction.
terNO_LINE_NO_ZERO, // Can't zero non-existant line, destination might make it. terNO_LINE_NO_ZERO, // Can't zero non-existant line, destination might make it.
}; };