Skip to content

Commit

Permalink
Drop unnecessary networkPassphrase (it's on the tx)
Browse files Browse the repository at this point in the history
  • Loading branch information
Shaptic committed Oct 23, 2023
1 parent 1714cff commit 5870a43
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 21 deletions.
23 changes: 5 additions & 18 deletions src/soroban/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -532,9 +532,6 @@ export class Server {
* from the simulation. In other words, if you include auth entries, you
* don't care about the auth returned from the simulation. Other fields
* (footprint, etc.) will be filled as normal.
* @param {string} [networkPassphrase] explicitly provide a network
* passphrase (default: requested from the server via
* {@link Server.getNetwork}).
*
* @returns {Promise<Transaction | FeeBumpTransaction>} a copy of the
* transaction with the expected authorizations (in the case of
Expand All @@ -544,7 +541,8 @@ export class Server {
*
* @see assembleTransaction
* @see https://soroban.stellar.org/api/methods/simulateTransaction
* @throws {jsonrpc.Error<any> | Error} if simulation fails
* @throws {jsonrpc.Error<any>|Error|Api.SimulateTransactionErrorResponse}
* if simulation fails
* @example
* const contractId = 'CA3D5KRYM6CB7OWQ6TWYRR3Z4T7GNZLKERYNZGGA5SOAOPIFY6YQGAXE';
* const contract = new StellarSdk.Contract(contractId);
Expand Down Expand Up @@ -576,24 +574,13 @@ export class Server {
* console.log("errorResultXdr:", result.errorResultXdr);
* });
*/
public async prepareTransaction(
transaction: Transaction | FeeBumpTransaction,
networkPassphrase?: string
): Promise<Transaction | FeeBumpTransaction> {
const [{ passphrase }, simResponse] = await Promise.all([
networkPassphrase
? Promise.resolve({ passphrase: networkPassphrase })
: this.getNetwork(),
this.simulateTransaction(transaction)
]);
public async prepareTransaction(tx: Transaction | FeeBumpTransaction) {
const simResponse = await this.simulateTransaction(tx);
if (Api.isSimulationError(simResponse)) {
throw simResponse.error;
}
if (!simResponse.result) {
throw new Error('transaction simulation failed');
}

return assembleTransaction(transaction, passphrase, simResponse).build();
return assembleTransaction(tx, simResponse).build();
}

/**
Expand Down
4 changes: 1 addition & 3 deletions src/soroban/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import { parseRawSimulation } from './parsers';
*/
export function assembleTransaction(
raw: Transaction | FeeBumpTransaction,
networkPassphrase: string,
simulation:
| Api.SimulateTransactionResponse
| Api.RawSimulateTransactionResponse
Expand All @@ -38,7 +37,6 @@ export function assembleTransaction(
// TODO: Handle feebump transactions
return assembleTransaction(
raw.innerTransaction,
networkPassphrase,
simulation
);
}
Expand Down Expand Up @@ -70,7 +68,7 @@ export function assembleTransaction(
fee: (classicFeeNum + minResourceFeeNum).toString(),
// apply the pre-built Soroban Tx Data from simulation onto the Tx
sorobanData: success.transactionData.build(),
networkPassphrase
networkPassphrase: raw.networkPassphrase
});

switch (raw.operations[0].type) {
Expand Down

0 comments on commit 5870a43

Please sign in to comment.