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 versioned transaction methods to adapter interface #558

Merged
merged 39 commits into from
Sep 15, 2022
Merged
Changes from 1 commit
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
5269c16
Bump @solana/web3.js version to v1.59.1
jstarry Sep 12, 2022
5ce4a3c
Add versioned transaction methods to adapter interface
jstarry Sep 8, 2022
1529a5b
feedback
jstarry Sep 12, 2022
9ce97d6
update web3.js consistent with master
jordaaash Sep 13, 2022
d5e9fd8
Merge branch 'master' into versioned-tx
jordaaash Sep 13, 2022
6762d53
update lockfile
jordaaash Sep 13, 2022
8098e7b
organize imports, lint fix
jordaaash Sep 13, 2022
f2f13b2
refactor versioned transaction methods
jordaaash Sep 13, 2022
f395866
fix react types
jordaaash Sep 13, 2022
af2257a
add type guard for versioned txs
jordaaash Sep 13, 2022
f731ea1
alpha adapter test
jordaaash Sep 13, 2022
98ca6e8
fixes
jordaaash Sep 13, 2022
aed4d7a
fixes
jordaaash Sep 13, 2022
793b161
check out wallets from master
jordaaash Sep 14, 2022
4b9132b
add supportedTransactionVersions flag to wallets
jordaaash Sep 14, 2022
eb4011d
infer types
jordaaash Sep 14, 2022
20bc5ed
organize imports
jordaaash Sep 14, 2022
04a6205
have signAllTransactions check for versioned txs
jordaaash Sep 14, 2022
80d1d48
infer supportedTransactionVersions type from field
jordaaash Sep 15, 2022
f2d50d6
fix sign / signAll in all adapters
jordaaash Sep 15, 2022
46ef36c
remove hack
jordaaash Sep 15, 2022
a46ff71
Add versioned transaction methods to adapter interface
jstarry Sep 8, 2022
43cde10
feedback
jstarry Sep 12, 2022
6505731
organize imports, lint fix
jordaaash Sep 13, 2022
aa1e381
refactor versioned transaction methods
jordaaash Sep 13, 2022
1e8b5ee
fix react types
jordaaash Sep 13, 2022
87b3943
add type guard for versioned txs
jordaaash Sep 13, 2022
6cc7d90
alpha adapter test
jordaaash Sep 13, 2022
4369e40
fixes
jordaaash Sep 13, 2022
8819905
fixes
jordaaash Sep 13, 2022
bde0bb2
check out wallets from master
jordaaash Sep 14, 2022
c2d14da
add supportedTransactionVersions flag to wallets
jordaaash Sep 14, 2022
a801e06
infer types
jordaaash Sep 14, 2022
ebe79ec
organize imports
jordaaash Sep 14, 2022
1c0b0f6
have signAllTransactions check for versioned txs
jordaaash Sep 14, 2022
6266bd8
infer supportedTransactionVersions type from field
jordaaash Sep 15, 2022
6533919
fix sign / signAll in all adapters
jordaaash Sep 15, 2022
18878eb
remove hack
jordaaash Sep 15, 2022
ddf04df
Merge branch 'versioned-tx' of https://github.com/jstarry/wallet-adap…
jordaaash Sep 15, 2022
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
Prev Previous commit
Next Next commit
fix sign / signAll in all adapters
jordaaash authored and jstarry committed Sep 15, 2022

Verified

This commit was signed with the committer’s verified signature.
camdencheek Camden Cheek
commit 6533919d8afb665e4b0a3d96efc4bb70263b31d0
8 changes: 4 additions & 4 deletions packages/wallets/alpha/src/adapter.ts
Original file line number Diff line number Diff line change
@@ -186,13 +186,13 @@ export class AlphaWalletAdapter extends BaseMessageSignerWalletAdapter {
}
}

async signTransaction(transaction: Transaction): Promise<Transaction> {
async signTransaction<T extends Transaction>(transaction: T): Promise<T> {
Copy link
Collaborator

@jordaaash jordaaash Sep 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We know that transaction will only ever be Transaction now because supportedTransactionVersions is null, but we still have to implement it this way because the interface declares it like this. All this means is that if a subtype of Transaction was passed to signTransaction, the wallet should return the same subtype. In practice, this doesn't matter because there are no subclasses of Transaction in web3.js to worry about.

try {
const wallet = this._wallet;
if (!wallet) throw new WalletNotConnectedError();

try {
return (await wallet.signTransaction(transaction)) || transaction;
return ((await wallet.signTransaction(transaction)) as T) || transaction;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we have to perform the one ugly bit, where we cast Transaction as T even though we know it will be valid.

} catch (error: any) {
throw new WalletSignTransactionError(error?.message, error);
}
@@ -202,13 +202,13 @@ export class AlphaWalletAdapter extends BaseMessageSignerWalletAdapter {
}
}

async signAllTransactions(transactions: Transaction[]): Promise<Transaction[]> {
async signAllTransactions<T extends Transaction>(transactions: T[]): Promise<T[]> {
try {
const wallet = this._wallet;
if (!wallet) throw new WalletNotConnectedError();

try {
return (await wallet.signAllTransactions(transactions)) || transactions;
return ((await wallet.signAllTransactions(transactions)) as T[]) || transactions;
} catch (error: any) {
throw new WalletSignTransactionError(error?.message, error);
}
8 changes: 4 additions & 4 deletions packages/wallets/avana/src/adapter.ts
Original file line number Diff line number Diff line change
@@ -188,13 +188,13 @@ export class AvanaWalletAdapter extends BaseMessageSignerWalletAdapter {
}
}

async signTransaction(transaction: Transaction): Promise<Transaction> {
async signTransaction<T extends Transaction>(transaction: T): Promise<T> {
try {
const wallet = this._wallet;
if (!wallet) throw new WalletNotConnectedError();

try {
return (await wallet.signTransaction(transaction)) || transaction;
return ((await wallet.signTransaction(transaction)) as T) || transaction;
} catch (error: any) {
throw new WalletSignTransactionError(error?.message, error);
}
@@ -204,13 +204,13 @@ export class AvanaWalletAdapter extends BaseMessageSignerWalletAdapter {
}
}

async signAllTransactions(transactions: Transaction[]): Promise<Transaction[]> {
async signAllTransactions<T extends Transaction>(transactions: T[]): Promise<T[]> {
try {
const wallet = this._wallet;
if (!wallet) throw new WalletNotConnectedError();

try {
return (await wallet.signAllTransactions(transactions)) || transactions;
return ((await wallet.signAllTransactions(transactions)) as T[]) || transactions;
} catch (error: any) {
throw new WalletSignTransactionError(error?.message, error);
}
8 changes: 4 additions & 4 deletions packages/wallets/backpack/src/adapter.ts
Original file line number Diff line number Diff line change
@@ -178,13 +178,13 @@ export class BackpackWalletAdapter extends BaseMessageSignerWalletAdapter {
}
}

async signTransaction(transaction: Transaction): Promise<Transaction> {
async signTransaction<T extends Transaction>(transaction: T): Promise<T> {
try {
const wallet = this._wallet;
if (!wallet) throw new WalletNotConnectedError();

try {
return await wallet.signTransaction(transaction, this.publicKey);
return (await wallet.signTransaction(transaction, this.publicKey)) as T;
} catch (error: any) {
throw new WalletSignTransactionError(error?.message, error);
}
@@ -194,13 +194,13 @@ export class BackpackWalletAdapter extends BaseMessageSignerWalletAdapter {
}
}

async signAllTransactions(transactions: Transaction[]): Promise<Transaction[]> {
async signAllTransactions<T extends Transaction>(transactions: T[]): Promise<T[]> {
try {
const wallet = this._wallet;
if (!wallet) throw new WalletNotConnectedError();

try {
return await wallet.signAllTransactions(transactions, this.publicKey);
return (await wallet.signAllTransactions(transactions, this.publicKey)) as T[];
} catch (error: any) {
throw new WalletSignTransactionError(error?.message, error);
}
8 changes: 4 additions & 4 deletions packages/wallets/bitkeep/src/adapter.ts
Original file line number Diff line number Diff line change
@@ -132,13 +132,13 @@ export class BitKeepWalletAdapter extends BaseMessageSignerWalletAdapter {
this.emit('disconnect');
}

async signTransaction(transaction: Transaction): Promise<Transaction> {
async signTransaction<T extends Transaction>(transaction: T): Promise<T> {
try {
const wallet = this._wallet;
if (!wallet) throw new WalletNotConnectedError();

try {
return (await wallet.signTransaction(transaction)) || transaction;
return ((await wallet.signTransaction(transaction)) as T) || transaction;
} catch (error: any) {
throw new WalletSignTransactionError(error?.message, error);
}
@@ -148,13 +148,13 @@ export class BitKeepWalletAdapter extends BaseMessageSignerWalletAdapter {
}
}

async signAllTransactions(transactions: Transaction[]): Promise<Transaction[]> {
async signAllTransactions<T extends Transaction>(transactions: T[]): Promise<T[]> {
try {
const wallet = this._wallet;
if (!wallet) throw new WalletNotConnectedError();

try {
return (await wallet.signAllTransactions(transactions)) || transactions;
return ((await wallet.signAllTransactions(transactions)) as T[]) || transactions;
} catch (error: any) {
throw new WalletSignTransactionError(error?.message, error);
}
8 changes: 4 additions & 4 deletions packages/wallets/bitpie/src/adapter.ts
Original file line number Diff line number Diff line change
@@ -117,13 +117,13 @@ export class BitpieWalletAdapter extends BaseSignerWalletAdapter {
this.emit('disconnect');
}

async signTransaction(transaction: Transaction): Promise<Transaction> {
async signTransaction<T extends Transaction>(transaction: T): Promise<T> {
try {
const wallet = this._wallet;
if (!wallet) throw new WalletNotConnectedError();

try {
return (await wallet.signTransaction(transaction)) || transaction;
return ((await wallet.signTransaction(transaction)) as T) || transaction;
} catch (error: any) {
throw new WalletSignTransactionError(error?.message, error);
}
@@ -133,13 +133,13 @@ export class BitpieWalletAdapter extends BaseSignerWalletAdapter {
}
}

async signAllTransactions(transactions: Transaction[]): Promise<Transaction[]> {
async signAllTransactions<T extends Transaction>(transactions: T[]): Promise<T[]> {
try {
const wallet = this._wallet;
if (!wallet) throw new WalletNotConnectedError();

try {
return (await wallet.signAllTransactions(transactions)) || transactions;
return ((await wallet.signAllTransactions(transactions)) as T[]) || transactions;
} catch (error: any) {
throw new WalletSignTransactionError(error?.message, error);
}
8 changes: 4 additions & 4 deletions packages/wallets/brave/src/adapter.ts
Original file line number Diff line number Diff line change
@@ -186,13 +186,13 @@ export class BraveWalletAdapter extends BaseMessageSignerWalletAdapter {
}
}

async signTransaction(transaction: Transaction): Promise<Transaction> {
async signTransaction<T extends Transaction>(transaction: T): Promise<T> {
try {
const wallet = this._wallet;
if (!wallet) throw new WalletNotConnectedError();

try {
return (await wallet.signTransaction(transaction)) || transaction;
return ((await wallet.signTransaction(transaction)) as T) || transaction;
} catch (error: any) {
throw new WalletSignTransactionError(error?.message, error);
}
@@ -202,13 +202,13 @@ export class BraveWalletAdapter extends BaseMessageSignerWalletAdapter {
}
}

async signAllTransactions(transactions: Transaction[]): Promise<Transaction[]> {
async signAllTransactions<T extends Transaction>(transactions: T[]): Promise<T[]> {
try {
const wallet = this._wallet;
if (!wallet) throw new WalletNotConnectedError();

try {
return (await wallet.signAllTransactions(transactions)) || transactions;
return ((await wallet.signAllTransactions(transactions)) as T[]) || transactions;
} catch (error: any) {
throw new WalletSignTransactionError(error?.message, error);
}
8 changes: 4 additions & 4 deletions packages/wallets/clover/src/adapter.ts
Original file line number Diff line number Diff line change
@@ -121,13 +121,13 @@ export class CloverWalletAdapter extends BaseMessageSignerWalletAdapter {
this.emit('disconnect');
}

async signTransaction(transaction: Transaction): Promise<Transaction> {
async signTransaction<T extends Transaction>(transaction: T): Promise<T> {
try {
const wallet = this._wallet;
if (!wallet) throw new WalletNotConnectedError();

try {
return (await wallet.signTransaction(transaction)) || transaction;
return ((await wallet.signTransaction(transaction)) as T) || transaction;
} catch (error: any) {
throw new WalletSignTransactionError(error?.message, error);
}
@@ -137,13 +137,13 @@ export class CloverWalletAdapter extends BaseMessageSignerWalletAdapter {
}
}

async signAllTransactions(transactions: Transaction[]): Promise<Transaction[]> {
async signAllTransactions<T extends Transaction>(transactions: T[]): Promise<T[]> {
try {
const wallet = this._wallet;
if (!wallet) throw new WalletNotConnectedError();

try {
return (await wallet.signAllTransactions(transactions)) || transactions;
return ((await wallet.signAllTransactions(transactions)) as T[]) || transactions;
} catch (error: any) {
throw new WalletSignTransactionError(error?.message, error);
}
4 changes: 2 additions & 2 deletions packages/wallets/coin98/src/adapter.ts
Original file line number Diff line number Diff line change
@@ -142,7 +142,7 @@ export class Coin98WalletAdapter extends BaseMessageSignerWalletAdapter {
this.emit('disconnect');
}

async signTransaction(transaction: Transaction): Promise<Transaction> {
async signTransaction<T extends Transaction>(transaction: T): Promise<T> {
try {
const wallet = this._wallet;
if (!wallet) throw new WalletNotConnectedError();
@@ -164,7 +164,7 @@ export class Coin98WalletAdapter extends BaseMessageSignerWalletAdapter {
}
}

async signAllTransactions(transactions: Transaction[]): Promise<Transaction[]> {
async signAllTransactions<T extends Transaction>(transactions: T[]): Promise<T[]> {
try {
const wallet = this._wallet;
if (!wallet) throw new WalletNotConnectedError();
8 changes: 4 additions & 4 deletions packages/wallets/coinbase/src/adapter.ts
Original file line number Diff line number Diff line change
@@ -177,13 +177,13 @@ export class CoinbaseWalletAdapter extends BaseMessageSignerWalletAdapter {
}
}

async signTransaction(transaction: Transaction): Promise<Transaction> {
async signTransaction<T extends Transaction>(transaction: T): Promise<T> {
try {
const wallet = this._wallet;
if (!wallet) throw new WalletNotConnectedError();

try {
return (await wallet.signTransaction(transaction)) || transaction;
return ((await wallet.signTransaction(transaction)) as T) || transaction;
} catch (error: any) {
throw new WalletSignTransactionError(error?.message, error);
}
@@ -193,13 +193,13 @@ export class CoinbaseWalletAdapter extends BaseMessageSignerWalletAdapter {
}
}

async signAllTransactions(transactions: Transaction[]): Promise<Transaction[]> {
async signAllTransactions<T extends Transaction>(transactions: T[]): Promise<T[]> {
try {
const wallet = this._wallet;
if (!wallet) throw new WalletNotConnectedError();

try {
return (await wallet.signAllTransactions(transactions)) || transactions;
return ((await wallet.signAllTransactions(transactions)) as T[]) || transactions;
} catch (error: any) {
throw new WalletSignTransactionError(error?.message, error);
}
8 changes: 4 additions & 4 deletions packages/wallets/coinhub/src/adapter.ts
Original file line number Diff line number Diff line change
@@ -119,13 +119,13 @@ export class CoinhubWalletAdapter extends BaseSignerWalletAdapter {
this.emit('disconnect');
}

async signTransaction(transaction: Transaction): Promise<Transaction> {
async signTransaction<T extends Transaction>(transaction: T): Promise<T> {
try {
const wallet = this._wallet;
if (!wallet) throw new WalletNotConnectedError();

try {
return wallet.signTransaction(transaction);
return (await wallet.signTransaction(transaction)) as T;
} catch (error: any) {
throw new WalletSignTransactionError(error?.message, error);
}
@@ -135,13 +135,13 @@ export class CoinhubWalletAdapter extends BaseSignerWalletAdapter {
}
}

async signAllTransactions(transactions: Transaction[]): Promise<Transaction[]> {
async signAllTransactions<T extends Transaction>(transactions: T[]): Promise<T[]> {
try {
const wallet = this._wallet;
if (!wallet) throw new WalletNotConnectedError();

try {
return wallet.signAllTransactions(transactions);
return (await wallet.signAllTransactions(transactions)) as T[];
} catch (error: any) {
throw new WalletSignTransactionError(error?.message, error);
}
8 changes: 4 additions & 4 deletions packages/wallets/exodus/src/adapter.ts
Original file line number Diff line number Diff line change
@@ -188,13 +188,13 @@ export class ExodusWalletAdapter extends BaseMessageSignerWalletAdapter {
}
}

async signTransaction(transaction: Transaction): Promise<Transaction> {
async signTransaction<T extends Transaction>(transaction: T): Promise<T> {
try {
const wallet = this._wallet;
if (!wallet) throw new WalletNotConnectedError();

try {
return await wallet.signTransaction(transaction);
return (await wallet.signTransaction(transaction)) as T;
} catch (error: any) {
throw new WalletSignTransactionError(error?.message, error);
}
@@ -204,13 +204,13 @@ export class ExodusWalletAdapter extends BaseMessageSignerWalletAdapter {
}
}

async signAllTransactions(transactions: Transaction[]): Promise<Transaction[]> {
async signAllTransactions<T extends Transaction>(transactions: T[]): Promise<T[]> {
try {
const wallet = this._wallet;
if (!wallet) throw new WalletNotConnectedError();

try {
return await wallet.signAllTransactions(transactions);
return (await wallet.signAllTransactions(transactions)) as T[];
} catch (error: any) {
throw new WalletSignTransactionError(error?.message, error);
}
8 changes: 4 additions & 4 deletions packages/wallets/glow/src/adapter.ts
Original file line number Diff line number Diff line change
@@ -211,13 +211,13 @@ export class GlowWalletAdapter extends BaseMessageSignerWalletAdapter {
}
}

async signTransaction(transaction: Transaction): Promise<Transaction> {
async signTransaction<T extends Transaction>(transaction: T): Promise<T> {
try {
const wallet = this._wallet;
if (!wallet) throw new WalletNotConnectedError();

try {
return (await wallet.signTransaction(transaction, this._network)) || transaction;
return ((await wallet.signTransaction(transaction, this._network)) as T) || transaction;
} catch (error: any) {
throw new WalletSignTransactionError(error?.message, error);
}
@@ -227,13 +227,13 @@ export class GlowWalletAdapter extends BaseMessageSignerWalletAdapter {
}
}

async signAllTransactions(transactions: Transaction[]): Promise<Transaction[]> {
async signAllTransactions<T extends Transaction>(transactions: T[]): Promise<T[]> {
try {
const wallet = this._wallet;
if (!wallet) throw new WalletNotConnectedError();

try {
return (await wallet.signAllTransactions(transactions, this._network)) || transactions;
return ((await wallet.signAllTransactions(transactions, this._network)) as T[]) || transactions;
} catch (error: any) {
throw new WalletSignTransactionError(error?.message, error);
}
Loading