Merge branch 'develop' of github.com:emschwartz/ripple-lib into newdocs

just merging with remote
This commit is contained in:
Evan Schwartz
2013-09-06 15:16:28 -07:00
5 changed files with 89 additions and 49 deletions

View File

@@ -838,8 +838,7 @@ Remote.prototype.request_account_tx = function (obj, callback) {
//extended account_tx
, 'forward' //false
, 'fwd_marker'
, 'rev_marker'
, 'marker'
];
for (var key in obj) {

View File

@@ -2,11 +2,14 @@ var util = require('util');
var extend = require('extend');
function RippleError(code, message) {
if (typeof code === 'object') {
extend(this, code);
} else {
this.result = code;
this.result_message = message;
switch (typeof code) {
case 'object':
extend(this, code);
break;
case 'string':
this.result = code;
this.result_message = message;
break;
}
this.result = this.result || this.error || 'Error';

View File

@@ -57,19 +57,6 @@ SerializedObject.prototype.resetPointer = function () {
this.pointer = 0;
};
/*
SerializedObject.prototype.read = function (numberOfBytes) {
var start = this.pointer;
var end = start+numberOfBytes;
if (end > this.buffer.length) {
throw new Error("There aren't that many bytes left to read.");
} else {
var result = this.buffer.slice(start,end);
this.pointer = end;
return result;
}
};
*/
var readOrPeek = function (advance) {
return function(numberOfBytes) {
@@ -113,6 +100,45 @@ var TRANSACTION_TYPES = {
101:"SetFee"
};
var LEDGER_ENTRY_TYPES = {
97:"AccountRoot",
99:"Contract",
100:"DirectoryNode",
102:"Features",
103:"GeneratorMap",
104:"LedgerHashes",
110:"Nickname",
111:"Offer",
114:"RippleState",
115:"FeeSettings"
};
var TRANSACTION_RESULTS = {
0 :"tesSUCCESS",
100:"tecCLAIM",
101:"tecPATH_PARTIAL",
102:"tecUNFUNDED_ADD",
103:"tecUNFUNDED_OFFER",
104:"tecUNFUNDED_PAYMENT",
105:"tecFAILED_PROCESSING",
121:"tecDIR_FULL",
122:"tecINSUF_RESERVE_LINE",
123:"tecINSUF_RESERVE_OFFER",
124:"tecNO_DST",
125:"tecNO_DST_INSUF_XRP",
126:"tecNO_LINE_INSUF_RESERVE",
127:"tecNO_LINE_REDUNDANT",
128:"tecPATH_DRY",
129:"tecUNFUNDED", // Deprecated, old ambiguous unfunded.
130:"tecMASTER_DISABLED",
131:"tecNO_REGULAR_KEY",
132:"tecOWNERS"
};
SerializedObject.prototype.to_json = function() {
var old_pointer = this.pointer;
this.resetPointer();
@@ -139,7 +165,9 @@ function jsonify_structure(thing,field_name) {
if ("number" === typeof thing) { //Special codes
if (field_name) {
if (field_name === "LedgerEntryType") {
output = thing; //TODO: Do we have special codes for LedgerEntryType?
output = LEDGER_ENTRY_TYPES[thing] || thing;
} else if (field_name === "TransactionResult") {
output = TRANSACTION_RESULTS[thing] || thing;
} else if (field_name === "TransactionType") {
output = TRANSACTION_TYPES[thing] || thing;
} else {
@@ -166,7 +194,7 @@ function jsonify_structure(thing,field_name) {
for (var i=0; i<keys.length; i++) {
var key = keys[i];
var value = thing[key];
output[key] = jsonify_structure(value);
output[key] = jsonify_structure(value,key);
}
} else {
output = thing;

View File

@@ -74,10 +74,10 @@ function Transaction(remote) {
this.hash = void(0);
// ledger_current_index was this when transaction was submited.
this.submit_index = void(0);
this.submit_index = void(0);
// Under construction.
this.state = void(0);
this.state = void(0);
this.finalized = false;
this._previous_signing_hash = void(0);
@@ -208,7 +208,7 @@ Transaction.prototype.sign = function () {
var seed = Seed.from_json(this._secret);
var hash = this.signing_hash();
var previously_signed = this.tx_json.TxnSignature
var previously_signed = this.tx_json.TxnSignature
&& hash === this._previous_signing_hash;
if (previously_signed) return;
@@ -232,7 +232,7 @@ Transaction.prototype.build_path = function (build) {
return this;
}
// tag should be undefined or a 32 bit integer.
// tag should be undefined or a 32 bit integer.
// YYY Add range checking for tag.
Transaction.prototype.destination_tag = function (tag) {
if (tag !== void(0)) {
@@ -242,19 +242,19 @@ Transaction.prototype.destination_tag = function (tag) {
}
Transaction._path_rewrite = function (path) {
var props = [
'account'
, 'issuer'
, 'currency'
]
var path_new = path.map(function(node) {
var node_new = { };
for (var prop in node) {
if (~props.indexOf(prop)) {
node_new[prop] = UInt160.json_rewrite(node[prop]);
}
if (node.hasOwnProperty('account')) {
node_new.account = UInt160.json_rewrite(node.account);
}
if (node.hasOwnProperty('issuer')) {
node_new.issuer = UInt160.json_rewrite(node.issuer);
}
if (node.hasOwnProperty('currency')) {
node_new.currency = Currency.json_rewrite(node.currency);
}
return node_new;
@@ -290,7 +290,7 @@ Transaction.prototype.send_max = function (send_max) {
return this;
};
// tag should be undefined or a 32 bit integer.
// tag should be undefined or a 32 bit integer.
// YYY Add range checking for tag.
Transaction.prototype.source_tag = function (tag) {
if (tag) {

View File

@@ -242,11 +242,15 @@ TransactionManager.prototype._request = function(tx) {
}
function submission_error(error) {
//Decrement sequence
self._next_sequence--;
tx.set_state('remoteError');
tx.emit('submitted', error);
tx.emit('error', new RippleError(error));
if (self._is_too_busy(error)) {
self._resubmit(1);
} else {
//Decrement sequence
self._next_sequence--;
tx.set_state('remoteError');
tx.emit('submitted', error);
tx.emit('error', new RippleError(error));
}
}
function submission_success(message) {
@@ -254,11 +258,11 @@ TransactionManager.prototype._request = function(tx) {
tx.hash = message.tx_json.hash;
}
message.result = message.engine_result || '';
tx.emit('submitted', message);
var engine_result = message.engine_result || '';
switch (engine_result.slice(0, 3)) {
switch (message.result.slice(0, 3)) {
case 'tec':
tx.emit('error', message);
break;
@@ -294,12 +298,18 @@ TransactionManager.prototype._request = function(tx) {
return submit_request;
};
TransactionManager.prototype._is_not_found = function(error) {
var not_found_re = /^(txnNotFound|transactionNotFound)$/;
TransactionManager.prototype._is_remote_error = function(error) {
return error && typeof error === 'object'
&& error.error === 'remoteError'
&& typeof error.remote === 'object'
&& not_found_re.test(error.remote.error);
};
TransactionManager.prototype._is_not_found = function(error) {
return this._is_remote_error(error) && /^(txnNotFound|transactionNotFound)$/.test(error.remote.error);
};
TransactionManager.prototype._is_too_busy = function(error) {
return this._is_remote_error(error) && error.remote.error === 'tooBusy';
};
/**
@@ -341,7 +351,7 @@ TransactionManager.prototype.submit = function(tx) {
tx.emit('error', new RippleError('tejAbort', 'Transaction aborted'));
});
var fee = tx.tx_json.Fee;
var fee = Number(tx.tx_json.Fee);
var remote = this.remote;
if (!tx._secret && !tx.tx_json.TxnSignature) {