Module: SolanaRuby::HttpMethods::TransactionMethods
- Defined in:
- lib/solana_ruby/http_methods/transaction_methods.rb
Overview
Transaction Related HTTP Methods
Constant Summary collapse
- DEFAULT_COMMITMENT =
"finalized"
- TIMEOUT =
seconds
60
- RETRY_INTERVAL =
seconds
2
- ENCODED_TRANSACTION_OPTIONS =
{ skipPreflight: false }.freeze
- FINALIZED_OPTIONS =
{ commitment: "finalized" }.freeze
Instance Method Summary collapse
- #confirm_transaction(signature, commitment = DEFAULT_COMMITMENT, timeout = TIMEOUT) ⇒ Object
- #get_transaction(signature, options = {}) ⇒ Object
- #get_transaction_count(options = FINALIZED_OPTIONS) ⇒ Object
- #get_transactions(signatures, options = FINALIZED_OPTIONS) ⇒ Object
- #request_airdrop(pubkey, lamports, options = FINALIZED_OPTIONS) ⇒ Object
- #send_encoded_transaction(encoded_transaction, options = ENCODED_TRANSACTION_OPTIONS.merge(FINALIZED_OPTIONS)) ⇒ Object
- #send_raw_transaction(raw_transaction, options = ENCODED_TRANSACTION_OPTIONS.merge(FINALIZED_OPTIONS)) ⇒ Object
- #send_transaction(signed_transaction, options = {}) ⇒ Object
- #simulate_transaction(transaction, options = { encoding: "base64" }) ⇒ Object
Instance Method Details
#confirm_transaction(signature, commitment = DEFAULT_COMMITMENT, timeout = TIMEOUT) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/solana_ruby/http_methods/transaction_methods.rb', line 19 def confirm_transaction(signature, commitment = DEFAULT_COMMITMENT, timeout = TIMEOUT) start_time = Time.now loop do # Fetch transaction status = { searchTransactionHistory: true } status_info = get_signature_status(signature, ) # Check if the transaction is confirmed based on the commitment level if status_info && (status_info["confirmationStatus"] == commitment || status_info["confirmationStatus"] == "confirmed") return true end # Break the loop if timeout is reached if Time.now - start_time > timeout raise "Transaction #{signature} was not confirmed within #{timeout} seconds." end sleep(RETRY_INTERVAL) end end |
#get_transaction(signature, options = {}) ⇒ Object
41 42 43 44 45 |
# File 'lib/solana_ruby/http_methods/transaction_methods.rb', line 41 def get_transaction(signature, = {}) params = [signature, ] response = request("getTransaction", params) response["result"] end |
#get_transaction_count(options = FINALIZED_OPTIONS) ⇒ Object
47 48 49 50 |
# File 'lib/solana_ruby/http_methods/transaction_methods.rb', line 47 def get_transaction_count( = FINALIZED_OPTIONS) result = request("getTransactionCount", []) result["result"] end |
#get_transactions(signatures, options = FINALIZED_OPTIONS) ⇒ Object
52 53 54 55 56 57 58 59 |
# File 'lib/solana_ruby/http_methods/transaction_methods.rb', line 52 def get_transactions(signatures, = FINALIZED_OPTIONS) transactions = [] signatures.each do |signature| transaction = get_transaction(signature, ) transactions << transaction end transactions end |
#request_airdrop(pubkey, lamports, options = FINALIZED_OPTIONS) ⇒ Object
61 62 63 64 65 |
# File 'lib/solana_ruby/http_methods/transaction_methods.rb', line 61 def request_airdrop(pubkey, lamports, = FINALIZED_OPTIONS) params = [pubkey, lamports, ] response = request("requestAirdrop", params) response["result"] end |
#send_encoded_transaction(encoded_transaction, options = ENCODED_TRANSACTION_OPTIONS.merge(FINALIZED_OPTIONS)) ⇒ Object
73 74 75 |
# File 'lib/solana_ruby/http_methods/transaction_methods.rb', line 73 def send_encoded_transaction(encoded_transaction, = ENCODED_TRANSACTION_OPTIONS.merge(FINALIZED_OPTIONS)) send_transaction(encoded_transaction, ) end |
#send_raw_transaction(raw_transaction, options = ENCODED_TRANSACTION_OPTIONS.merge(FINALIZED_OPTIONS)) ⇒ Object
77 78 79 80 81 82 |
# File 'lib/solana_ruby/http_methods/transaction_methods.rb', line 77 def send_raw_transaction(raw_transaction, = ENCODED_TRANSACTION_OPTIONS.merge(FINALIZED_OPTIONS)) # Convert the raw hexadecimal transaction to base64 encoding base64_encoded_transaction = Base64.encode64(raw_transaction) send_transaction(base64_encoded_transaction, ) end |
#send_transaction(signed_transaction, options = {}) ⇒ Object
13 14 15 16 17 |
# File 'lib/solana_ruby/http_methods/transaction_methods.rb', line 13 def send_transaction(signed_transaction, = {}) params = [signed_transaction, ] result = request("sendTransaction", params) result["result"] end |
#simulate_transaction(transaction, options = { encoding: "base64" }) ⇒ Object
67 68 69 70 71 |
# File 'lib/solana_ruby/http_methods/transaction_methods.rb', line 67 def simulate_transaction(transaction, = { encoding: "base64" }) params = [transaction, ] response = request("simulateTransaction", params) response["result"] end |