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

Add Support to submit bcs serialized transactions #124

Merged
merged 5 commits into from
Apr 24, 2023
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
5 changes: 5 additions & 0 deletions .changeset/good-ravens-build.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@aptos-labs/wallet-adapter-core": minor
---

Support to submit bcs serialized transactions
34 changes: 31 additions & 3 deletions packages/wallet-adapter-core/src/WalletCore.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { HexString, Types } from "aptos";
import { HexString, TxnBuilderTypes, Types } from "aptos";
import EventEmitter from "eventemitter3";
import nacl from "tweetnacl";
import { Buffer } from "buffer";
Expand Down Expand Up @@ -233,8 +233,8 @@ export class WalletCore extends EventEmitter<WalletCoreEvents> {
}

/**
Sign and submit transaction to chain.
@param transaction
Sign and submit an entry (not bcs serialized) transaction type to chain.
@param transaction a non-bcs serialized transaction
@return response from the wallet's signAndSubmitTransaction function
@throws WalletSignAndSubmitMessageError
*/
Expand All @@ -254,6 +254,34 @@ export class WalletCore extends EventEmitter<WalletCoreEvents> {
}
}

/**
Sign and submit a bsc serialized transaction type to chain.
@param transaction a bcs serialized transaction
@return response from the wallet's signAndSubmitBCSTransaction function
@throws WalletSignAndSubmitMessageError
*/
async signAndSubmitBCSTransaction(
transaction: TxnBuilderTypes.TransactionPayload
): Promise<any> {
if (this._wallet && !("signAndSubmitBCSTransaction" in this._wallet)) {
throw new WalletNotSupportedMethod(
`Submit a BCS Transaction is not supported by ${this.wallet?.name}`
).message;
}

try {
this.doesWalletExist();
const response = await (this._wallet as any).signAndSubmitBCSTransaction(
transaction
);
return response;
} catch (error: any) {
const errMsg =
typeof error == "object" && "message" in error ? error.message : error;
throw new WalletSignAndSubmitMessageError(errMsg).message;
}
}

/**
Sign transaction (doesnt submit to chain).
@param transaction
Expand Down