mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-20 04:05:52 +00:00
Merge pull request #589 from wltsmrz/multisign-update
Fix Transaction.complete() for multisigned transactions
This commit is contained in:
@@ -384,24 +384,32 @@ Transaction.prototype.err = function(error, errorMessage) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Transaction.prototype.complete = function() {
|
Transaction.prototype.complete = function() {
|
||||||
// Auto-fill the secret
|
const hasMultiSigners = this.hasMultiSigners();
|
||||||
this._secret = this._secret || this.getSecret();
|
|
||||||
|
|
||||||
if (_.isUndefined(this._secret)) {
|
if (!hasMultiSigners) {
|
||||||
return this.err('tejSecretUnknown', 'Missing secret');
|
// Auto-fill the secret
|
||||||
}
|
this._secret = this._secret || this.getSecret();
|
||||||
|
|
||||||
if (this.remote && !(this.remote.local_signing || this.remote.trusted)) {
|
if (_.isUndefined(this._secret)) {
|
||||||
return this.err(
|
return this.err('tejSecretUnknown', 'Missing secret');
|
||||||
'tejServerUntrusted',
|
}
|
||||||
'Attempt to give secret to untrusted server');
|
|
||||||
|
if (this.remote && !(this.remote.local_signing || this.remote.trusted)) {
|
||||||
|
return this.err(
|
||||||
|
'tejServerUntrusted',
|
||||||
|
'Attempt to give secret to untrusted server');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_.isUndefined(this.tx_json.SigningPubKey)) {
|
if (_.isUndefined(this.tx_json.SigningPubKey)) {
|
||||||
try {
|
if (hasMultiSigners) {
|
||||||
this.setSigningPubKey(this.getSigningPubKey());
|
this.setSigningPubKey('');
|
||||||
} catch (e) {
|
} else {
|
||||||
return this.err('tejSecretInvalid', 'Invalid secret');
|
try {
|
||||||
|
this.setSigningPubKey(this.getSigningPubKey());
|
||||||
|
} catch (e) {
|
||||||
|
return this.err('tejSecretInvalid', 'Invalid secret');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -724,6 +724,10 @@ TransactionManager.prototype.submit = function(tx) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tx.once('cleanup', function() {
|
||||||
|
self.getPending().remove(tx);
|
||||||
|
});
|
||||||
|
|
||||||
if (!_.isNumber(tx.tx_json.Sequence)) {
|
if (!_.isNumber(tx.tx_json.Sequence)) {
|
||||||
// Honor manually-set sequences
|
// Honor manually-set sequences
|
||||||
tx.setSequence(this._nextSequence++);
|
tx.setSequence(this._nextSequence++);
|
||||||
@@ -735,13 +739,8 @@ TransactionManager.prototype.submit = function(tx) {
|
|||||||
|
|
||||||
if (tx.hasMultiSigners()) {
|
if (tx.hasMultiSigners()) {
|
||||||
tx.setResubmittable(false);
|
tx.setResubmittable(false);
|
||||||
tx.setSigningPubKey('');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tx.once('cleanup', function() {
|
|
||||||
self.getPending().remove(tx);
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!tx.complete()) {
|
if (!tx.complete()) {
|
||||||
this._nextSequence -= 1;
|
this._nextSequence -= 1;
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -2302,6 +2302,10 @@ describe('Transaction', function() {
|
|||||||
{Signer: s2},
|
{Signer: s2},
|
||||||
{Signer: s1}
|
{Signer: s1}
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
transaction.remote = new Remote();
|
||||||
|
assert(transaction.complete());
|
||||||
|
assert.strictEqual(transaction.tx_json.SigningPubKey, '');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Multisign -- missing LastLedgerSequence', function() {
|
it('Multisign -- missing LastLedgerSequence', function() {
|
||||||
@@ -2317,4 +2321,27 @@ describe('Transaction', function() {
|
|||||||
transaction.getMultiSigningJson();
|
transaction.getMultiSigningJson();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('Multisign -- LastLedgerSequence autofill', function() {
|
||||||
|
const transaction = Transaction.from_json({
|
||||||
|
Account: 'rG1QQv2nh2gr7RCZ1P8YYcBUKCCN633jCn',
|
||||||
|
Sequence: 1,
|
||||||
|
Fee: '100',
|
||||||
|
TransactionType: 'AccountSet',
|
||||||
|
Flags: 0
|
||||||
|
});
|
||||||
|
|
||||||
|
const sequence = 1;
|
||||||
|
transaction.remote = {
|
||||||
|
getLedgerSequenceSync: () => {
|
||||||
|
return sequence;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const mJson = transaction.getMultiSigningJson();
|
||||||
|
assert.strictEqual(mJson.LastLedgerSequence,
|
||||||
|
sequence + 1 + transaction._lastLedgerOffset);
|
||||||
|
assert.strictEqual(transaction.tx_json.LastLedgerSequence,
|
||||||
|
sequence + 1 + transaction._lastLedgerOffset);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user