Use STPathSet in place of STPath in transactions.

This commit is contained in:
Arthur Britto
2012-05-20 23:43:02 -07:00
parent 261fab7108
commit 1e9304f8c6
9 changed files with 16 additions and 17 deletions

View File

@@ -429,7 +429,7 @@ Json::Value RPCServer::doSend(Json::Value& params)
} }
else else
{ {
STPath spPaths; STPathSet spPaths;
Transaction::pointer trans = Transaction::sharedPayment( Transaction::pointer trans = Transaction::sharedPayment(
naAccountPublic, naAccountPrivate, naAccountPublic, naAccountPrivate,
naSrcAccountID, naSrcAccountID,

View File

@@ -564,12 +564,12 @@ void STObject::setValueFieldAmount(SOE_Field field, const STAmount &v)
(*cf) = v; (*cf) = v;
} }
void STObject::setValueFieldPath(SOE_Field field, const STPath &v) void STObject::setValueFieldPathSet(SOE_Field field, const STPathSet &v)
{ {
SerializedType* rf = getPField(field); SerializedType* rf = getPField(field);
if (!rf) throw std::runtime_error("Field not found"); if (!rf) throw std::runtime_error("Field not found");
if (rf->getSType() == STI_NOTPRESENT) rf = makeFieldPresent(field); if (rf->getSType() == STI_NOTPRESENT) rf = makeFieldPresent(field);
STPath* cf = dynamic_cast<STPath*>(rf); STPathSet* cf = dynamic_cast<STPathSet*>(rf);
if (!cf) throw std::runtime_error("Wrong field type"); if (!cf) throw std::runtime_error("Wrong field type");
(*cf) = v; (*cf) = v;
} }

View File

@@ -161,7 +161,7 @@ public:
void setValueFieldAccount(SOE_Field field, const NewcoinAddress& addr) void setValueFieldAccount(SOE_Field field, const NewcoinAddress& addr)
{ setValueFieldAccount(field, addr.getAccountID()); } { setValueFieldAccount(field, addr.getAccountID()); }
void setValueFieldAmount(SOE_Field field, const STAmount&); void setValueFieldAmount(SOE_Field field, const STAmount&);
void setValueFieldPath(SOE_Field field, const STPath&); void setValueFieldPathSet(SOE_Field field, const STPathSet&);
bool isFieldPresent(SOE_Field field) const; bool isFieldPresent(SOE_Field field) const;
SerializedType* makeFieldPresent(SOE_Field field); SerializedType* makeFieldPresent(SOE_Field field);

View File

@@ -101,8 +101,8 @@ public:
{ return mInnerTxn.setValueFieldAccount(field, v); } { return mInnerTxn.setValueFieldAccount(field, v); }
void setITFieldAmount(SOE_Field field, const STAmount& v) void setITFieldAmount(SOE_Field field, const STAmount& v)
{ return mInnerTxn.setValueFieldAmount(field, v); } { return mInnerTxn.setValueFieldAmount(field, v); }
void setITFieldPath(SOE_Field field, const STPath& v) void setITFieldPathSet(SOE_Field field, const STPathSet& v)
{ return mInnerTxn.setValueFieldPath(field, v); } { return mInnerTxn.setValueFieldPathSet(field, v); }
// optional field functions // optional field functions
bool getITFieldPresent(SOE_Field field) const; bool getITFieldPresent(SOE_Field field) const;

View File

@@ -406,3 +406,4 @@ void STPathSet::add(Serializer& s) const
} }
s.add8(STPathElement::typeEnd); s.add8(STPathElement::typeEnd);
} }
// vim:ts=4

View File

@@ -469,8 +469,8 @@ public:
bool isEmpty() const { return mPath.empty(); } bool isEmpty() const { return mPath.empty(); }
const STPathElement& getElement(int offset) const { return mPath[offset]; } const STPathElement& getElement(int offset) const { return mPath[offset]; }
const STPathElement& getElemet(int offset) { return mPath[offset]; } const STPathElement& getElemet(int offset) { return mPath[offset]; }
void addElement(const STPathElement& e) { mPath.push_back(e); } void addElement(const STPathElement& e) { mPath.push_back(e); }
void clear() { mPath.clear(); } void clear() { mPath.clear(); }
int getSerializeSize() const { return 1 + mPath.size() * 21; } int getSerializeSize() const { return 1 + mPath.size() * 21; }
std::string getText() const; std::string getText() const;
Json::Value getJson(int) const; Json::Value getJson(int) const;

View File

@@ -191,21 +191,19 @@ Transaction::pointer Transaction::setPayment(
const NewcoinAddress& toAccount, const NewcoinAddress& toAccount,
const STAmount& saAmount, const STAmount& saAmount,
const STAmount& saSendMax, const STAmount& saSendMax,
const STPath& spPaths) const STPathSet& spPaths)
{ {
mTransaction->setITFieldAccount(sfDestination, toAccount); mTransaction->setITFieldAccount(sfDestination, toAccount);
mTransaction->setITFieldAmount(sfAmount, saAmount); mTransaction->setITFieldAmount(sfAmount, saAmount);
if (saAmount != saSendMax) if (saAmount != saSendMax)
{ {
mTransaction->makeITFieldPresent(sfSendMax);
mTransaction->setITFieldAmount(sfSendMax, saSendMax); mTransaction->setITFieldAmount(sfSendMax, saSendMax);
} }
if (!spPaths.emptyPath()) if (spPaths.getPathCount())
{ {
mTransaction->makeITFieldPresent(sfPaths); mTransaction->setITFieldPathSet(sfPaths, spPaths);
mTransaction->setITFieldPath(sfPaths, spPaths);
} }
sign(naPrivateKey); sign(naPrivateKey);
@@ -222,7 +220,7 @@ Transaction::pointer Transaction::sharedPayment(
const NewcoinAddress& toAccount, const NewcoinAddress& toAccount,
const STAmount& saAmount, const STAmount& saAmount,
const STAmount& saSendMax, const STAmount& saSendMax,
const STPath& saPaths) const STPathSet& saPaths)
{ {
pointer tResult = boost::make_shared<Transaction>(ttPAYMENT, pointer tResult = boost::make_shared<Transaction>(ttPAYMENT,
naPublicKey, naSourceAccount, naPublicKey, naSourceAccount,

View File

@@ -62,7 +62,7 @@ private:
const NewcoinAddress& toAccount, const NewcoinAddress& toAccount,
const STAmount& saAmount, const STAmount& saAmount,
const STAmount& saSendMax, const STAmount& saSendMax,
const STPath& spPaths); const STPathSet& spPaths);
public: public:
Transaction(const SerializedTransaction::pointer st, bool bValidate); Transaction(const SerializedTransaction::pointer st, bool bValidate);
@@ -106,7 +106,7 @@ public:
const NewcoinAddress& toAccount, const NewcoinAddress& toAccount,
const STAmount& saAmount, const STAmount& saAmount,
const STAmount& saSendMax, const STAmount& saSendMax,
const STPath& saPaths); const STPathSet& saPaths);
bool sign(const NewcoinAddress& naAccountPrivate); bool sign(const NewcoinAddress& naAccountPrivate);
bool checkSign() const; bool checkSign() const;

View File

@@ -10,7 +10,7 @@ TransactionFormat InnerTxnFormats[]=
{ S_FIELD(Destination), STI_ACCOUNT, SOE_REQUIRED, 0 }, { S_FIELD(Destination), STI_ACCOUNT, SOE_REQUIRED, 0 },
{ S_FIELD(Amount), STI_AMOUNT, SOE_REQUIRED, 0 }, { S_FIELD(Amount), STI_AMOUNT, SOE_REQUIRED, 0 },
{ S_FIELD(SendMax), STI_AMOUNT, SOE_IFFLAG, 1 }, { S_FIELD(SendMax), STI_AMOUNT, SOE_IFFLAG, 1 },
{ S_FIELD(Paths), STI_PATH, SOE_IFFLAG, 2 }, { S_FIELD(Paths), STI_PATHSET, SOE_IFFLAG, 2 },
{ S_FIELD(SourceTag), STI_UINT32, SOE_IFFLAG, 4 }, { S_FIELD(SourceTag), STI_UINT32, SOE_IFFLAG, 4 },
{ S_FIELD(InvoiceID), STI_HASH256, SOE_IFFLAG, 8 }, { S_FIELD(InvoiceID), STI_HASH256, SOE_IFFLAG, 8 },
{ S_FIELD(Extensions), STI_TL, SOE_IFFLAG, 0x02000000 }, { S_FIELD(Extensions), STI_TL, SOE_IFFLAG, 0x02000000 },