Skip to content

Commit d3b6b81

Browse files
committed
[FIX] transaction without explicit remote
remote was instantiated as an object and checks through the class for `this.remote` would pass and cause unintended behavior e.g. `.complete()` would view an undefined remote as untrusted and not allow local signing e.g. calling `_computeFee()` with an undefined remote would crash ripple-lib
1 parent bc1f9f8 commit d3b6b81

File tree

2 files changed

+38
-3
lines changed

2 files changed

+38
-3
lines changed

src/js/ripple/transaction.js

+11-3
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ function Transaction(remote) {
6060

6161
var self = this;
6262

63-
var remote = remote || { };
63+
var remote = remote || void(0);
6464

6565
this.remote = remote;
6666

@@ -69,7 +69,7 @@ function Transaction(remote) {
6969

7070
this._secret = void(0);
7171
this._build_path = false;
72-
this._maxFee = this.remote.max_fee;
72+
this._maxFee = (typeof remote === 'object') ? this.remote.max_fee : void(0);
7373

7474
this.state = 'unsubmitted';
7575
this.finalized = false;
@@ -241,7 +241,7 @@ Transaction.prototype.finalize = function(message) {
241241
};
242242

243243
Transaction.prototype._accountSecret = function(account) {
244-
return this.remote.secrets[account];
244+
return this.remote ? this.remote.secrets[account] : void(0);
245245
};
246246

247247
/**
@@ -266,6 +266,10 @@ Transaction.prototype.feeUnits = function() {
266266
*/
267267

268268
Transaction.prototype._computeFee = function() {
269+
if (!this.remote) {
270+
return void(0);
271+
}
272+
269273
var servers = this.remote._servers;
270274
var fees = [ ];
271275

@@ -898,6 +902,10 @@ Transaction.prototype.submit = function(callback) {
898902

899903
var account = this.tx_json.Account;
900904

905+
if (!this.remote) {
906+
return this.emit('error', new Error('No remote found'));
907+
}
908+
901909
if (!UInt160.is_valid(account)) {
902910
return this.emit('error', new RippleError('tejInvalidAccount', 'Account is missing or invalid'));
903911
}

test/transaction-test.js

+27
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,11 @@ describe('Transaction', function() {
229229
assert.strictEqual(transaction._computeFee(), '72');
230230
});
231231

232+
it('Compute fee, no remote', function() {
233+
var transaction = new Transaction();
234+
assert.strictEqual(transaction._computeFee(10), void(0));
235+
});
236+
232237
it('Compute fee - no connected server', function() {
233238
var remote = new Remote();
234239

@@ -371,6 +376,16 @@ describe('Transaction', function() {
371376
done();
372377
});
373378

379+
it('Complete transaction, local signing, no remote', function(done) {
380+
var transaction = new Transaction();
381+
transaction._secret = 'sh2pTicynUEG46jjR4EoexHcQEoij';
382+
transaction.tx_json.Account = 'rMWwx3Ma16HnqSd4H6saPisihX9aKpXxHJ';
383+
384+
assert(transaction.complete());
385+
386+
done();
387+
});
388+
374389
it('Complete transaction - untrusted', function(done) {
375390
var remote = new Remote();
376391
var transaction = new Transaction(remote);
@@ -1505,6 +1520,18 @@ describe('Transaction', function() {
15051520
transaction.submit(submitCallback);
15061521
});
15071522

1523+
it('Submit transaction - submission error, no remote', function(done) {
1524+
var transaction = new Transaction();
1525+
1526+
transaction.once('error', function(error) {
1527+
assert(error);
1528+
assert.strictEqual(error.message, 'No remote found');
1529+
done();
1530+
});
1531+
1532+
transaction.submit();
1533+
});
1534+
15081535
it('Submit transaction - invalid account', function(done) {
15091536
var remote = new Remote();
15101537
var transaction = new Transaction(remote).accountSet('r36xtKNKR43SeXnGn7kN4r4JdQzcrkqpWe');

0 commit comments

Comments
 (0)