diff --git a/CHANGELOG.md b/CHANGELOG.md index f6fdba4b4..b35e7ac0c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,10 +3,16 @@ ## Unreleased +## [v6.0.3](https://github.com/stellar/js-stellar-base/compare/v6.0.2..v6.0.3) + +### Fix +- When creating a `Transaction`, forward the optional `withMuxing` flag along to its operations so that their properties are also decoded with the appropriate muxing state ([#469](https://github.com/stellar/js-stellar-base/pull/469)). + + ## [v6.0.2](https://github.com/stellar/js-stellar-base/compare/v6.0.1..v6.0.2) ### Fix - - Fix Typescript signatures for operations to universally allow setting the `withMuxing` flag. +- Fix Typescript signatures for operations to universally allow setting the `withMuxing` flag ([#466](https://github.com/stellar/js-stellar-base/pull/466)). ## [v6.0.1](https://github.com/stellar/js-stellar-base/compare/v5.3.2..v6.0.1) diff --git a/package.json b/package.json index 1d5fd14b1..1c9cbbbee 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "stellar-base", - "version": "6.0.2", + "version": "6.0.3", "description": "Low level stellar support library", "main": "./lib/index.js", "types": "./types/index.d.ts", diff --git a/src/operation.js b/src/operation.js index ae4cd73f1..cd11f37dc 100644 --- a/src/operation.js +++ b/src/operation.js @@ -114,8 +114,8 @@ export class Operation { * was used to create the operation (i.e. the `opts` parameter to most ops). * * @param {xdr.Operation} operation - An XDR Operation. - * @param {boolean} [withMuxing] - Indicates that the operation - * contains M... addresses which should be interpreted fully as muxed + * @param {boolean} [withMuxing] - Indicates that if the operation + * contains M... addresses, they should be interpreted fully as muxed * accounts. By default, this option is disabled until muxed accounts are * mature. * diff --git a/src/transaction.js b/src/transaction.js index b52362ac4..02b41ab5e 100644 --- a/src/transaction.js +++ b/src/transaction.js @@ -83,7 +83,9 @@ export class Transaction extends TransactionBase { }; } const operations = tx.operations() || []; - this._operations = map(operations, (op) => Operation.fromXDRObject(op)); + this._operations = map(operations, (op) => + Operation.fromXDRObject(op, withMuxing) + ); } /** diff --git a/test/unit/transaction_test.js b/test/unit/transaction_test.js index 929613379..2b5ec3a51 100644 --- a/test/unit/transaction_test.js +++ b/test/unit/transaction_test.js @@ -532,25 +532,19 @@ describe('Transaction', function() { ) .addMemo(StellarBase.Memo.text('Happy birthday!')) .build(); - let med25519 = new StellarBase.xdr.MuxedAccountMed25519({ - id: StellarBase.xdr.Uint64.fromString('0'), - ed25519: source.rawPublicKey() - }); - let muxedAccount = StellarBase.xdr.MuxedAccount.keyTypeMuxedEd25519( - med25519 - ); + + // force the source to be muxed in the envelope + const muxedSource = new StellarBase.MuxedAccount(account, '0'); const envelope = tx.toEnvelope(); envelope .v1() .tx() - .sourceAccount(muxedAccount); - - let destMed25519 = new StellarBase.xdr.MuxedAccountMed25519({ - id: StellarBase.xdr.Uint64.fromString('0'), - ed25519: StellarBase.StrKey.decodeEd25519PublicKey(destination) - }); - let destMuxedAccount = StellarBase.xdr.MuxedAccount.keyTypeMuxedEd25519( - destMed25519 + .sourceAccount(muxedSource.toXDRObject()); + + // force the payment destination to be muxed in the envelope + const destinationMuxed = new StellarBase.MuxedAccount( + new StellarBase.Account(destination, '1'), + '0' ); envelope .v1() @@ -558,16 +552,27 @@ describe('Transaction', function() { .operations()[0] .body() .value() - .destination(destMuxedAccount); + .destination(destinationMuxed.toXDRObject()); - const txWithMuxedAccount = new StellarBase.Transaction( + // make sure there are no muxed properties on decoding by default + const unmuxedTx = new StellarBase.Transaction( envelope, networkPassphrase ); - expect(txWithMuxedAccount.source).to.equal(source.publicKey()); expect(tx.source).to.equal(source.publicKey()); - var operation = txWithMuxedAccount.operations[0]; - expect(operation.destination).to.be.equal(destination); + expect(unmuxedTx.source).to.equal(source.publicKey()); + expect(unmuxedTx.operations[0].destination).to.be.equal(destination); + + // but they should be muxed if we enforce it + const muxedTx = new StellarBase.Transaction( + envelope, + StellarBase.Networks.TESTNET, + true + ); + expect(muxedTx.source).to.be.equal(muxedSource.accountId()); + expect(muxedTx.operations[0].destination).to.be.equal( + destinationMuxed.accountId() + ); }); }); });