Add support for claim transaction.

This commit is contained in:
Arthur Britto
2012-05-12 18:30:47 -07:00
parent d761f4c451
commit e0cb27f1c1
3 changed files with 51 additions and 2 deletions

View File

@@ -175,7 +175,54 @@ TransactionEngineResult TransactionEngine::applyTransaction(const SerializedTran
TransactionEngineResult TransactionEngine::doClaim(const SerializedTransaction& txn,
std::vector<AffectedAccount>& accounts)
{
return terUNKNOWN;
NewcoinAddress naSigningPubKey;
naSigningPubKey.setAccountPublic(txn.peekSigningPubKey());
uint160 sourceAccountID = naSigningPubKey.getAccountID();
if (sourceAccountID != txn.getSourceAccount().getAccountID())
// Signing Pub Key must be for Source Account ID.
return terINVALID;
LedgerStateParms qry = lepNONE;
SerializedLedgerEntry::pointer dest = mLedger->getAccountRoot(qry, sourceAccountID);
if (!dest)
// Source account does not exist. Could succeed if it was created first.
return terNO_ACCOUNT;
if (dest->getIFieldPresent(sfAuthorizedKey))
// Source account already claimed.
return terCLAIMED;
uint160 hGeneratorID = txn.getITFieldH160(sfGeneratorID);
qry = lepNONE;
SerializedLedgerEntry::pointer gen = mLedger->getGenerator(qry, hGeneratorID);
if (gen)
// Generator is already in use. Regular passphrases limited to one wallet.
return terGEN_IN_USE;
//
// Claim the account.
//
std::vector<unsigned char> vucCipher = txn.getITFieldVL(sfGenerator);
// Set the public key needed to use the account.
dest->setIFieldH160(sfAuthorizedKey, hGeneratorID);
accounts.push_back(std::make_pair(taaMODIFY, dest));
// Construct a generator map entry.
gen = boost::make_shared<SerializedLedgerEntry>(ltGENERATOR_MAP);
gen->setIndex(Ledger::getGeneratorIndex(hGeneratorID));
gen->setIFieldH160(sfGeneratorID, hGeneratorID);
gen->setIFieldVL(sfGenerator, vucCipher);
accounts.push_back(std::make_pair(taaCREATE, gen));
return terSUCCESS;
}
TransactionEngineResult TransactionEngine::doPayment(const SerializedTransaction& txn,

View File

@@ -12,6 +12,8 @@
enum TransactionEngineResult
{ // <0 = Can never succeed, 0 = success, >0 = failed, but could succeed
terGEN_IN_USE = -6, // Generator already in use.
terCLAIMED = -5, // Can not claim a previously claimed account.
terFAILED = -4, // Something broke horribly
terUNKNOWN = -3, // The transactions requires logic not implemented yet
terINSUF_FEE_P = -2, // fee totally insufficient

View File

@@ -18,7 +18,7 @@ TransactionFormat InnerTxnFormats[]=
},
{ "Claim", ttCLAIM, {
{ S_FIELD(Flags), STI_UINT32, SOE_FLAGS, 0 },
{ S_FIELD(GeneratorID), STI_AMOUNT, SOE_REQUIRED, 0 },
{ S_FIELD(GeneratorID), STI_HASH160, SOE_REQUIRED, 0 },
{ S_FIELD(Generator), STI_VL, SOE_REQUIRED, 0 },
{ S_FIELD(Extensions), STI_TL, SOE_IFFLAG, 0x02000000 },
{ sfInvalid, NULL, STI_DONE, SOE_NEVER, -1 } }