mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Be clear about what's an account and what's a public key.
This commit is contained in:
@@ -7,7 +7,7 @@ SerializedTransaction::SerializedTransaction(TransactionType type) : mType(type)
|
|||||||
if (mFormat == NULL) throw std::runtime_error("invalid transaction type");
|
if (mFormat == NULL) throw std::runtime_error("invalid transaction type");
|
||||||
|
|
||||||
mMiddleTxn.giveObject(new STUInt32("Magic", TransactionMagic));
|
mMiddleTxn.giveObject(new STUInt32("Magic", TransactionMagic));
|
||||||
mMiddleTxn.giveObject(new STVariableLength("SigningAccount"));
|
mMiddleTxn.giveObject(new STVariableLength("SigningPubKey"));
|
||||||
mMiddleTxn.giveObject(new STUInt32("Sequence"));
|
mMiddleTxn.giveObject(new STUInt32("Sequence"));
|
||||||
mMiddleTxn.giveObject(new STUInt8("Type", static_cast<unsigned char>(type)));
|
mMiddleTxn.giveObject(new STUInt8("Type", static_cast<unsigned char>(type)));
|
||||||
mMiddleTxn.giveObject(new STUInt64("Fee"));
|
mMiddleTxn.giveObject(new STUInt64("Fee"));
|
||||||
@@ -28,7 +28,7 @@ SerializedTransaction::SerializedTransaction(SerializerIterator& sit, int length
|
|||||||
throw std::runtime_error("Transaction has invalid magic");
|
throw std::runtime_error("Transaction has invalid magic");
|
||||||
|
|
||||||
mMiddleTxn.giveObject(new STUInt32("Magic", TransactionMagic));
|
mMiddleTxn.giveObject(new STUInt32("Magic", TransactionMagic));
|
||||||
mMiddleTxn.giveObject(new STVariableLength("SigningAccount", sit.getVL()));
|
mMiddleTxn.giveObject(new STVariableLength("SigningPubKey", sit.getVL()));
|
||||||
mMiddleTxn.giveObject(new STUInt32("Sequence", sit.get32()));
|
mMiddleTxn.giveObject(new STUInt32("Sequence", sit.get32()));
|
||||||
|
|
||||||
mType = static_cast<TransactionType>(sit.get32());
|
mType = static_cast<TransactionType>(sit.get32());
|
||||||
@@ -44,7 +44,7 @@ SerializedTransaction::SerializedTransaction(SerializerIterator& sit, int length
|
|||||||
void SerializedTransaction::updateSourceAccount()
|
void SerializedTransaction::updateSourceAccount()
|
||||||
{
|
{
|
||||||
NewcoinAddress a;
|
NewcoinAddress a;
|
||||||
a.setAccountPublic(peekRawSigningAccount());
|
a.setAccountPublic(peekSigningPubKey());
|
||||||
mSourceAccount.setAccountID(a.getAccountID());
|
mSourceAccount.setAccountID(a.getAccountID());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -194,35 +194,36 @@ void SerializedTransaction::setSequence(uint32 seq)
|
|||||||
v->setValue(seq);
|
v->setValue(seq);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<unsigned char> SerializedTransaction::getRawSigningAccount() const
|
std::vector<unsigned char> SerializedTransaction::getSigningPubKey() const
|
||||||
{
|
{
|
||||||
const STVariableLength* v =
|
const STVariableLength* v =
|
||||||
dynamic_cast<const STVariableLength*>(mMiddleTxn.peekAtPIndex(TransactionISigningAccount));
|
dynamic_cast<const STVariableLength*>(mMiddleTxn.peekAtPIndex(TransactionISigningPubKey));
|
||||||
if (!v) throw std::runtime_error("corrupt transaction");
|
if (!v) throw std::runtime_error("corrupt transaction");
|
||||||
return v->getValue();
|
return v->getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::vector<unsigned char>& SerializedTransaction::peekRawSigningAccount() const
|
const std::vector<unsigned char>& SerializedTransaction::peekSigningPubKey() const
|
||||||
{
|
{
|
||||||
const STVariableLength* v=
|
const STVariableLength* v=
|
||||||
dynamic_cast<const STVariableLength*>(mMiddleTxn.peekAtPIndex(TransactionISigningAccount));
|
dynamic_cast<const STVariableLength*>(mMiddleTxn.peekAtPIndex(TransactionISigningPubKey));
|
||||||
if (!v) throw std::runtime_error("corrupt transaction");
|
if (!v) throw std::runtime_error("corrupt transaction");
|
||||||
return v->peekValue();
|
return v->peekValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<unsigned char>& SerializedTransaction::peekRawSigningAccount()
|
std::vector<unsigned char>& SerializedTransaction::peekSigningPubKey()
|
||||||
{
|
{
|
||||||
STVariableLength* v = dynamic_cast<STVariableLength*>(mMiddleTxn.getPIndex(TransactionISigningAccount));
|
STVariableLength* v = dynamic_cast<STVariableLength*>(mMiddleTxn.getPIndex(TransactionISigningPubKey));
|
||||||
if (!v) throw std::runtime_error("corrupt transaction");
|
if (!v) throw std::runtime_error("corrupt transaction");
|
||||||
return v->peekValue();
|
return v->peekValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SerializedTransaction::setSigningAccount(const std::vector<unsigned char>& s)
|
const NewcoinAddress& SerializedTransaction::setSigningPubKey(const std::vector<unsigned char>& s)
|
||||||
{
|
{
|
||||||
STVariableLength* v = dynamic_cast<STVariableLength*>(mMiddleTxn.getPIndex(TransactionISigningAccount));
|
STVariableLength* v = dynamic_cast<STVariableLength*>(mMiddleTxn.getPIndex(TransactionISigningPubKey));
|
||||||
if (!v) throw std::runtime_error("corrupt transaction");
|
if (!v) throw std::runtime_error("corrupt transaction");
|
||||||
v->setValue(s);
|
v->setValue(s);
|
||||||
updateSourceAccount();
|
updateSourceAccount();
|
||||||
|
return mSourceAccount;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint160 SerializedTransaction::getITFieldAccount(SOE_Field field) const
|
uint160 SerializedTransaction::getITFieldAccount(SOE_Field field) const
|
||||||
|
|||||||
@@ -52,10 +52,10 @@ public:
|
|||||||
void setTransactionFee(uint64);
|
void setTransactionFee(uint64);
|
||||||
|
|
||||||
const NewcoinAddress& getSourceAccount() const { return mSourceAccount; }
|
const NewcoinAddress& getSourceAccount() const { return mSourceAccount; }
|
||||||
std::vector<unsigned char> getRawSigningAccount() const;
|
std::vector<unsigned char> getSigningPubKey() const;
|
||||||
const std::vector<unsigned char>& peekRawSigningAccount() const;
|
const std::vector<unsigned char>& peekSigningPubKey() const;
|
||||||
std::vector<unsigned char>& peekRawSigningAccount();
|
std::vector<unsigned char>& peekSigningPubKey();
|
||||||
void setSigningAccount(const std::vector<unsigned char>& s);
|
const NewcoinAddress& setSigningPubKey(const std::vector<unsigned char>& s);
|
||||||
std::string getTransactionType() const { return mFormat->t_name; }
|
std::string getTransactionType() const { return mFormat->t_name; }
|
||||||
|
|
||||||
// inner transaction functions
|
// inner transaction functions
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ Transaction::Transaction(LocalAccount::pointer fromLocalAccount, const NewcoinAd
|
|||||||
|
|
||||||
mFromPubKey = fromLocalAccount->getPublicKey();
|
mFromPubKey = fromLocalAccount->getPublicKey();
|
||||||
assert(mFromPubKey);
|
assert(mFromPubKey);
|
||||||
mTransaction->setSigningAccount(mFromPubKey->GetPubKey());
|
mTransaction->setSigningPubKey(mFromPubKey->GetPubKey());
|
||||||
|
|
||||||
mTransaction->setSequence(accountState->getSeq());
|
mTransaction->setSequence(accountState->getSeq());
|
||||||
assert(mTransaction->getSequence() != 0);
|
assert(mTransaction->getSequence() != 0);
|
||||||
@@ -59,7 +59,7 @@ Transaction::Transaction(SerializedTransaction::pointer sit, bool validate) : mS
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
pubKey = mTransaction->getRawSigningAccount();
|
pubKey = mTransaction->peekSigningPubKey();
|
||||||
mTransactionID = mTransaction->getTransactionID();
|
mTransactionID = mTransaction->getTransactionID();
|
||||||
mAccountFrom = mTransaction->getSourceAccount();
|
mAccountFrom = mTransaction->getSourceAccount();
|
||||||
}
|
}
|
||||||
@@ -109,17 +109,17 @@ Transaction::Transaction(const NewcoinAddress& fromID, const NewcoinAddress& toI
|
|||||||
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), 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);
|
||||||
mTransaction->setTransactionFee(fee);
|
mTransaction->setTransactionFee(fee);
|
||||||
mTransaction->setSigningAccount(pubKey->GetPubKey());
|
mTransaction->setSigningPubKey(pubKey->GetPubKey());
|
||||||
mTransaction->setSequence(fromSeq);
|
mTransaction->setSequence(fromSeq);
|
||||||
if(fromLedger!=0)
|
if (fromLedger != 0)
|
||||||
{
|
{
|
||||||
mTransaction->makeITFieldPresent(sfTargetLedger);
|
mTransaction->makeITFieldPresent(sfTargetLedger);
|
||||||
mTransaction->setITFieldU32(sfTargetLedger, fromLedger);
|
mTransaction->setITFieldU32(sfTargetLedger, fromLedger);
|
||||||
}
|
}
|
||||||
if(ident!=0)
|
if (ident != 0)
|
||||||
{
|
{
|
||||||
mTransaction->makeITFieldPresent(sfSourceTag);
|
mTransaction->makeITFieldPresent(sfSourceTag);
|
||||||
mTransaction->setITFieldU32(sfSourceTag, ident);
|
mTransaction->setITFieldU32(sfSourceTag, ident);
|
||||||
@@ -131,7 +131,7 @@ Transaction::Transaction(const NewcoinAddress& fromID, const NewcoinAddress& toI
|
|||||||
|
|
||||||
bool Transaction::sign(LocalAccount::pointer fromLocalAccount)
|
bool Transaction::sign(LocalAccount::pointer fromLocalAccount)
|
||||||
{
|
{
|
||||||
CKey::pointer privateKey=fromLocalAccount->getPrivateKey();
|
CKey::pointer privateKey = fromLocalAccount->getPrivateKey();
|
||||||
if(!privateKey)
|
if(!privateKey)
|
||||||
{
|
{
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ TransactionEngineResult TransactionEngine::applyTransaction(const SerializedTran
|
|||||||
|
|
||||||
// extract signing key
|
// extract signing key
|
||||||
CKey acctKey;
|
CKey acctKey;
|
||||||
if (!acctKey.SetPubKey(txn.getRawSigningAccount())) return terINVALID;
|
if (!acctKey.SetPubKey(txn.peekSigningPubKey())) return terINVALID;
|
||||||
|
|
||||||
// check signature
|
// check signature
|
||||||
if (!txn.checkSign(acctKey)) return terINVALID;
|
if (!txn.checkSign(acctKey)) return terINVALID;
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ struct TransactionFormat
|
|||||||
|
|
||||||
const int32 TransactionMagic=0x54584E00;
|
const int32 TransactionMagic=0x54584E00;
|
||||||
|
|
||||||
const int TransactionIVersion=0, TransactionISigningAccount=1, TransactionISequence=2;
|
const int TransactionIVersion=0, TransactionISigningPubKey=1, TransactionISequence=2;
|
||||||
const int TransactionIType=3, TransactionIFee=4;
|
const int TransactionIType=3, TransactionIFee=4;
|
||||||
|
|
||||||
const int TransactionMinLen=32;
|
const int TransactionMinLen=32;
|
||||||
|
|||||||
Reference in New Issue
Block a user