Avoid the getValue confusion. Use getNValue for native, getMantissa otherwise

This commit is contained in:
JoelKatz
2012-05-27 18:23:33 -07:00
parent faa3e00aa8
commit 959fa8e298
3 changed files with 12 additions and 10 deletions

View File

@@ -721,9 +721,9 @@ uint64 getRate(const STAmount& offerOut, const STAmount& offerIn)
if (offerOut.isZero()) throw std::runtime_error("Worthless offer");
STAmount r = divide(offerIn, offerOut, uint160(1));
assert((r.getOffset() >= -100) && (r.getOffset() <= 155));
uint64 ret = r.getOffset() + 100;
return (ret << (64 - 8)) | r.getValue();
assert((r.getExponent() >= -100) && (r.getExponent() <= 155));
uint64 ret = r.getExponent() + 100;
return (ret << (64 - 8)) | r.getMantissa();
}
STAmount getClaimed(STAmount& offerOut, STAmount& offerIn, STAmount& paid)
@@ -786,8 +786,7 @@ static uint64_t muldiv(uint64_t a, uint64_t b, uint64_t c)
uint64 convertToDisplayAmount(const STAmount& internalAmount, uint64_t totalNow, uint64_t totalInit)
{ // Convert an internal ledger/account quantity of native currency to a display amount
if (internalAmount.isNative()) throw std::runtime_error("not native curency");
return muldiv(internalAmount.getValue(), totalInit, totalNow);
return muldiv(internalAmount.getNValue(), totalInit, totalNow);
}
STAmount convertToInternalAmount(uint64_t displayAmount, uint64_t totalNow, uint64_t totalInit,

View File

@@ -164,14 +164,14 @@ STAmount SerializedTransaction::getTransactionFee() const
{
const STAmount* v = dynamic_cast<const STAmount*>(mMiddleTxn.peekAtPIndex(TransactionIFee));
if (!v) throw std::runtime_error("corrupt transaction");
return v->getValue();
return v->getNValue();
}
void SerializedTransaction::setTransactionFee(STAmount saFee)
{
STAmount* v = dynamic_cast<STAmount*>(mMiddleTxn.getPIndex(TransactionIFee));
if (!v) throw std::runtime_error("corrupt transaction");
v->setValue(saFee);
v->setNValue(saFee);
}
uint32 SerializedTransaction::getSequence() const

View File

@@ -253,9 +253,12 @@ public:
std::string getRaw() const;
void add(Serializer& s) const;
int getOffset() const { return mOffset; }
uint64 getValue() const { return mValue; }
void setValue(const STAmount& v) { mValue=v; }
int getExponent() const { return mOffset; }
uint64 getMantissa() const { return mValue; }
uint64 getNValue() const { if (!mIsNative) throw std::runtime_error("not native"); return mValue; }
void setNValue(uint64_t v) { if (!mIsNative) throw std::runtime_error("not native"); mValue = v; }
std::string getCurrencyHuman();
bool isNative() const { return mIsNative; }