mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Remove obsolete assumptions. (Not every transaction has an amount, not every
transaction has a destination).
This commit is contained in:
@@ -15,7 +15,6 @@ Transaction::Transaction(LocalAccount::pointer fromLocalAccount, const NewcoinAd
|
|||||||
uint32 ident, uint32 ledger) : mInLedger(0), mStatus(NEW)
|
uint32 ident, uint32 ledger) : mInLedger(0), mStatus(NEW)
|
||||||
{
|
{
|
||||||
mAccountFrom = fromLocalAccount->getAddress();
|
mAccountFrom = fromLocalAccount->getAddress();
|
||||||
mAccountTo = toAccount;
|
|
||||||
|
|
||||||
mTransaction = boost::make_shared<SerializedTransaction>(ttMAKE_PAYMENT);
|
mTransaction = boost::make_shared<SerializedTransaction>(ttMAKE_PAYMENT);
|
||||||
|
|
||||||
@@ -27,7 +26,7 @@ Transaction::Transaction(LocalAccount::pointer fromLocalAccount, const NewcoinAd
|
|||||||
assert(mTransaction->getSequence() != 0);
|
assert(mTransaction->getSequence() != 0);
|
||||||
mTransaction->setTransactionFee(100); // for now
|
mTransaction->setTransactionFee(100); // for now
|
||||||
|
|
||||||
mTransaction->setITFieldVL(sfDestination, toAccount.getAccountPublic());
|
mTransaction->setITFieldAccount(sfDestination, toAccount);
|
||||||
mTransaction->setITFieldU64(sfAmount, amount);
|
mTransaction->setITFieldU64(sfAmount, amount);
|
||||||
if (ledger != 0)
|
if (ledger != 0)
|
||||||
{
|
{
|
||||||
@@ -52,26 +51,21 @@ Transaction::Transaction(LocalAccount::pointer fromLocalAccount, const NewcoinAd
|
|||||||
|
|
||||||
Transaction::Transaction(SerializedTransaction::pointer sit, bool validate) : mStatus(INVALID), mTransaction(sit)
|
Transaction::Transaction(SerializedTransaction::pointer sit, bool validate) : mStatus(INVALID), mTransaction(sit)
|
||||||
{
|
{
|
||||||
uint160 toAccountID, fromAccountID;
|
|
||||||
std::vector<unsigned char> pubKey;
|
std::vector<unsigned char> pubKey;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
toAccountID = mTransaction->getITFieldH160(sfDestination);
|
|
||||||
pubKey = mTransaction->getRawSigningAccount();
|
pubKey = mTransaction->getRawSigningAccount();
|
||||||
mTransactionID = mTransaction->getTransactionID();
|
mTransactionID = mTransaction->getTransactionID();
|
||||||
|
mAccountFrom = mTransaction->getSourceAccount();
|
||||||
}
|
}
|
||||||
catch(...)
|
catch(...)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
mAccountTo.setAccountID(toAccountID);
|
|
||||||
mAccountFrom.setAccountID(fromAccountID);
|
|
||||||
|
|
||||||
mFromPubKey = boost::make_shared<CKey>();
|
mFromPubKey = boost::make_shared<CKey>();
|
||||||
if (!mFromPubKey->SetPubKey(pubKey)) return;
|
if (!mFromPubKey->SetPubKey(pubKey)) return;
|
||||||
mAccountFrom.setAccountPublic(pubKey);
|
|
||||||
mFromPubKey = theApp->getPubKeyCache().store(mAccountFrom, mFromPubKey);
|
mFromPubKey = theApp->getPubKeyCache().store(mAccountFrom, mFromPubKey);
|
||||||
|
|
||||||
if (!validate || checkSign())
|
if (!validate || checkSign())
|
||||||
@@ -109,7 +103,7 @@ Transaction::Transaction(const std::vector<unsigned char>& raw, bool validate) :
|
|||||||
Transaction::Transaction(const NewcoinAddress& fromID, const NewcoinAddress& toID,
|
Transaction::Transaction(const NewcoinAddress& fromID, const NewcoinAddress& toID,
|
||||||
CKey::pointer pubKey, uint64 amount, uint64 fee, uint32 fromSeq, uint32 fromLedger,
|
CKey::pointer pubKey, uint64 amount, uint64 fee, uint32 fromSeq, uint32 fromLedger,
|
||||||
uint32 ident, const std::vector<unsigned char>& signature, uint32 ledgerSeq, TransStatus st) :
|
uint32 ident, const std::vector<unsigned char>& signature, uint32 ledgerSeq, TransStatus st) :
|
||||||
mAccountFrom(fromID), mAccountTo(toID), mFromPubKey(pubKey), mInLedger(ledgerSeq), mStatus(st)
|
mAccountFrom(fromID), mFromPubKey(pubKey), mInLedger(ledgerSeq), mStatus(st)
|
||||||
{
|
{
|
||||||
mTransaction=boost::make_shared<SerializedTransaction>(ttMAKE_PAYMENT);
|
mTransaction=boost::make_shared<SerializedTransaction>(ttMAKE_PAYMENT);
|
||||||
mTransaction->setSignature(signature);
|
mTransaction->setSignature(signature);
|
||||||
@@ -127,6 +121,7 @@ Transaction::Transaction(const NewcoinAddress& fromID, const NewcoinAddress& toI
|
|||||||
mTransaction->setITFieldU32(sfSourceTag, ident);
|
mTransaction->setITFieldU32(sfSourceTag, ident);
|
||||||
}
|
}
|
||||||
mTransaction->setValueFieldU64(sfAmount, amount);
|
mTransaction->setValueFieldU64(sfAmount, amount);
|
||||||
|
mTransaction->setValueFieldAccount(sfDestination, toID.getAccountID());
|
||||||
updateID();
|
updateID();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -141,7 +136,7 @@ bool Transaction::sign(LocalAccount::pointer fromLocalAccount)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( (mTransaction->getITFieldU64(sfAmount)==0) || !mAccountTo.IsValid() )
|
if( (mTransaction->getITFieldU64(sfAmount)==0) )
|
||||||
{
|
{
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
std::cerr << "Bad amount or destination" << std::endl;
|
std::cerr << "Bad amount or destination" << std::endl;
|
||||||
@@ -354,7 +349,9 @@ bool Transaction::isHexTxID(const std::string& txid)
|
|||||||
Json::Value Transaction::getJson(bool decorate, bool paid, bool credited) const
|
Json::Value Transaction::getJson(bool decorate, bool paid, bool credited) const
|
||||||
{
|
{
|
||||||
Json::Value ret(mTransaction->getJson(0));
|
Json::Value ret(mTransaction->getJson(0));
|
||||||
|
|
||||||
if(mInLedger) ret["InLedger"]=mInLedger;
|
if(mInLedger) ret["InLedger"]=mInLedger;
|
||||||
|
if(paid) ret["Paid"]=true;
|
||||||
|
|
||||||
switch(mStatus)
|
switch(mStatus)
|
||||||
{
|
{
|
||||||
@@ -370,12 +367,7 @@ Json::Value Transaction::getJson(bool decorate, bool paid, bool credited) const
|
|||||||
default: ret["Status"]="unknown";
|
default: ret["Status"]="unknown";
|
||||||
}
|
}
|
||||||
|
|
||||||
Json::Value source(Json::objectValue);
|
#if 0
|
||||||
source["AccountID"]=mAccountFrom.humanAccountID();
|
|
||||||
|
|
||||||
Json::Value destination(Json::objectValue);
|
|
||||||
destination["AccountID"]=mAccountTo.humanAccountID();
|
|
||||||
|
|
||||||
if(decorate)
|
if(decorate)
|
||||||
{
|
{
|
||||||
LocalAccount::pointer lac=theApp->getWallet().getLocalAccount(mAccountFrom);
|
LocalAccount::pointer lac=theApp->getWallet().getLocalAccount(mAccountFrom);
|
||||||
@@ -383,9 +375,7 @@ Json::Value Transaction::getJson(bool decorate, bool paid, bool credited) const
|
|||||||
lac=theApp->getWallet().getLocalAccount(mAccountTo);
|
lac=theApp->getWallet().getLocalAccount(mAccountTo);
|
||||||
if(!!lac) destination=lac->getJson();
|
if(!!lac) destination=lac->getJson();
|
||||||
}
|
}
|
||||||
if(paid) source["Paid"]=true;
|
#endif
|
||||||
if(credited) destination["Credited"]=true;
|
|
||||||
ret["Source"]=source;
|
|
||||||
ret["Destination"]=destination;
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
uint256 mTransactionID;
|
uint256 mTransactionID;
|
||||||
NewcoinAddress mAccountFrom, mAccountTo;
|
NewcoinAddress mAccountFrom;
|
||||||
CKey::pointer mFromPubKey;
|
CKey::pointer mFromPubKey;
|
||||||
|
|
||||||
uint32 mInLedger;
|
uint32 mInLedger;
|
||||||
@@ -66,7 +66,6 @@ public:
|
|||||||
|
|
||||||
const uint256& getID() const { return mTransactionID; }
|
const uint256& getID() const { return mTransactionID; }
|
||||||
const NewcoinAddress& getFromAccount() const { return mAccountFrom; }
|
const NewcoinAddress& getFromAccount() const { return mAccountFrom; }
|
||||||
const NewcoinAddress& getToAccount() const { return mAccountTo; }
|
|
||||||
uint64 getAmount() const { return mTransaction->getITFieldU64(sfAmount); }
|
uint64 getAmount() const { return mTransaction->getITFieldU64(sfAmount); }
|
||||||
uint64 getFee() const { return mTransaction->getTransactionFee(); }
|
uint64 getFee() const { return mTransaction->getTransactionFee(); }
|
||||||
uint32 getFromAccountSeq() const { return mTransaction->getSequence(); }
|
uint32 getFromAccountSeq() const { return mTransaction->getSequence(); }
|
||||||
|
|||||||
Reference in New Issue
Block a user