Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When decoding transactions, decode their operations w/ the same muxed semantics. #469

Merged
merged 4 commits into from
Sep 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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