mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
STAmount helpers for STObject/STTransaction.
This commit is contained in:
@@ -429,6 +429,17 @@ std::vector<TaggedListItem> STObject::getValueFieldTL(SOE_Field field) const
|
||||
return cf->getValue();
|
||||
}
|
||||
|
||||
STAmount STObject::getValueFieldAmount(SOE_Field field) const
|
||||
{
|
||||
const SerializedType* rf = peekAtPField(field);
|
||||
if (!rf) throw std::runtime_error("Field not found");
|
||||
SerializedTypeID id = rf->getSType();
|
||||
if (id == STI_NOTPRESENT) return STAmount(); // optional field not present
|
||||
const STAmount *cf = dynamic_cast<const STAmount *>(rf);
|
||||
if (!cf) throw std::runtime_error("Wrong field type");
|
||||
return *cf;
|
||||
}
|
||||
|
||||
void STObject::setValueFieldU8(SOE_Field field, unsigned char v)
|
||||
{
|
||||
SerializedType* rf = getPField(field);
|
||||
@@ -519,6 +530,16 @@ void STObject::setValueFieldTL(SOE_Field field, const std::vector<TaggedListItem
|
||||
cf->setValue(v);
|
||||
}
|
||||
|
||||
void STObject::setValueFieldAmount(SOE_Field field, const STAmount &v)
|
||||
{
|
||||
SerializedType* rf = getPField(field);
|
||||
if (!rf) throw std::runtime_error("Field not found");
|
||||
if (rf->getSType() == STI_NOTPRESENT) rf = makeFieldPresent(field);
|
||||
STAmount* cf = dynamic_cast<STAmount*>(rf);
|
||||
if (!cf) throw std::runtime_error("Wrong field type");
|
||||
(*cf) = v;
|
||||
}
|
||||
|
||||
Json::Value STObject::getJson(int options) const
|
||||
{
|
||||
Json::Value ret(Json::objectValue);
|
||||
|
||||
@@ -145,6 +145,7 @@ public:
|
||||
NewcoinAddress getValueFieldAccount(SOE_Field field) const;
|
||||
std::vector<unsigned char> getValueFieldVL(SOE_Field field) const;
|
||||
std::vector<TaggedListItem> getValueFieldTL(SOE_Field field) const;
|
||||
STAmount getValueFieldAmount(SOE_Field field) const;
|
||||
|
||||
void setValueFieldU8(SOE_Field field, unsigned char);
|
||||
void setValueFieldU16(SOE_Field field, uint16);
|
||||
@@ -157,6 +158,7 @@ public:
|
||||
void setValueFieldAccount(SOE_Field field, const uint160&);
|
||||
void setValueFieldAccount(SOE_Field field, const NewcoinAddress& addr)
|
||||
{ setValueFieldAccount(field, addr.getAccountID()); }
|
||||
void setValueFieldAmount(SOE_Field field, const STAmount&);
|
||||
|
||||
bool isFieldPresent(SOE_Field field) const;
|
||||
SerializedType* makeFieldPresent(SOE_Field field);
|
||||
|
||||
@@ -84,6 +84,7 @@ public:
|
||||
uint256 getITFieldH256(SOE_Field field) const { return mInnerTxn.getValueFieldH256(field); }
|
||||
std::vector<unsigned char> getITFieldVL(SOE_Field field) const { return mInnerTxn.getValueFieldVL(field); }
|
||||
std::vector<TaggedListItem> getITFieldTL(SOE_Field field) const { return mInnerTxn.getValueFieldTL(field); }
|
||||
STAmount getITFieldAmount(SOE_Field field) const { return mInnerTxn.getValueFieldAmount(field); }
|
||||
void setITFieldU8(SOE_Field field, unsigned char v) { return mInnerTxn.setValueFieldU8(field, v); }
|
||||
void setITFieldU16(SOE_Field field, uint16 v) { return mInnerTxn.setValueFieldU16(field, v); }
|
||||
void setITFieldU32(SOE_Field field, uint32 v) { return mInnerTxn.setValueFieldU32(field, v); }
|
||||
@@ -98,6 +99,8 @@ public:
|
||||
{ return mInnerTxn.setValueFieldAccount(field, v); }
|
||||
void setITFieldAccount(SOE_Field field, const NewcoinAddress& v)
|
||||
{ return mInnerTxn.setValueFieldAccount(field, v); }
|
||||
void setITFieldAmount(SOE_Field field, const STAmount& v)
|
||||
{ return mInnerTxn.setValueFieldAmount(field, v); }
|
||||
|
||||
// optional field functions
|
||||
bool getITFieldPresent(SOE_Field field) const;
|
||||
|
||||
Reference in New Issue
Block a user