Merge branch 'master' of github.com:jedmccaleb/NewCoin

This commit is contained in:
Arthur Britto
2012-11-24 14:08:34 -08:00
7 changed files with 53 additions and 136 deletions

View File

@@ -114,9 +114,9 @@ public:
NetworkOPs(boost::asio::io_service& io_service, LedgerMaster* pLedgerMaster);
// network information
uint32 getNetworkTimeNC();
uint32 getCloseTimeNC();
uint32 getValidationTimeNC();
uint32 getNetworkTimeNC(); // Our best estimate of wall time in seconds from 1/1/2000
uint32 getCloseTimeNC(); // Our best estimate of current ledger close time
uint32 getValidationTimeNC(); // Use *only* to timestamp our own validation
void closeTimeOffset(int);
boost::posix_time::ptime getNetworkTimePT();
uint32 getLedgerID(const uint256& hash);

View File

@@ -2,23 +2,23 @@
// appropriate #define statements.
// types (common)
TYPE("Int16", UINT16, 1)
TYPE("Int32", UINT32, 2)
TYPE("Int64", UINT64, 3)
TYPE("Hash128", HASH128, 4)
TYPE("Hash256", HASH256, 5)
TYPE("Amount", AMOUNT, 6)
TYPE("VariableLength", VL, 7)
TYPE("Account", ACCOUNT, 8)
TYPE(Int16, UINT16, 1)
TYPE(Int32, UINT32, 2)
TYPE(Int64, UINT64, 3)
TYPE(Hash128, HASH128, 4)
TYPE(Hash256, HASH256, 5)
TYPE(Amount, AMOUNT, 6)
TYPE(VariableLength, VL, 7)
TYPE(Account, ACCOUNT, 8)
// 9-13 are reserved
TYPE("Object", OBJECT, 14)
TYPE("Array", ARRAY, 15)
TYPE(Object, OBJECT, 14)
TYPE(Array, ARRAY, 15)
// types (uncommon)
TYPE("Int8", UINT8, 16)
TYPE("Hash160", HASH160, 17)
TYPE("PathSet", PATHSET, 18)
TYPE("Vector256", VECTOR256, 19)
TYPE(Int8, UINT8, 16)
TYPE(Hash160, HASH160, 17)
TYPE(PathSet, PATHSET, 18)
TYPE(Vector256, VECTOR256, 19)

View File

@@ -116,7 +116,6 @@ public:
RippleAddress getFieldAccount(SField::ref field) const;
uint160 getFieldAccount160(SField::ref field) const;
std::vector<unsigned char> getFieldVL(SField::ref field) const;
std::vector<TaggedListItem> getFieldTL(SField::ref field) const;
STAmount getFieldAmount(SField::ref field) const;
STPathSet getFieldPathSet(SField::ref field) const;
STVector256 getFieldV256(SField::ref field) const;
@@ -129,7 +128,6 @@ public:
void setFieldH160(SField::ref field, const uint160&);
void setFieldH256(SField::ref field, const uint256&);
void setFieldVL(SField::ref field, const std::vector<unsigned char>&);
void setFieldTL(SField::ref field, const std::vector<TaggedListItem>&);
void setFieldAccount(SField::ref field, const uint160&);
void setFieldAccount(SField::ref field, const RippleAddress& addr)
{ setFieldAccount(field, addr.getAccountID()); }

View File

@@ -380,64 +380,6 @@ int Serializer::addVL(const std::string& string)
return ret;
}
int Serializer::addTaggedList(const std::list<TaggedListItem>& list)
{
int size = list.size();
if (size > 255) return -1;
int ret = add8(size);
if (size != 0)
{
BOOST_FOREACH(const TaggedListItem& it, list)
{
add8(it.first);
addVL(it.second);
}
}
return ret;
}
int Serializer::addTaggedList(const std::vector<TaggedListItem>& list)
{
int size = list.size();
if (size > 255) return -1;
int ret = add8(size);
if (size != 0)
{
BOOST_FOREACH(const TaggedListItem& it, list)
{
add8(it.first);
addVL(it.second);
}
}
return ret;
}
int Serializer::getTaggedListLength(const std::list<TaggedListItem>& list)
{
int size = list.size();
if (size > 255) return -1;
int ret = 1;
if (size != 0)
{
BOOST_FOREACH(const TaggedListItem& it, list)
ret += 1 + it.second.size() + Serializer::encodeLengthLength(it.second.size());
}
return ret;
}
int Serializer::getTaggedListLength(const std::vector<TaggedListItem>& list)
{
int size = list.size();
if (size > 255) return -1;
int ret = 1;
if (size != 0)
{
BOOST_FOREACH(const TaggedListItem& it, list)
ret += 1 + it.second.size() + Serializer::encodeLengthLength(it.second.size());
}
return ret;
}
bool Serializer::getVL(std::vector<unsigned char>& objectVL, int offset, int& length) const
{
int b1;
@@ -503,44 +445,6 @@ bool Serializer::getVLLength(int& length, int offset) const
return true;
}
bool Serializer::getTaggedList(std::list<TaggedListItem>& list, int offset, int& length) const
{
list.clear();
int startOffset = offset;
int numElem;
if (!get8(numElem, offset++)) return false;
for (int i = 0; i<numElem; ++i)
{
int tag, len;
std::vector<unsigned char> data;
if (!get8(tag, offset++)) return false;
if (!getVL(data, offset, len)) return false;
offset += len;
list.push_back(std::make_pair(tag, data));
}
length = offset - startOffset;
return true;
}
bool Serializer::getTaggedList(std::vector<TaggedListItem>& list, int offset, int& length) const
{
list.clear();
int startOffset = offset;
int numElem;
if (!get8(numElem, offset++)) return false;
for (int i = 0; i<numElem; ++i)
{
int tag, len;
std::vector<unsigned char> data;
if (!get8(tag, offset++)) return false;
if (!getVL(data, offset, len)) return false;
offset += len;
list.push_back(std::make_pair(tag, data));
}
length = offset - startOffset;
return true;
}
std::vector<unsigned char> Serializer::encodeVL(int length)
{
unsigned char lenBytes[4];
@@ -692,15 +596,6 @@ std::vector<unsigned char> SerializerIterator::getVL()
return vl;
}
std::vector<TaggedListItem> SerializerIterator::getTaggedList()
{
int length;
std::vector<TaggedListItem> tl;
if (!mSerializer.getTaggedList(tl, mPos, length)) throw std::runtime_error("invalid serializer getTL");
mPos += length;
return tl;
}
std::vector<unsigned char> SerializerIterator::getRaw(int iLength)
{
int iPos = mPos;

View File

@@ -11,8 +11,6 @@
#include "uint256.h"
#include "FieldNames.h"
typedef std::pair<int, std::vector<unsigned char> > TaggedListItem;
class Serializer
{
public:
@@ -46,10 +44,6 @@ public:
int addVL(const std::vector<unsigned char> &vector);
int addVL(const std::string& string);
int addVL(const void *ptr, int len);
int addTaggedList(const std::list<TaggedListItem>&);
int addTaggedList(const std::vector<TaggedListItem>&);
static int getTaggedListLength(const std::list<TaggedListItem>&);
static int getTaggedListLength(const std::vector<TaggedListItem>&);
// disassemble functions
bool get8(int&, int offset) const;
@@ -66,8 +60,6 @@ public:
bool getVL(std::vector<unsigned char>& objectVL, int offset, int& length) const;
bool getVLLength(int& length, int offset) const;
bool getTaggedList(std::list<TaggedListItem>&, int offset, int& length) const;
bool getTaggedList(std::vector<TaggedListItem>&, int offset, int& length) const;
bool getFieldID(int& type, int& name, int offset) const;
int addFieldID(int type, int name);
@@ -171,7 +163,6 @@ public:
std::vector<unsigned char> getRaw(int iLength);
std::vector<unsigned char> getVL();
std::vector<TaggedListItem> getTaggedList();
};
#endif

View File

@@ -449,11 +449,34 @@ Amount.prototype.to_text = function(allow_nan) {
}
};
Amount.prototype.format_pretty = function ()
/**
* Format only value in a human-readable format.
*
* @example
* var pretty = amount.to_human({precision: 2});
*
* @param opts Options for formatter.
* @param opts.precision {Number} Max. number of digits after decimal point.
*/
Amount.prototype.to_human = function (opts)
{
this._value.mod(consts.bi_xns_unit);
opts = opts || {};
return "WOOOOO";
var int_part = this._value.divide(consts.bi_xns_unit).toString(10);
var fraction_part = this._value.mod(consts.bi_xns_unit).toString(10);
int_part = int_part.replace(/^0*/, '');
fraction_part = fraction_part.replace(/0*$/, '');
if ("number" === typeof opts.precision) {
fraction_part = fraction_part.slice(0, opts.precision);
}
var formatted = '';
formatted += int_part.length ? int_part : '0';
formatted += fraction_part.length ? '.'+fraction_part : '';
return formatted;
};
Amount.prototype.canonicalize = function() {