mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
Add support for claim transaction.
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 } }
|
||||
|
||||
Reference in New Issue
Block a user