@aptos-labs/ts-sdk
Version:
Aptos TypeScript SDK
75 lines • 3.46 kB
JavaScript
// Copyright © Aptos Foundation
// SPDX-License-Identifier: Apache-2.0
import { Serializable } from "../../bcs/serializer.js";
import { AccountAddress } from "../../core/index.js";
import { RawTransaction } from "./rawTransaction.js";
/**
* Represents a multi-agent transaction that can be serialized and deserialized.
* This transaction includes a raw transaction, optional fee payer address, and multiple secondary signer addresses.
*
* @param rawTransaction The raw transaction to be executed.
* @param secondarySignerAddresses An array of secondary signer addresses involved in the transaction.
* @param feePayerAddress An optional account address that sponsors the transaction's gas fees.
* @group Implementation
* @category Transactions
*/
export class MultiAgentTransaction extends Serializable {
rawTransaction;
feePayerAddress;
secondarySignerAddresses;
/**
* Represents a MultiAgentTransaction that can be submitted to the Aptos chain for execution.
* This class encapsulates the raw transaction data, the secondary signer addresses, and an optional fee payer address.
*
* @param rawTransaction The raw transaction data.
* @param secondarySignerAddresses An array of secondary signer addresses.
* @param feePayerAddress An optional account address that sponsors the gas fees.
* @group Implementation
* @category Transactions
*/
constructor(rawTransaction, secondarySignerAddresses, feePayerAddress) {
super();
this.rawTransaction = rawTransaction;
this.feePayerAddress = feePayerAddress;
this.secondarySignerAddresses = secondarySignerAddresses;
}
/**
* Serializes the transaction data, including the raw transaction, secondary signer addresses, and fee payer address.
* This function is essential for preparing the transaction for transmission or storage in a serialized format.
*
* @param serializer - The serializer instance used to serialize the transaction data.
* @group Implementation
* @category Transactions
*/
serialize(serializer) {
this.rawTransaction.serialize(serializer);
serializer.serializeVector(this.secondarySignerAddresses);
if (this.feePayerAddress === undefined) {
serializer.serializeBool(false);
}
else {
serializer.serializeBool(true);
this.feePayerAddress.serialize(serializer);
}
}
/**
* Deserializes a MultiAgentTransaction from the provided deserializer.
* This function allows you to reconstruct a MultiAgentTransaction object from its serialized form, including any secondary
* signer addresses and the fee payer address if present.
*
* @param deserializer - The deserializer instance used to read the serialized data.
* @group Implementation
* @category Transactions
*/
static deserialize(deserializer) {
const rawTransaction = RawTransaction.deserialize(deserializer);
const secondarySignerAddresses = deserializer.deserializeVector(AccountAddress);
const feePayerPresent = deserializer.deserializeBool();
let feePayerAddress;
if (feePayerPresent) {
feePayerAddress = AccountAddress.deserialize(deserializer);
}
return new MultiAgentTransaction(rawTransaction, secondarySignerAddresses, feePayerAddress);
}
}
//# sourceMappingURL=multiAgentTransaction.js.map