-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
STREAM-554: fix aptos metadata id deriving (#95)
* STREAM-554: fix aptos metadata id deriving, separate wallet from types
- Loading branch information
Showing
7 changed files
with
147 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { | ||
AptosAccount, | ||
AptosClient, | ||
Types, | ||
TransactionBuilderRemoteABI, | ||
MaybeHexString, | ||
} from "aptos"; | ||
import { WalletContextState } from "@manahippo/aptos-wallet-adapter"; | ||
|
||
export class AptosWalletWrapper<T extends WalletContextState | AptosAccount> { | ||
wallet: T; | ||
|
||
address: MaybeHexString; | ||
|
||
client: AptosClient; | ||
|
||
constructor(wallet: T, client: AptosClient) { | ||
this.client = client; | ||
this.wallet = wallet; | ||
if (wallet instanceof AptosAccount) { | ||
this.address = wallet.address(); | ||
} else { | ||
this.address = wallet.account!.address!; | ||
} | ||
} | ||
|
||
public async signAndSubmitTransaction( | ||
input: Types.TransactionPayload_EntryFunctionPayload | ||
): Promise<string> { | ||
if (this.wallet instanceof AptosAccount) { | ||
const builder = new TransactionBuilderRemoteABI(this.client, { | ||
sender: this.address, | ||
}); | ||
const rawTxn = await builder.build(input.function, input.type_arguments, input.arguments); | ||
const signedTx = await this.client.signTransaction(this.wallet, rawTxn); | ||
const tx = await this.client.submitSignedBCSTransaction(signedTx); | ||
await this.client.waitForTransaction(tx.hash); | ||
return tx.hash; | ||
} | ||
return (await this.wallet.signAndSubmitTransaction(input)).hash; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { Keypair } from "@mysten/sui.js/cryptography"; | ||
import { WalletContextState } from "@suiet/wallet-kit"; | ||
import { SuiClient, SuiTransactionBlockResponse } from "@mysten/sui.js/client"; | ||
|
||
import { SuiSignAndExecuteTransactionBlockInput } from "./types"; | ||
|
||
export class SuiWalletWrapper<T extends WalletContextState | Keypair> { | ||
wallet: T; | ||
|
||
address: string; | ||
|
||
client: SuiClient; | ||
|
||
constructor(wallet: T, client: SuiClient) { | ||
this.client = client; | ||
this.wallet = wallet; | ||
if (wallet instanceof Keypair) { | ||
this.address = wallet.toSuiAddress(); | ||
} else { | ||
this.address = wallet.address!; | ||
} | ||
} | ||
|
||
public async signAndExecuteTransactionBlock( | ||
input: SuiSignAndExecuteTransactionBlockInput | ||
): Promise<SuiTransactionBlockResponse> { | ||
if (this.wallet instanceof Keypair) { | ||
return this.client.signAndExecuteTransactionBlock({ | ||
...input, | ||
signer: this.wallet, | ||
}); | ||
} | ||
return this.wallet.signAndExecuteTransactionBlock(input); | ||
} | ||
} |