Skip to content

Commit

Permalink
Return signature from sendAndConfirmTransaction (solana-labs#203)
Browse files Browse the repository at this point in the history
  • Loading branch information
jstarry authored Aug 3, 2020
1 parent ef94e22 commit ef75a1d
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 142 deletions.
6 changes: 3 additions & 3 deletions token-swap/js/client/token-swap.js
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ export class TokenSwap {
destination: PublicKey,
tokenProgramId: PublicKey,
amount: number | Numberu64,
): Promise<?TransactionSignature> {
): Promise<TransactionSignature> {
return await sendAndConfirmTransaction(
'swap',
this.connection,
Expand Down Expand Up @@ -373,7 +373,7 @@ export class TokenSwap {
poolAccount: PublicKey,
tokenProgramId: PublicKey,
amount: number | Numberu64,
): Promise<?TransactionSignature> {
): Promise<TransactionSignature> {
return await sendAndConfirmTransaction(
'deposit',
this.connection,
Expand Down Expand Up @@ -459,7 +459,7 @@ export class TokenSwap {
userAccountB: PublicKey,
tokenProgramId: PublicKey,
amount: number | Numberu64,
): Promise<?TransactionSignature> {
): Promise<TransactionSignature> {
return await sendAndConfirmTransaction(
'withdraw',
this.connection,
Expand Down
52 changes: 13 additions & 39 deletions token-swap/js/client/util/send-and-confirm-transaction.js
Original file line number Diff line number Diff line change
@@ -1,47 +1,21 @@
// @flow

import {sendAndConfirmTransaction as realSendAndConfirmTransaction} from '@solana/web3.js';
import type {Account, Connection, Transaction} from '@solana/web3.js';
import YAML from 'json-to-pretty-yaml';

type TransactionNotification = (string, string) => void;

let notify: TransactionNotification = () => undefined;

export function onTransaction(callback: TransactionNotification) {
notify = callback;
}

export async function sendAndConfirmTransaction(
import type {
Account,
Connection,
Transaction,
TransactionSignature,
} from '@solana/web3.js';

export function sendAndConfirmTransaction(
title: string,
connection: Connection,
transaction: Transaction,
...signers: Array<Account>
): Promise<void> {
const when = Date.now();

const signature = await realSendAndConfirmTransaction(
connection,
transaction,
signers,
{
confirmations: 1,
skipPreflight: true,
},
);

const body = {
time: new Date(when).toString(),
from: signers[0].publicKey.toBase58(),
signature,
instructions: transaction.instructions.map(i => {
return {
keys: i.keys.map(keyObj => keyObj.pubkey.toBase58()),
programId: i.programId.toBase58(),
data: '0x' + i.data.toString('hex'),
};
}),
};

notify(title, YAML.stringify(body).replace(/"/g, ''));
): Promise<TransactionSignature> {
return realSendAndConfirmTransaction(connection, transaction, signers, {
confirmations: 1,
skipPreflight: true,
});
}
2 changes: 1 addition & 1 deletion token/js/client/token.js
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ export class Token {
authority: any,
multiSigners: Array<Account>,
amount: number | u64,
): Promise<?TransactionSignature> {
): Promise<TransactionSignature> {
let ownerPublicKey;
let signers;
if (isAccount(authority)) {
Expand Down
52 changes: 13 additions & 39 deletions token/js/client/util/send-and-confirm-transaction.js
Original file line number Diff line number Diff line change
@@ -1,47 +1,21 @@
// @flow

import {sendAndConfirmTransaction as realSendAndConfirmTransaction} from '@solana/web3.js';
import type {Account, Connection, Transaction} from '@solana/web3.js';
import YAML from 'json-to-pretty-yaml';

type TransactionNotification = (string, string) => void;

let notify: TransactionNotification = () => undefined;

export function onTransaction(callback: TransactionNotification) {
notify = callback;
}

export async function sendAndConfirmTransaction(
import type {
Account,
Connection,
Transaction,
TransactionSignature,
} from '@solana/web3.js';

export function sendAndConfirmTransaction(
title: string,
connection: Connection,
transaction: Transaction,
...signers: Array<Account>
): Promise<void> {
const when = Date.now();

const signature = await realSendAndConfirmTransaction(
connection,
transaction,
signers,
{
confirmations: 1,
skipPreflight: true,
},
);

const body = {
time: new Date(when).toString(),
from: signers[0].publicKey.toBase58(),
signature,
instructions: transaction.instructions.map(i => {
return {
keys: i.keys.map(keyObj => keyObj.pubkey.toBase58()),
programId: i.programId.toBase58(),
data: '0x' + i.data.toString('hex'),
};
}),
};

notify(title, YAML.stringify(body).replace(/"/g, ''));
): Promise<TransactionSignature> {
return realSendAndConfirmTransaction(connection, transaction, signers, {
confirmations: 1,
skipPreflight: true,
});
}
38 changes: 0 additions & 38 deletions token/js/flow-typed/json-to-pretty-yaml.js

This file was deleted.

2 changes: 1 addition & 1 deletion token/js/module.flow.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ declare module '@solana/spl-token' {
authority: Account | PublicKey,
multiSigners: Array<Account>,
amount: number | u64,
): Promise<?TransactionSignature>;
): Promise<TransactionSignature>;
approve(
account: PublicKey,
delegate: PublicKey,
Expand Down
19 changes: 0 additions & 19 deletions token/js/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion token/js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
"bn.js": "^5.0.0",
"buffer-layout": "^1.2.0",
"dotenv": "8.2.0",
"json-to-pretty-yaml": "^1.2.2",
"mkdirp-promise": "^5.0.1"
},
"devDependencies": {
Expand Down
1 change: 0 additions & 1 deletion token/js/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ function generateConfig(configType) {
'bn.js',
'buffer-layout',
'@solana/web3.js',
'json-to-pretty-yaml',
];
break;
default:
Expand Down

0 comments on commit ef75a1d

Please sign in to comment.