mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-22 13:15:49 +00:00
Fix requestTransactionEntry arguments, add flexibility to remote.transaction
This commit is contained in:
@@ -513,7 +513,7 @@ Remote.isValidLedgerData = function(ledger) {
|
|||||||
&& (typeof ledger.ledger_time === 'number')
|
&& (typeof ledger.ledger_time === 'number')
|
||||||
&& (typeof ledger.reserve_base === 'number')
|
&& (typeof ledger.reserve_base === 'number')
|
||||||
&& (typeof ledger.reserve_inc === 'number')
|
&& (typeof ledger.reserve_inc === 'number')
|
||||||
&& (typeof ledger.txn_count === 'number')
|
&& (typeof ledger.txn_count === 'number');
|
||||||
};
|
};
|
||||||
|
|
||||||
Remote.isLoadStatus = function(message) {
|
Remote.isLoadStatus = function(message) {
|
||||||
@@ -781,6 +781,14 @@ Remote.prototype.requestTransactionEntry = function(hash, ledger_hash, callback)
|
|||||||
request.ledgerHash(ledger_hash);
|
request.ledgerHash(ledger_hash);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'number':
|
||||||
|
request.ledgerIndex(ledger_hash);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'function':
|
||||||
|
request.callback(ledger_hash);
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
request.ledgerIndex('validated');
|
request.ledgerIndex('validated');
|
||||||
callback = ledger_hash;
|
callback = ledger_hash;
|
||||||
@@ -1450,17 +1458,57 @@ Remote.prototype.requestConnect = function(ip, port, callback) {
|
|||||||
return request;
|
return request;
|
||||||
};
|
};
|
||||||
|
|
||||||
Remote.prototype.transaction = function(source, destination, amount, callback) {
|
Remote.prototype.createTransaction =
|
||||||
var tx = new Transaction(this);
|
Remote.prototype.transaction = function(source, options, callback) {
|
||||||
|
var transaction = new Transaction(this);
|
||||||
|
|
||||||
if (arguments.length >= 3) {
|
var transactionTypes = {
|
||||||
tx = tx.payment(source, destination, amount);
|
payment: 'payment',
|
||||||
if (typeof callback === 'function') {
|
accountset: 'accountSet',
|
||||||
tx.submit(callback);
|
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;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -621,6 +621,7 @@ Transaction.prototype.payment = function(src, dst, amount) {
|
|||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Transaction.prototype.trustSet =
|
||||||
Transaction.prototype.rippleLineSet = function(src, limit, quality_in, quality_out) {
|
Transaction.prototype.rippleLineSet = function(src, limit, quality_in, quality_out) {
|
||||||
if (typeof src === 'object') {
|
if (typeof src === 'object') {
|
||||||
var options = src;
|
var options = src;
|
||||||
|
|||||||
Reference in New Issue
Block a user