Skip to content

Commit

Permalink
Add Support to submit bcs serialized transactions (#124)
Browse files Browse the repository at this point in the history
* submit bcs transaction support

* update changelog

* rename function

* update doc

* update doc
  • Loading branch information
0xmaayan authored Apr 24, 2023
1 parent 5afd0ac commit 50968c4
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
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

0 comments on commit 50968c4

Please sign in to comment.