Skip to content

Commit a09a1ed

Browse files
authored
When decoding txs, decode their ops w/ matching muxed semantics. (#469)
1 parent 6f27102 commit a09a1ed

File tree

5 files changed

+38
-25
lines changed

5 files changed

+38
-25
lines changed

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,16 @@
33
## Unreleased
44

55

6+
## [v6.0.3](https://github.com/stellar/js-stellar-base/compare/v6.0.2..v6.0.3)
7+
8+
### Fix
9+
- 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)).
10+
11+
612
## [v6.0.2](https://github.com/stellar/js-stellar-base/compare/v6.0.1..v6.0.2)
713

814
### Fix
9-
- Fix Typescript signatures for operations to universally allow setting the `withMuxing` flag.
15+
- Fix Typescript signatures for operations to universally allow setting the `withMuxing` flag ([#466](https://github.com/stellar/js-stellar-base/pull/466)).
1016

1117

1218
## [v6.0.1](https://github.com/stellar/js-stellar-base/compare/v5.3.2..v6.0.1)

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "stellar-base",
3-
"version": "6.0.2",
3+
"version": "6.0.3",
44
"description": "Low level stellar support library",
55
"main": "./lib/index.js",
66
"types": "./types/index.d.ts",

src/operation.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,8 @@ export class Operation {
114114
* was used to create the operation (i.e. the `opts` parameter to most ops).
115115
*
116116
* @param {xdr.Operation} operation - An XDR Operation.
117-
* @param {boolean} [withMuxing] - Indicates that the operation
118-
* contains M... addresses which should be interpreted fully as muxed
117+
* @param {boolean} [withMuxing] - Indicates that if the operation
118+
* contains M... addresses, they should be interpreted fully as muxed
119119
* accounts. By default, this option is disabled until muxed accounts are
120120
* mature.
121121
*

src/transaction.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,9 @@ export class Transaction extends TransactionBase {
8383
};
8484
}
8585
const operations = tx.operations() || [];
86-
this._operations = map(operations, (op) => Operation.fromXDRObject(op));
86+
this._operations = map(operations, (op) =>
87+
Operation.fromXDRObject(op, withMuxing)
88+
);
8789
}
8890

8991
/**

test/unit/transaction_test.js

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -532,42 +532,47 @@ describe('Transaction', function() {
532532
)
533533
.addMemo(StellarBase.Memo.text('Happy birthday!'))
534534
.build();
535-
let med25519 = new StellarBase.xdr.MuxedAccountMed25519({
536-
id: StellarBase.xdr.Uint64.fromString('0'),
537-
ed25519: source.rawPublicKey()
538-
});
539-
let muxedAccount = StellarBase.xdr.MuxedAccount.keyTypeMuxedEd25519(
540-
med25519
541-
);
535+
536+
// force the source to be muxed in the envelope
537+
const muxedSource = new StellarBase.MuxedAccount(account, '0');
542538
const envelope = tx.toEnvelope();
543539
envelope
544540
.v1()
545541
.tx()
546-
.sourceAccount(muxedAccount);
547-
548-
let destMed25519 = new StellarBase.xdr.MuxedAccountMed25519({
549-
id: StellarBase.xdr.Uint64.fromString('0'),
550-
ed25519: StellarBase.StrKey.decodeEd25519PublicKey(destination)
551-
});
552-
let destMuxedAccount = StellarBase.xdr.MuxedAccount.keyTypeMuxedEd25519(
553-
destMed25519
542+
.sourceAccount(muxedSource.toXDRObject());
543+
544+
// force the payment destination to be muxed in the envelope
545+
const destinationMuxed = new StellarBase.MuxedAccount(
546+
new StellarBase.Account(destination, '1'),
547+
'0'
554548
);
555549
envelope
556550
.v1()
557551
.tx()
558552
.operations()[0]
559553
.body()
560554
.value()
561-
.destination(destMuxedAccount);
555+
.destination(destinationMuxed.toXDRObject());
562556

563-
const txWithMuxedAccount = new StellarBase.Transaction(
557+
// make sure there are no muxed properties on decoding by default
558+
const unmuxedTx = new StellarBase.Transaction(
564559
envelope,
565560
networkPassphrase
566561
);
567-
expect(txWithMuxedAccount.source).to.equal(source.publicKey());
568562
expect(tx.source).to.equal(source.publicKey());
569-
var operation = txWithMuxedAccount.operations[0];
570-
expect(operation.destination).to.be.equal(destination);
563+
expect(unmuxedTx.source).to.equal(source.publicKey());
564+
expect(unmuxedTx.operations[0].destination).to.be.equal(destination);
565+
566+
// but they should be muxed if we enforce it
567+
const muxedTx = new StellarBase.Transaction(
568+
envelope,
569+
StellarBase.Networks.TESTNET,
570+
true
571+
);
572+
expect(muxedTx.source).to.be.equal(muxedSource.accountId());
573+
expect(muxedTx.operations[0].destination).to.be.equal(
574+
destinationMuxed.accountId()
575+
);
571576
});
572577
});
573578
});

0 commit comments

Comments
 (0)