diff --git a/src/SerializedObject.cpp b/src/SerializedObject.cpp index 18117d29a..2f8ea20a3 100644 --- a/src/SerializedObject.cpp +++ b/src/SerializedObject.cpp @@ -350,6 +350,17 @@ uint256 STObject::getValueFieldH256(SOE_Field field) const return cf->getValue(); } +NewcoinAddress STObject::getValueFieldAccount(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_OBJECT) return NewcoinAddress(); // optional field not present + const STAccount* cf = dynamic_cast(rf); + if (!cf) throw std::runtime_error("Wrong field type"); + return cf->getValueNCA(); +} + std::vector STObject::getValueFieldVL(SOE_Field field) const { const SerializedType* rf = peekAtPField(field); diff --git a/src/SerializedObject.h b/src/SerializedObject.h index ce2bbb9f8..b97fd286f 100644 --- a/src/SerializedObject.h +++ b/src/SerializedObject.h @@ -102,6 +102,7 @@ public: uint64 getValueFieldU64(SOE_Field field) const; uint160 getValueFieldH160(SOE_Field field) const; uint256 getValueFieldH256(SOE_Field field) const; + NewcoinAddress getValueFieldAccount(SOE_Field field) const; std::vector getValueFieldVL(SOE_Field field) const; std::vector getValueFieldTL(SOE_Field field) const; @@ -114,6 +115,8 @@ public: void setValueFieldVL(SOE_Field field, const std::vector&); void setValueFieldTL(SOE_Field field, const std::vector&); void setValueFieldAccount(SOE_Field field, const uint160&); + void setValueFieldAccount(SOE_Field field, const NewcoinAddress& addr) + { setValueFieldAccount(field, addr.getAccountID()); } bool isFieldPresent(SOE_Field field) const; void makeFieldPresent(SOE_Field field);