| 
									
										
										
										
											2019-05-09 13:43:39 -07:00
										 |  |  | #!/usr/bin/env bash
 | 
					
						
							| 
									
										
										
										
											2019-07-26 19:00:34 -07:00
										 |  |  | # | 
					
						
							|  |  |  | # A thin wrapper around `solana-replicator` that automatically provisions the | 
					
						
							|  |  |  | # replicator's identity and/or storage keypair if not provided by the caller. | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | set -e | 
					
						
							| 
									
										
										
										
											2019-05-09 13:43:39 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | here=$(dirname "$0") | 
					
						
							| 
									
										
										
										
											2019-07-26 19:00:34 -07:00
										 |  |  | # shellcheck source=multinode-demo/common.sh | 
					
						
							|  |  |  | source "$here"/common.sh | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | entrypoint=127.0.0.0:8001 | 
					
						
							|  |  |  | label= | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | while [[ -n $1 ]]; do | 
					
						
							|  |  |  |   if [[ ${1:0:1} = - ]]; then | 
					
						
							|  |  |  |     if [[ $1 = --entrypoint ]]; then | 
					
						
							|  |  |  |       entrypoint=$2 | 
					
						
							|  |  |  |       args+=("$1" "$2") | 
					
						
							|  |  |  |       shift 2 | 
					
						
							|  |  |  |     elif [[ $1 = --identity ]]; then | 
					
						
							|  |  |  |       identity_keypair=$2 | 
					
						
							|  |  |  |       [[ -r $identity_keypair ]] || { | 
					
						
							|  |  |  |         echo "$identity_keypair does not exist" | 
					
						
							|  |  |  |         exit 1 | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       args+=("$1" "$2") | 
					
						
							|  |  |  |       shift 2 | 
					
						
							|  |  |  |     elif [[ $1 = --label ]]; then | 
					
						
							|  |  |  |       label="-$2" | 
					
						
							|  |  |  |       shift 2 | 
					
						
							|  |  |  |     elif [[ $1 = --ledger ]]; then | 
					
						
							|  |  |  |       args+=("$1" "$2") | 
					
						
							|  |  |  |       shift 2 | 
					
						
							|  |  |  |     elif [[ $1 = --storage-keypair ]]; then | 
					
						
							|  |  |  |       storage_keypair=$2 | 
					
						
							|  |  |  |       [[ -r $storage_keypair ]] || { | 
					
						
							|  |  |  |         echo "$storage_keypair does not exist" | 
					
						
							|  |  |  |         exit 1 | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       args+=("$1" "$2") | 
					
						
							|  |  |  |       shift 2 | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |       echo "Unknown argument: $1" | 
					
						
							|  |  |  |       $solana_replicator --help | 
					
						
							|  |  |  |       exit 1 | 
					
						
							|  |  |  |     fi | 
					
						
							|  |  |  |   else | 
					
						
							|  |  |  |     echo "Unknown argument: $1" | 
					
						
							|  |  |  |     $solana_replicator --help | 
					
						
							|  |  |  |     exit 1 | 
					
						
							|  |  |  |   fi | 
					
						
							|  |  |  | done | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : "${identity_keypair:="$SOLANA_ROOT"/farf/replicator-identity-keypair"$label".json}" | 
					
						
							| 
									
										
										
										
											2019-07-30 22:43:47 -07:00
										 |  |  | : "${storage_keypair:="$SOLANA_ROOT"/farf/replicator-storage-keypair"$label".json}" | 
					
						
							| 
									
										
										
										
											2019-07-26 19:00:34 -07:00
										 |  |  | ledger="$SOLANA_ROOT"/farf/replicator-ledger"$label" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-13 10:49:48 -07:00
										 |  |  | rpc_url=$($solana_gossip get-rpc-url --entrypoint "$entrypoint") | 
					
						
							| 
									
										
										
										
											2019-07-26 19:00:34 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | if [[ ! -r $identity_keypair ]]; then | 
					
						
							|  |  |  |   $solana_keygen new -o "$identity_keypair" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   # TODO: https://github.com/solana-labs/solminer/blob/9cd2289/src/replicator.js#L17-L18 | 
					
						
							| 
									
										
										
										
											2019-08-22 13:51:16 -07:00
										 |  |  |   $solana_cli --keypair "$identity_keypair" --url "$rpc_url" \
 | 
					
						
							| 
									
										
										
										
											2019-09-10 17:16:40 -06:00
										 |  |  |       airdrop 100000 lamports | 
					
						
							| 
									
										
										
										
											2019-07-26 19:00:34 -07:00
										 |  |  | fi | 
					
						
							|  |  |  | identity_pubkey=$($solana_keygen pubkey "$identity_keypair") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | if [[ ! -r $storage_keypair ]]; then | 
					
						
							|  |  |  |   $solana_keygen new -o "$storage_keypair" | 
					
						
							|  |  |  |   storage_pubkey=$($solana_keygen pubkey "$storage_keypair") | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-22 13:51:16 -07:00
										 |  |  |   $solana_cli --keypair "$identity_keypair" --url "$rpc_url" \
 | 
					
						
							| 
									
										
										
										
											2019-07-26 19:00:34 -07:00
										 |  |  |     create-replicator-storage-account "$identity_pubkey" "$storage_pubkey" | 
					
						
							|  |  |  | fi | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | default_arg --entrypoint "$entrypoint" | 
					
						
							|  |  |  | default_arg --identity "$identity_keypair" | 
					
						
							|  |  |  | default_arg --storage-keypair "$storage_keypair" | 
					
						
							|  |  |  | default_arg --ledger "$ledger" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | set -x | 
					
						
							|  |  |  | # shellcheck disable=SC2086 # Don't want to double quote $solana_replicator | 
					
						
							|  |  |  | exec $solana_replicator "${args[@]}" |