feat: add commitment param to JSON RPC API requests (#549)
* feat: add commitment param to json rpc requests * fix: tests and examples * fix: docs * fix: epoch info test * fix: budget example * fix: test timeout * fix: remove MAX_COMMITMENT and RECENT_COMMITMENT types
This commit is contained in:
committed by
Michael Vines
parent
d0c89f7fa3
commit
189807f5a5
@@ -1,6 +1,7 @@
|
||||
// @flow
|
||||
|
||||
import {Connection} from '../connection';
|
||||
import type {Commitment} from '../connection';
|
||||
import {sleep} from './sleep';
|
||||
import type {TransactionSignature} from '../transaction';
|
||||
import {DEFAULT_TICKS_PER_SLOT, NUM_TICKS_PER_SECOND} from '../timing';
|
||||
@@ -11,6 +12,7 @@ import {DEFAULT_TICKS_PER_SLOT, NUM_TICKS_PER_SECOND} from '../timing';
|
||||
export async function sendAndConfirmRawTransaction(
|
||||
connection: Connection,
|
||||
rawTransaction: Buffer,
|
||||
commitment: ?Commitment,
|
||||
): Promise<TransactionSignature> {
|
||||
const start = Date.now();
|
||||
let signature = await connection.sendRawTransaction(rawTransaction);
|
||||
@@ -19,7 +21,7 @@ export async function sendAndConfirmRawTransaction(
|
||||
let status = null;
|
||||
let statusRetries = 6;
|
||||
for (;;) {
|
||||
status = await connection.getSignatureStatus(signature);
|
||||
status = await connection.getSignatureStatus(signature, commitment);
|
||||
if (status) {
|
||||
break;
|
||||
}
|
||||
|
@@ -3,12 +3,29 @@
|
||||
import invariant from 'assert';
|
||||
|
||||
import {Connection} from '../connection';
|
||||
import type {Commitment} from '../connection';
|
||||
import {Transaction} from '../transaction';
|
||||
import {sleep} from './sleep';
|
||||
import type {Account} from '../account';
|
||||
import type {TransactionSignature} from '../transaction';
|
||||
import {DEFAULT_TICKS_PER_SLOT, NUM_TICKS_PER_SECOND} from '../timing';
|
||||
|
||||
/**
|
||||
* Sign, send and confirm a transaction with recent commitment level
|
||||
*/
|
||||
export async function sendAndConfirmRecentTransaction(
|
||||
connection: Connection,
|
||||
transaction: Transaction,
|
||||
...signers: Array<Account>
|
||||
): Promise<TransactionSignature> {
|
||||
return await _sendAndConfirmTransaction(
|
||||
connection,
|
||||
transaction,
|
||||
signers,
|
||||
'recent',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sign, send and confirm a transaction
|
||||
*/
|
||||
@@ -16,6 +33,15 @@ export async function sendAndConfirmTransaction(
|
||||
connection: Connection,
|
||||
transaction: Transaction,
|
||||
...signers: Array<Account>
|
||||
): Promise<TransactionSignature> {
|
||||
return await _sendAndConfirmTransaction(connection, transaction, signers);
|
||||
}
|
||||
|
||||
async function _sendAndConfirmTransaction(
|
||||
connection: Connection,
|
||||
transaction: Transaction,
|
||||
signers: Array<Account>,
|
||||
commitment: ?Commitment,
|
||||
): Promise<TransactionSignature> {
|
||||
let sendRetries = 10;
|
||||
let signature;
|
||||
@@ -27,7 +53,7 @@ export async function sendAndConfirmTransaction(
|
||||
let status = null;
|
||||
let statusRetries = 6;
|
||||
for (;;) {
|
||||
status = await connection.getSignatureStatus(signature);
|
||||
status = await connection.getSignatureStatus(signature, commitment);
|
||||
if (status) {
|
||||
break;
|
||||
}
|
||||
|
Reference in New Issue
Block a user