File tree Expand file tree Collapse file tree 2 files changed +38
-0
lines changed Expand file tree Collapse file tree 2 files changed +38
-0
lines changed Original file line number Diff line number Diff line change 1+ // @flow
2+
3+ import { Connection , Transaction } from '..' ;
4+
5+ import { sleep } from './sleep' ;
6+
7+ import type { Account } from '..' ;
8+
9+ /**
10+ * Sign, send and confirm a transaction
11+ */
12+ export async function sendAndConfirmTransaction (
13+ connection : Connection ,
14+ from : Account ,
15+ transaction : Transaction ,
16+ runtimeErrorOk : boolean = false
17+ ) : Promise < void > {
18+ const signature = await connection . sendTransaction ( from , transaction ) ;
19+
20+ // Wait up to a couple seconds for a confirmation
21+ let i = 4 ;
22+ for ( ; ; ) {
23+ const status = await connection . getSignatureStatus ( signature ) ;
24+ if ( status == 'Confirmed' ) return ;
25+ if ( runtimeErrorOk && status == 'ProgramRuntimeError' ) return ;
26+ await sleep ( 500 ) ;
27+ if ( -- i < 0 ) {
28+ throw new Error ( `Transaction '${ signature } ' was not confirmed (${ status } )` ) ;
29+ }
30+ }
31+ }
32+
Original file line number Diff line number Diff line change 1+ // @flow
2+
3+ // zzz
4+ export function sleep ( ms : number ) : Promise < void > {
5+ return new Promise ( resolve => setTimeout ( resolve , ms ) ) ;
6+ }
You can’t perform that action at this time.
0 commit comments