From ab8dee398f53f46cec4c7d4b006c5636d7101d61 Mon Sep 17 00:00:00 2001 From: George Kudrayvtsev Date: Fri, 4 Jun 2021 13:42:54 -0700 Subject: [PATCH 1/9] Make `MuxedAccount` conform to the `Account` pseudo-interface. --- src/account.js | 18 ++++++++++++++++++ types/index.d.ts | 1 + types/test.ts | 2 ++ 3 files changed, 21 insertions(+) diff --git a/src/account.js b/src/account.js index 731551a69..32f28269d 100644 --- a/src/account.js +++ b/src/account.js @@ -149,6 +149,14 @@ export class MuxedAccount { return new MuxedAccount(new Account(gAddress, sequenceNum), id); } + /** + * A helper method to turn an M-address into its underlying G-address. + */ + static parseBaseAddress(mAddress) { + const muxedAccount = decodeAddressToMuxedAccount(mAddress, true); + return encodeMuxedAccountToAddress(muxedAccount, false); + } + /** * @return {Account} the underlying account object shared among all muxed * accounts with this Stellar address @@ -195,6 +203,16 @@ export class MuxedAccount { return this.account.incrementSequenceNumber(); } + /** + * Creates another muxed "sub"account from the base with a new ID set + * + * @param {string} id - the ID of the new muxed account + * @return {MuxedAccount} a new instance w/ the specified parameters + */ + createSubaccount(id) { + return new MuxedAccount(this.account, id); + } + /** * @return {xdr.MuxedAccount} the XDR object representing this muxed account's * G-address and uint64 ID diff --git a/types/index.d.ts b/types/index.d.ts index c7e183ad5..d67ffe305 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -21,6 +21,7 @@ export class MuxedAccount { accountId(): string; sequenceNumber(): string; incrementSequenceNumber(): void; + createSubaccount(id: string): MuxedAccount; baseAccount(): Account; id(): string; diff --git a/types/test.ts b/types/test.ts index a82882e17..3b846e5ca 100644 --- a/types/test.ts +++ b/types/test.ts @@ -6,6 +6,8 @@ const destKey = StellarSdk.Keypair.random(); const usd = new StellarSdk.Asset('USD', 'GDGU5OAPHNPU5UCLE5RDJHG7PXZFQYWKCFOEXSXNMR6KRQRI5T6XXCD7'); // $ExpectType Asset const account = new StellarSdk.Account(sourceKey.publicKey(), '1'); // $ExpectType Account const muxedAccount = new StellarSdk.MuxedAccount(account, '123'); // $ExpectType MuxedAccount +const muxedConforms: StellarSdk.Account = muxedAccount; // $ExpectType Account + const transaction = new StellarSdk.TransactionBuilder(account, { fee: "100", networkPassphrase: StellarSdk.Networks.TESTNET From a56984575c39074b1fae67d96c00bebbe3aa5a34 Mon Sep 17 00:00:00 2001 From: George Kudrayvtsev Date: Fri, 4 Jun 2021 13:44:05 -0700 Subject: [PATCH 2/9] Add test that fails without muxed support for fee bumps. --- test/unit/transaction_builder_test.js | 55 +++++++++++++++++++++++++-- 1 file changed, 52 insertions(+), 3 deletions(-) diff --git a/test/unit/transaction_builder_test.js b/test/unit/transaction_builder_test.js index 0e8e39627..35044b64a 100644 --- a/test/unit/transaction_builder_test.js +++ b/test/unit/transaction_builder_test.js @@ -680,10 +680,11 @@ describe('TransactionBuilder', function() { ); const PUBKEY_SRC = StellarBase.StrKey.decodeEd25519PublicKey( - 'GA7QYNF7SOWQ3GLR2BGMZEHXAVIRZA4KVWLTJJFC7MGXUA74P7UJVSGZ' + source.baseAccount().accountId() ); const MUXED_SRC_ID = StellarBase.xdr.Uint64.fromString('2'); const networkPassphrase = 'Standalone Network ; February 2017'; + const signer = StellarBase.Keypair.master(StellarBase.Networks.TESTNET); it('enables muxed support after creation', function() { let builder = new StellarBase.TransactionBuilder(source, { @@ -707,7 +708,6 @@ describe('TransactionBuilder', function() { // TODO: More muxed-enabled operations ]; - const signer = StellarBase.Keypair.master(StellarBase.Networks.TESTNET); let builder = new StellarBase.TransactionBuilder(source, { fee: '100', timebounds: { minTime: 0, maxTime: 0 }, @@ -726,7 +726,7 @@ describe('TransactionBuilder', function() { tx.sign(signer); const envelope = tx.toEnvelope(); - const xdrTx = envelope.v1().tx(); + const xdrTx = envelope.value().tx(); const rawMuxedSourceAccount = xdrTx.sourceAccount(); @@ -753,5 +753,54 @@ describe('TransactionBuilder', function() { ); }).to.not.throw(); }); + + it('works with fee-bump transactions', function() { + // We create a non-muxed transaction, then fee-bump with a muxed source. + let builder = new StellarBase.TransactionBuilder(source.baseAccount(), { + fee: '100', + timebounds: { minTime: 0, maxTime: 0 }, + networkPassphrase: networkPassphrase + }); + + builder.addOperation( + StellarBase.Operation.payment({ + source: source.baseAccount().accountId(), + destination: StellarBase.MuxedAccount.parseBaseAddress(destination), + amount: amount, + asset: asset + }) + ); + + let tx = builder.build(); + tx.sign(signer); + + const kp = StellarBase.Keypair.fromPublicKey( + source.baseAccount().accountId() + ); + const feeTx = StellarBase.TransactionBuilder.buildFeeBumpTransaction( + kp, + '1000', + tx, + networkPassphrase, + '2' + ); + + expect(feeTx).to.be.an.instanceof(StellarBase.FeeBumpTransaction); + const envelope = feeTx.toEnvelope(); + const xdrTx = envelope.value().tx(); + + const rawFeeSource = xdrTx.feeSource(); + + expect(rawFeeSource.switch()).to.equal( + StellarBase.xdr.CryptoKeyType.keyTypeMuxedEd25519() + ); + + const innerMux = rawFeeSource.med25519(); + expect(innerMux.ed25519()).to.eql(PUBKEY_SRC); + expect(encodeMuxedAccountToAddress(rawFeeSource, true)).to.equal( + source.accountId() + ); + expect(innerMux.id()).to.eql(MUXED_SRC_ID); + }); }); }); From 954984aaef2f644753dbfcbe3f7da8c2673ddc1b Mon Sep 17 00:00:00 2001 From: George Kudrayvtsev Date: Fri, 4 Jun 2021 13:44:32 -0700 Subject: [PATCH 3/9] Add optional muxed ID support to the `Keypair.xdrMuxedAccount` helper method --- src/keypair.js | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/src/keypair.js b/src/keypair.js index 9aa5ecca5..622406aab 100644 --- a/src/keypair.js +++ b/src/keypair.js @@ -1,9 +1,13 @@ import nacl from 'tweetnacl'; +import isUndefined from 'lodash/isUndefined'; +import isString from 'lodash/isString'; + import { sign, verify, generate } from './signing'; import { StrKey } from './strkey'; -import xdr from './generated/stellar-xdr_generated'; import { hash } from './hashing'; +import xdr from './generated/stellar-xdr_generated'; + /** * `Keypair` represents public (and secret) keys of the account. * @@ -121,7 +125,31 @@ export class Keypair { return new xdr.PublicKey.publicKeyTypeEd25519(this._publicKey); } - xdrMuxedAccount() { + /** + * Creates a {@link xdr.MuxedAccount} object from the public key. + * + * You will get a different type of muxed account depending on whether or not + * you pass an ID. + * + * @param {string} [id] - stringified integer indicating the underlying muxed + * ID of the new account object + * + * @return {xdr.MuxedAccount} + */ + xdrMuxedAccount(id) { + if (!isUndefined(id)) { + if (!isString(id)) { + throw new TypeError(`expected string for ID, got ${typeof id}`); + } + + return xdr.MuxedAccount.keyTypeMuxedEd25519( + new xdr.MuxedAccountMed25519({ + id: xdr.Uint64.fromString(id), + ed25519: this._publicKey + }) + ); + } + return new xdr.MuxedAccount.keyTypeEd25519(this._publicKey); } From 1bdf6717b64db72b15f908212cc1a696c953b96b Mon Sep 17 00:00:00 2001 From: George Kudrayvtsev Date: Fri, 4 Jun 2021 13:44:58 -0700 Subject: [PATCH 4/9] Add muxing support to fee-bump transactions and their builder --- src/fee_bump_transaction.js | 18 ++++++++++++++---- src/transaction_builder.js | 38 +++++++++++++++++++++++++++++-------- 2 files changed, 44 insertions(+), 12 deletions(-) diff --git a/src/fee_bump_transaction.js b/src/fee_bump_transaction.js index 88a27c65c..1354b39a8 100644 --- a/src/fee_bump_transaction.js +++ b/src/fee_bump_transaction.js @@ -13,12 +13,19 @@ import { encodeMuxedAccountToAddress } from './util/decode_encode_muxed_account' * Once a {@link FeeBumpTransaction} has been created, its attributes and operations * should not be changed. You should only add signatures (using {@link FeeBumpTransaction#sign}) before * submitting to the network or forwarding on to additional signers. - * @param {string|xdr.TransactionEnvelope} envelope - The transaction envelope object or base64 encoded string. - * @param {string} networkPassphrase passphrase of the target stellar network (e.g. "Public Global Stellar Network ; September 2015"). + * + * @param {string|xdr.TransactionEnvelope} envelope - transaction envelope + * object or base64 encoded string. + * @param {string} networkPassphrase - passphrase of the target Stellar network + * (e.g. "Public Global Stellar Network ; September 2015"). + * @param {bool} [opts.withMuxing] - indicates that the fee source of this + * transaction is a proper muxed account (i.e. coming from an M... address). + * By default, this option is disabled until muxed accounts are mature. + * * @extends TransactionBase */ export class FeeBumpTransaction extends TransactionBase { - constructor(envelope, networkPassphrase) { + constructor(envelope, networkPassphrase, withMuxing) { if (typeof envelope === 'string') { const buffer = Buffer.from(envelope, 'base64'); envelope = xdr.TransactionEnvelope.fromXDR(buffer); @@ -42,7 +49,10 @@ export class FeeBumpTransaction extends TransactionBase { const innerTxEnvelope = xdr.TransactionEnvelope.envelopeTypeTx( tx.innerTx().v1() ); - this._feeSource = encodeMuxedAccountToAddress(this.tx.feeSource()); + this._feeSource = encodeMuxedAccountToAddress( + this.tx.feeSource(), + withMuxing + ); this._innerTransaction = new Transaction( innerTxEnvelope, networkPassphrase diff --git a/src/transaction_builder.js b/src/transaction_builder.js index 9d169cc19..483f61cdb 100644 --- a/src/transaction_builder.js +++ b/src/transaction_builder.js @@ -272,18 +272,36 @@ export class TransactionBuilder { } /** - * Builds a {@link FeeBumpTransaction} - * @param {Keypair} feeSource - The account paying for the transaction. - * @param {string} baseFee - The max fee willing to pay per operation in inner transaction (**in stroops**). Required. - * @param {Transaction} innerTx - The Transaction to be bumped by the fee bump transaction. - * @param {string} networkPassphrase - networkPassphrase of the target stellar network (e.g. "Public Global Stellar Network ; September 2015"). + * Builds a {@link FeeBumpTransaction}, enabling you to resubmit an existing + * transaction with a higher fee. + * + * @param {Keypair} feeSource - account paying for the transaction + * @param {string} baseFee - max fee willing to pay per + * operation in inner transaction (**in stroops**) + * @param {Transaction} innerTx - {@link Transaction} to be bumped + * by the fee bump transaction + * @param {string} networkPassphrase - passphrase of the target Stellar + * network (e.g. "Public Global Stellar Network ; September 2015") + * @param {string} [muxedId] - an (optional, stringified) ID to + * indicate that the source account for the fee-bump is a muxed account. + * The muxed account will be built from the `feeSource`'s public key and + * this `muxedId`. + * + * @todo Alongside the next major version bump, this type signature can be + * changed to be less awkward: accept a MuxedAccount as the `feeSource` + * rather than a keypair and an optional ID. + * + * @note Your fee-bump amount should be 10x the original fee. + * @see https://developers.stellar.org/docs/glossary/fee-bumps/#replace-by-fee + * * @returns {FeeBumpTransaction} */ static buildFeeBumpTransaction( feeSource, baseFee, innerTx, - networkPassphrase + networkPassphrase, + muxedId ) { const innerOps = innerTx.operations.length; const innerBaseFeeRate = new BigNumber(innerTx.fee).div(innerOps); @@ -328,7 +346,7 @@ export class TransactionBuilder { } const tx = new xdr.FeeBumpTransaction({ - feeSource: feeSource.xdrMuxedAccount(), + feeSource: feeSource.xdrMuxedAccount(muxedId), fee: xdr.Int64.fromString(base.mul(innerOps + 1).toString()), innerTx: xdr.FeeBumpTransactionInnerTx.envelopeTypeTx( innerTxEnvelope.v1() @@ -343,7 +361,11 @@ export class TransactionBuilder { feeBumpTxEnvelope ); - return new FeeBumpTransaction(envelope, networkPassphrase); + return new FeeBumpTransaction( + envelope, + networkPassphrase, + !isUndefined(muxedId) + ); } /** From 378641b3a9bf4d90f3896376c40fbf25fb1079cf Mon Sep 17 00:00:00 2001 From: George Kudrayvtsev Date: Fri, 4 Jun 2021 13:45:09 -0700 Subject: [PATCH 5/9] Improve payment error message --- src/operations/payment.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/operations/payment.js b/src/operations/payment.js index 0f17d8ae0..b87f7d0cf 100644 --- a/src/operations/payment.js +++ b/src/operations/payment.js @@ -35,7 +35,7 @@ export function payment(opts) { opts.withMuxing ); } catch (e) { - throw new Error('destination is invalid'); + throw new Error('destination is invalid; did you forget to enable muxing?'); } attributes.asset = opts.asset.toXDRObject(); From 6d2e9ce7a2a16a4f79c4bda35fc2cb3a1d3361b3 Mon Sep 17 00:00:00 2001 From: George Kudrayvtsev Date: Fri, 4 Jun 2021 13:52:13 -0700 Subject: [PATCH 6/9] Add CHANGELOG entry for this PR --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index bc758cd1e..be8cadc4f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,11 @@ # Changelog + ## Unreleased +### Add +- **Opt-in support for muxed accounts.** In addition to the support introduced in [v5.2.0](https://github.com/stellar/js-stellar-base/releases/v5.2.0), this completes support for muxed accounts by enabling them for fee-bump transactions. Pass the muxing ID as the (new, optional) last parameter to `TransactionBuilder.buildFeeBumpTransaction` to make the `feeSource` a fully-muxed account instance ([#434](https://github.com/stellar/js-stellar-base/pull/434)). + ## [v5.2.0](https://github.com/stellar/js-stellar-base/compare/v5.1.0..v5.2.0) From d92bb4a04d89b4def0b9e1a93204ab8558579913 Mon Sep 17 00:00:00 2001 From: George Kudrayvtsev Date: Fri, 4 Jun 2021 14:00:02 -0700 Subject: [PATCH 7/9] Add Typescript definitions for fee-bumps --- src/account.js | 3 +++ types/index.d.ts | 16 +++++++++++++--- types/test.ts | 2 +- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/account.js b/src/account.js index 32f28269d..1dba6e8ab 100644 --- a/src/account.js +++ b/src/account.js @@ -151,6 +151,9 @@ export class MuxedAccount { /** * A helper method to turn an M-address into its underlying G-address. + * + * @param {string} mAddress - muxed address to convert + * @returns {string} underlying G-address */ static parseBaseAddress(mAddress) { const muxedAccount = decodeAddressToMuxedAccount(mAddress, true); diff --git a/types/index.d.ts b/types/index.d.ts index d67ffe305..81c8ca486 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -16,6 +16,7 @@ export class Account { export class MuxedAccount { constructor(account: Account, sequence: string); static fromAddress(mAddress: string, sequenceNum: string): MuxedAccount; + static parseBaseAddress(mAddress: string): string; /* Modeled after Account, above */ accountId(): string; @@ -100,7 +101,10 @@ export class Keypair { signDecorated(data: Buffer): xdr.DecoratedSignature; signatureHint(): Buffer; verify(data: Buffer, signature: Buffer): boolean; + xdrAccountId(): xdr.AccountId; + xdrPublicKey(): xdr.PublicKey; + xdrMuxedAccount(id: string): xdr.MuxedAccount; } export const MemoNone = 'none'; @@ -764,7 +768,8 @@ export class TransactionI { export class FeeBumpTransaction extends TransactionI { constructor( envelope: string | xdr.TransactionEnvelope, - networkPassphrase: string + networkPassphrase: string, + withMuxing?: boolean ); feeSource: string; innerTransaction: Transaction; @@ -776,7 +781,8 @@ export class Transaction< > extends TransactionI { constructor( envelope: string | xdr.TransactionEnvelope, - networkPassphrase: string + networkPassphrase: string, + withMuxing?: boolean ); memo: TMemo; operations: TOps; @@ -805,12 +811,15 @@ export class TransactionBuilder { feeSource: Keypair, baseFee: string, innerTx: Transaction, - networkPassphrase: string + networkPassphrase: string, + id?: string ): FeeBumpTransaction; static fromXDR( envelope: string | xdr.TransactionEnvelope, networkPassphrase: string ): Transaction | FeeBumpTransaction; + + supportMuxedAccounts: boolean; } export namespace TransactionBuilder { @@ -823,6 +832,7 @@ export namespace TransactionBuilder { memo?: Memo; networkPassphrase?: string; v1?: boolean; + withMuxing?: boolean; } } diff --git a/types/test.ts b/types/test.ts index 3b846e5ca..b7b5f7e6d 100644 --- a/types/test.ts +++ b/types/test.ts @@ -6,7 +6,7 @@ const destKey = StellarSdk.Keypair.random(); const usd = new StellarSdk.Asset('USD', 'GDGU5OAPHNPU5UCLE5RDJHG7PXZFQYWKCFOEXSXNMR6KRQRI5T6XXCD7'); // $ExpectType Asset const account = new StellarSdk.Account(sourceKey.publicKey(), '1'); // $ExpectType Account const muxedAccount = new StellarSdk.MuxedAccount(account, '123'); // $ExpectType MuxedAccount -const muxedConforms: StellarSdk.Account = muxedAccount; // $ExpectType Account +const muxedConforms = muxedAccount as StellarSdk.Account; // $ExpectType Account const transaction = new StellarSdk.TransactionBuilder(account, { fee: "100", From 0dd5b8d8ef06066047b4823063a73c8471128352 Mon Sep 17 00:00:00 2001 From: George Kudrayvtsev Date: Fri, 4 Jun 2021 16:05:17 -0700 Subject: [PATCH 8/9] Allow account IDs (G... or M...) as fee-bump source --- CHANGELOG.md | 2 +- src/transaction_builder.js | 41 +++++++++++++++------------ test/unit/transaction_builder_test.js | 7 ++--- types/index.d.ts | 4 +-- 4 files changed, 28 insertions(+), 26 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index be8cadc4f..f92580aaa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ ## Unreleased ### Add -- **Opt-in support for muxed accounts.** In addition to the support introduced in [v5.2.0](https://github.com/stellar/js-stellar-base/releases/v5.2.0), this completes support for muxed accounts by enabling them for fee-bump transactions. Pass the muxing ID as the (new, optional) last parameter to `TransactionBuilder.buildFeeBumpTransaction` to make the `feeSource` a fully-muxed account instance ([#434](https://github.com/stellar/js-stellar-base/pull/434)). +- **Opt-in support for muxed accounts.** In addition to the support introduced in [v5.2.0](https://github.com/stellar/js-stellar-base/releases/v5.2.0), this completes support for muxed accounts by enabling them for fee-bump transactions. Pass a muxed account address (in the `M...` form) as the first parameter (and opting-in to muxing by passing `true` as the last parameter) to `TransactionBuilder.buildFeeBumpTransaction` to make the `feeSource` a fully-muxed account instance ([#434](https://github.com/stellar/js-stellar-base/pull/434)). ## [v5.2.0](https://github.com/stellar/js-stellar-base/compare/v5.1.0..v5.2.0) diff --git a/src/transaction_builder.js b/src/transaction_builder.js index 483f61cdb..067802928 100644 --- a/src/transaction_builder.js +++ b/src/transaction_builder.js @@ -2,6 +2,7 @@ import { UnsignedHyper } from 'js-xdr'; import BigNumber from 'bignumber.js'; import clone from 'lodash/clone'; import isUndefined from 'lodash/isUndefined'; +import isString from 'lodash/isString'; import xdr from './generated/stellar-xdr_generated'; import { Transaction } from './transaction'; @@ -275,21 +276,22 @@ export class TransactionBuilder { * Builds a {@link FeeBumpTransaction}, enabling you to resubmit an existing * transaction with a higher fee. * - * @param {Keypair} feeSource - account paying for the transaction - * @param {string} baseFee - max fee willing to pay per - * operation in inner transaction (**in stroops**) - * @param {Transaction} innerTx - {@link Transaction} to be bumped - * by the fee bump transaction - * @param {string} networkPassphrase - passphrase of the target Stellar + * @param {Keypair|string} feeSource - account paying for the transaction, + * in the form of either a Keypair (only the public key is used) or + * an account ID (in G... or M... form, but refer to `withMuxing`) + * @param {string} baseFee - max fee willing to pay per operation + * in inner transaction (**in stroops**) + * @param {Transaction} innerTx - {@link Transaction} to be bumped by + * the fee bump transaction + * @param {string} networkPassphrase - passphrase of the target Stellar * network (e.g. "Public Global Stellar Network ; September 2015") - * @param {string} [muxedId] - an (optional, stringified) ID to - * indicate that the source account for the fee-bump is a muxed account. - * The muxed account will be built from the `feeSource`'s public key and - * this `muxedId`. + * @param {bool} [withMuxing] - allows fee sources to be proper + * muxed accounts (i.e. coming from an M... address). By default, this + * option is disabled until muxed accounts are mature. * * @todo Alongside the next major version bump, this type signature can be * changed to be less awkward: accept a MuxedAccount as the `feeSource` - * rather than a keypair and an optional ID. + * rather than a keypair or string. * * @note Your fee-bump amount should be 10x the original fee. * @see https://developers.stellar.org/docs/glossary/fee-bumps/#replace-by-fee @@ -301,7 +303,7 @@ export class TransactionBuilder { baseFee, innerTx, networkPassphrase, - muxedId + withMuxing ) { const innerOps = innerTx.operations.length; const innerBaseFeeRate = new BigNumber(innerTx.fee).div(innerOps); @@ -345,8 +347,15 @@ export class TransactionBuilder { ); } + let feeSourceAccount; + if (isString(feeSource)) { + feeSourceAccount = decodeAddressToMuxedAccount(feeSource, withMuxing); + } else { + feeSourceAccount = feeSource.xdrMuxedAccount(); + } + const tx = new xdr.FeeBumpTransaction({ - feeSource: feeSource.xdrMuxedAccount(muxedId), + feeSource: feeSourceAccount, fee: xdr.Int64.fromString(base.mul(innerOps + 1).toString()), innerTx: xdr.FeeBumpTransactionInnerTx.envelopeTypeTx( innerTxEnvelope.v1() @@ -361,11 +370,7 @@ export class TransactionBuilder { feeBumpTxEnvelope ); - return new FeeBumpTransaction( - envelope, - networkPassphrase, - !isUndefined(muxedId) - ); + return new FeeBumpTransaction(envelope, networkPassphrase, withMuxing); } /** diff --git a/test/unit/transaction_builder_test.js b/test/unit/transaction_builder_test.js index 35044b64a..4a05c1b56 100644 --- a/test/unit/transaction_builder_test.js +++ b/test/unit/transaction_builder_test.js @@ -774,15 +774,12 @@ describe('TransactionBuilder', function() { let tx = builder.build(); tx.sign(signer); - const kp = StellarBase.Keypair.fromPublicKey( - source.baseAccount().accountId() - ); const feeTx = StellarBase.TransactionBuilder.buildFeeBumpTransaction( - kp, + source.accountId(), '1000', tx, networkPassphrase, - '2' + true ); expect(feeTx).to.be.an.instanceof(StellarBase.FeeBumpTransaction); diff --git a/types/index.d.ts b/types/index.d.ts index 81c8ca486..ac6f459a4 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -808,11 +808,11 @@ export class TransactionBuilder { build(): Transaction; setNetworkPassphrase(networkPassphrase: string): this; static buildFeeBumpTransaction( - feeSource: Keypair, + feeSource: Keypair | string, baseFee: string, innerTx: Transaction, networkPassphrase: string, - id?: string + withMuxing?: boolean ): FeeBumpTransaction; static fromXDR( envelope: string | xdr.TransactionEnvelope, From cfc6df0cd594563ec488b49aaa94239dc7ca241c Mon Sep 17 00:00:00 2001 From: George Kudrayvtsev Date: Mon, 7 Jun 2021 13:47:12 -0700 Subject: [PATCH 9/9] Drop (possibly?) unnecessary helper method --- src/account.js | 11 ----------- test/unit/muxed_account_test.js | 3 +++ test/unit/transaction_builder_test.js | 4 +++- 3 files changed, 6 insertions(+), 12 deletions(-) diff --git a/src/account.js b/src/account.js index 1dba6e8ab..ca5e170bd 100644 --- a/src/account.js +++ b/src/account.js @@ -149,17 +149,6 @@ export class MuxedAccount { return new MuxedAccount(new Account(gAddress, sequenceNum), id); } - /** - * A helper method to turn an M-address into its underlying G-address. - * - * @param {string} mAddress - muxed address to convert - * @returns {string} underlying G-address - */ - static parseBaseAddress(mAddress) { - const muxedAccount = decodeAddressToMuxedAccount(mAddress, true); - return encodeMuxedAccountToAddress(muxedAccount, false); - } - /** * @return {Account} the underlying account object shared among all muxed * accounts with this Stellar address diff --git a/test/unit/muxed_account_test.js b/test/unit/muxed_account_test.js index f94eb89c7..57fe4d9bc 100644 --- a/test/unit/muxed_account_test.js +++ b/test/unit/muxed_account_test.js @@ -82,6 +82,9 @@ describe('muxed account abstraction works', function() { const mux1 = new StellarBase.MuxedAccount.fromAddress(MPUBKEY_ZERO, '123'); expect(mux1.id()).to.equal('0'); expect(mux1.accountId()).to.equal(MPUBKEY_ZERO); + expect(mux1.baseAccount().accountId()).to.equal( + 'GA7QYNF7SOWQ3GLR2BGMZEHXAVIRZA4KVWLTJJFC7MGXUA74P7UJVSGZ' + ); expect(mux1.sequenceNumber()).to.equal('123'); }); }); diff --git a/test/unit/transaction_builder_test.js b/test/unit/transaction_builder_test.js index 4a05c1b56..7e75edbce 100644 --- a/test/unit/transaction_builder_test.js +++ b/test/unit/transaction_builder_test.js @@ -762,10 +762,12 @@ describe('TransactionBuilder', function() { networkPassphrase: networkPassphrase }); + const muxed = new StellarBase.MuxedAccount.fromAddress(destination, '0'); + const gAddress = muxed.baseAccount().accountId(); builder.addOperation( StellarBase.Operation.payment({ source: source.baseAccount().accountId(), - destination: StellarBase.MuxedAccount.parseBaseAddress(destination), + destination: gAddress, amount: amount, asset: asset })