Class: Coinbase::Transfer
- Inherits:
-
Object
- Object
- Coinbase::Transfer
- Defined in:
- lib/coinbase/transfer.rb
Overview
A representation of a Transfer, which moves an amount of an Asset from 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
-
#amount ⇒ BigDecimal
Returns the amount of the asset for the Transfer.
- #asset ⇒ Object
-
#asset_id ⇒ Symbol
Returns the Asset ID of the Transfer.
-
#destination_address_id ⇒ String
Returns the Destination Address ID of the Transfer.
-
#from_address_id ⇒ String
Returns the From Address ID of the Transfer.
-
#id ⇒ String
Returns the Transfer ID.
-
#initialize(model) ⇒ Transfer
constructor
Returns a new Transfer object.
-
#inspect ⇒ String
Same as to_s.
-
#network_id ⇒ Symbol
Returns the Network ID of the Transfer.
-
#reload ⇒ Transfer
Reload reloads the Transfer model with the latest version from the server side.
-
#signed_payload ⇒ String
Returns the Signed Payload of the Transfer.
-
#status ⇒ Symbol
Returns the status of the Transfer.
-
#to_s ⇒ String
Returns a String representation of the Transfer.
-
#transaction ⇒ Coinbase::Transaction
Returns the Transfer transaction.
-
#transaction_hash ⇒ String
Returns the Transaction Hash of the Transfer.
-
#transaction_link ⇒ String
Returns the link to the transaction on the blockchain explorer.
-
#unsigned_payload ⇒ String
Returns the Unsigned Payload of the Transfer.
-
#wait!(interval_seconds = 0.2, timeout_seconds = 20) ⇒ Transfer
Waits until the Transfer is completed or failed by polling the Network at the given interval.
-
#wallet_id ⇒ String
Returns the Wallet ID of the Transfer.
Constructor Details
Instance Method Details
#amount ⇒ BigDecimal
Returns the amount of the asset for the Transfer.
65 66 67 |
# File 'lib/coinbase/transfer.rb', line 65 def amount BigDecimal(@model.amount) / BigDecimal(10).power(@model.asset.decimals) end |
#asset ⇒ Object
53 54 55 |
# File 'lib/coinbase/transfer.rb', line 53 def asset @asset ||= Coinbase::Asset.from_model(@model.asset) end |
#asset_id ⇒ Symbol
Returns the Asset ID of the Transfer.
59 60 61 |
# File 'lib/coinbase/transfer.rb', line 59 def asset_id @model.asset_id.to_sym end |
#destination_address_id ⇒ String
Returns the Destination Address ID of the Transfer.
49 50 51 |
# File 'lib/coinbase/transfer.rb', line 49 def destination_address_id @model.destination end |
#from_address_id ⇒ String
Returns the From Address ID of the Transfer.
43 44 45 |
# File 'lib/coinbase/transfer.rb', line 43 def from_address_id @model.address_id end |
#id ⇒ String
Returns the Transfer ID.
25 26 27 |
# File 'lib/coinbase/transfer.rb', line 25 def id @model.transfer_id end |
#inspect ⇒ String
Same as to_s.
151 152 153 |
# File 'lib/coinbase/transfer.rb', line 151 def inspect to_s end |
#network_id ⇒ Symbol
Returns the Network ID of the Transfer.
31 32 33 |
# File 'lib/coinbase/transfer.rb', line 31 def network_id Coinbase.to_sym(@model.network_id) end |
#reload ⇒ Transfer
Reload reloads the Transfer model with the latest version from the server side.
108 109 110 111 112 113 114 115 116 117 |
# File 'lib/coinbase/transfer.rb', line 108 def reload @model = Coinbase.call_api do transfers_api.get_transfer(wallet_id, from_address_id, id) end # Update memoized transaction. @transaction = Coinbase::Transaction.new(@model.transaction) self end |
#signed_payload ⇒ String
Returns the Signed Payload of the Transfer.
84 85 86 |
# File 'lib/coinbase/transfer.rb', line 84 def signed_payload @model.signed_payload end |
#status ⇒ Symbol
Returns the status of the Transfer.
102 103 104 |
# File 'lib/coinbase/transfer.rb', line 102 def status transaction.status end |
#to_s ⇒ String
Returns a String representation of the Transfer.
142 143 144 145 146 147 |
# File 'lib/coinbase/transfer.rb', line 142 def to_s "Coinbase::Transfer{transfer_id: '#{id}', network_id: '#{network_id}', " \ "from_address_id: '#{from_address_id}', destination_address_id: '#{destination_address_id}', " \ "asset_id: '#{asset_id}', amount: '#{amount}', transaction_link: '#{transaction_link}', " \ "status: '#{status}'}" end |
#transaction ⇒ Coinbase::Transaction
Returns the Transfer transaction.
90 91 92 |
# File 'lib/coinbase/transfer.rb', line 90 def transaction @transaction ||= Coinbase::Transaction.new(@model.transaction) end |
#transaction_hash ⇒ String
Returns the Transaction Hash of the Transfer.
96 97 98 |
# File 'lib/coinbase/transfer.rb', line 96 def transaction_hash @model.transaction_hash end |
#transaction_link ⇒ String
Returns the link to the transaction on the blockchain explorer.
71 72 73 74 |
# File 'lib/coinbase/transfer.rb', line 71 def transaction_link # TODO: Parameterize this by Network. "https://sepolia.basescan.org/tx/#{transaction_hash}" end |
#unsigned_payload ⇒ String
Returns the Unsigned Payload of the Transfer.
78 79 80 |
# File 'lib/coinbase/transfer.rb', line 78 def unsigned_payload @model.unsigned_payload end |
#wait!(interval_seconds = 0.2, timeout_seconds = 20) ⇒ Transfer
Waits until the Transfer is completed or failed by polling the Network at the given interval. Raises a Timeout::Error if the Transfer takes longer than the given timeout.
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/coinbase/transfer.rb', line 124 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, 'Transfer timed out' if Time.now - start_time > timeout_seconds self.sleep interval_seconds end self end |
#wallet_id ⇒ String
Returns the Wallet ID of the Transfer.
37 38 39 |
# File 'lib/coinbase/transfer.rb', line 37 def wallet_id @model.wallet_id end |