Skip to content

Commit

Permalink
add checks for method extraction
Browse files Browse the repository at this point in the history
  • Loading branch information
BlaineHeffron committed Jun 6, 2024
1 parent 6148f9d commit 49df04f
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/contract/assembled_transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,15 @@ export class AssembledTransaction<T> {
): AssembledTransaction<T> {
const envelope = xdr.TransactionEnvelope.fromXDR(encodedXDR, "base64");
const built = TransactionBuilder.fromXDR(envelope, options.networkPassphrase) as Tx;
const method = ((built.operations[0] as Operation.InvokeHostFunction).func.value() as xdr.InvokeContractArgs).functionName().toString('utf-8');
const operation = built.operations[0] as Operation.InvokeHostFunction;
if (!operation?.func?.value || typeof operation.func.value !== 'function') {
throw new Error("Could not extract the method from the transaction envelope.");
}
const invokeContractArgs = operation.func.value() as xdr.InvokeContractArgs;
if (!invokeContractArgs?.functionName) {
throw new Error("Could not extract the method name from the transaction envelope.");
}
const method = invokeContractArgs.functionName().toString('utf-8');
const txn = new AssembledTransaction(
{ ...options,
method,
Expand Down

0 comments on commit 49df04f

Please sign in to comment.