Skip to content

Commit

Permalink
When decoding txs, decode their ops w/ matching muxed semantics. (#469)
Browse files Browse the repository at this point in the history
  • Loading branch information
Shaptic authored Sep 14, 2021
1 parent 6f27102 commit a09a1ed
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 25 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
4 changes: 2 additions & 2 deletions src/operation.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
4 changes: 3 additions & 1 deletion src/transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
);
}

/**
Expand Down
45 changes: 25 additions & 20 deletions test/unit/transaction_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -532,42 +532,47 @@ 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()
.tx()
.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()
);
});
});
});
Expand Down

0 comments on commit a09a1ed

Please sign in to comment.