Fix requestTransactionEntry arguments, add flexibility to remote.transaction

This commit is contained in:
wltsmrz
2014-01-07 01:23:54 -08:00
parent 848c203b81
commit 626164a8ab
2 changed files with 59 additions and 10 deletions

View File

@@ -513,7 +513,7 @@ Remote.isValidLedgerData = function(ledger) {
&& (typeof ledger.ledger_time === 'number')
&& (typeof ledger.reserve_base === 'number')
&& (typeof ledger.reserve_inc === 'number')
&& (typeof ledger.txn_count === 'number')
&& (typeof ledger.txn_count === 'number');
};
Remote.isLoadStatus = function(message) {
@@ -781,6 +781,14 @@ Remote.prototype.requestTransactionEntry = function(hash, ledger_hash, callback)
request.ledgerHash(ledger_hash);
break;
case 'number':
request.ledgerIndex(ledger_hash);
break;
case 'function':
request.callback(ledger_hash);
break;
default:
request.ledgerIndex('validated');
callback = ledger_hash;
@@ -1450,17 +1458,57 @@ Remote.prototype.requestConnect = function(ip, port, callback) {
return request;
};
Remote.prototype.transaction = function(source, destination, amount, callback) {
var tx = new Transaction(this);
Remote.prototype.createTransaction =
Remote.prototype.transaction = function(source, options, callback) {
var transaction = new Transaction(this);
if (arguments.length >= 3) {
tx = tx.payment(source, destination, amount);
if (typeof callback === 'function') {
tx.submit(callback);
}
var transactionTypes = {
payment: 'payment',
accountset: 'accountSet',
trustset: 'trustSet',
offercreate: 'offerCreate',
offercancel: 'offerCancel',
sign: 'sign'
}
return tx;
var transactionType;
switch (typeof source) {
case 'object':
if (typeof source.type !== 'string') {
throw new Error('Missing transaction type');
}
transactionType = transactionTypes[source.type.toLowerCase()];
if (!transactionType) {
throw new Error('Invalid transaction type: ' + transactionType);
}
transaction = transaction[transactionType](source);
break;
case 'string':
transactionType = source.toLowerCase();
if (!transactionType) {
throw new Error('Invalid transaction type: ' + transactionType);
}
transaction = transaction[transactionType](options);
break;
default:
throw new Error('Argument must be string or object: ' + source);
}
var lastArg = arguments[arguments.length - 1];
if (typeof lastArg === 'function') {
transaction.submit(lastArg);
}
return transaction;
};
/**

View File

@@ -621,6 +621,7 @@ Transaction.prototype.payment = function(src, dst, amount) {
return this;
};
Transaction.prototype.trustSet =
Transaction.prototype.rippleLineSet = function(src, limit, quality_in, quality_out) {
if (typeof src === 'object') {
var options = src;