Class: Coinbase::FaucetTransaction

Inherits:
Object
  • Object
show all
Defined in:
lib/coinbase/faucet_transaction.rb

Overview

A representation of a transaction from a faucet. a user-controlled Wallet to another address. The fee is assumed to be paid in the native Asset of the Network. Transfers should be created through Wallet#transfer or Address#transfer.

Instance Method Summary collapse

Constructor Details

#initialize(model) ⇒ FaucetTransaction

Returns a new FaucetTransaction object. Do not use this method directly - instead, use Address#faucet.

Parameters:



11
12
13
# File 'lib/coinbase/faucet_transaction.rb', line 11

def initialize(model)
  @model = model
end

Instance Method Details

#inspectString

Same as to_s.

Returns:

  • (String)

    a String representation of the FaucetTransaction



93
94
95
# File 'lib/coinbase/faucet_transaction.rb', line 93

def inspect
  to_s
end

#networkCoinbase::Network

Returns the Network of the Transaction.

Returns:



41
42
43
# File 'lib/coinbase/faucet_transaction.rb', line 41

def network
  transaction.network
end

#reloadObject



66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/coinbase/faucet_transaction.rb', line 66

def reload
  @model = Coinbase.call_api do
    addresses_api.get_faucet_transaction(
      network.normalized_id,
      transaction.to_address_id,
      transaction_hash
    )
  end

  @transaction = Coinbase::Transaction.new(@model.transaction)

  self
end

#statusSymbol

Returns the status of the Faucet transaction.

Returns:

  • (Symbol)

    The status



23
24
25
# File 'lib/coinbase/faucet_transaction.rb', line 23

def status
  transaction.status
end

#to_sString

Returns a String representation of the FaucetTransaction.

Returns:

  • (String)

    a String representation of the FaucetTransaction



82
83
84
85
86
87
88
89
# File 'lib/coinbase/faucet_transaction.rb', line 82

def to_s
  Coinbase.pretty_print_object(
    self.class,
    status: transaction.status,
    transaction_hash: transaction_hash,
    transaction_link: transaction_link
  )
end

#transactionCoinbase::Transaction

Returns the Faucet transaction.

Returns:



17
18
19
# File 'lib/coinbase/faucet_transaction.rb', line 17

def transaction
  @transaction ||= Coinbase::Transaction.new(@model.transaction)
end

#transaction_hashString

Returns the transaction hash.

Returns:

  • (String)

    The onchain transaction hash



29
30
31
# File 'lib/coinbase/faucet_transaction.rb', line 29

def transaction_hash
  transaction.transaction_hash
end

Returns the link to the transaction on the blockchain explorer.

Returns:

  • (String)

    The link to the transaction on the blockchain explorer



35
36
37
# File 'lib/coinbase/faucet_transaction.rb', line 35

def transaction_link
  transaction.transaction_link
end

#wait!(interval_seconds = 0.2, timeout_seconds = 20) ⇒ Transfer

Waits until the FaucetTransaction is completed or failed by polling on the given interval.

Parameters:

  • interval_seconds (Integer) (defaults to: 0.2)

    The interval at which to poll the Network, in seconds

  • timeout_seconds (Integer) (defaults to: 20)

    The maximum amount of time to wait for the Transfer to complete, in seconds

Returns:

  • (Transfer)

    The completed Transfer object

Raises:

  • (Timeout::Error)

    if the FaucetTransaction takes longer than the given timeout



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/coinbase/faucet_transaction.rb', line 50

def wait!(interval_seconds = 0.2, timeout_seconds = 20)
  start_time = Time.now

  loop do
    reload

    return self if transaction.terminal_state?

    raise Timeout::Error, 'Faucet transaction timed out' if Time.now - start_time > timeout_seconds

    self.sleep interval_seconds
  end

  self
end