Class: Coinbase::Destination
- Inherits:
-
Object
- Object
- Coinbase::Destination
- Defined in:
- lib/coinbase/destination.rb
Overview
A representation of the intended recipient of an onchain interaction. For example, a simple Transfer has a single destination, which is the address that will receive the transferred funds. This class is used to handle the several different types that we can use as a destination, namely a Coinbase::Wallet, a Coinbase::Address, a String. This also ensures that the destination is valid for the network that is being interacted with. If a Coinbase::Wallet is used, the default address of the wallet is used as the destination. If a Coinbase::Address is used, the address ID is used as the destination. If a String is used, the string is used as the destination. If an existing Coinbase::Destination is used, the same address ID is used as the destination.
Instance Attribute Summary collapse
-
#address_id ⇒ Object
readonly
Returns the value of attribute address_id.
-
#network_id ⇒ Object
readonly
Returns the value of attribute network_id.
Instance Method Summary collapse
-
#initialize(model, network_id: nil) ⇒ Destination
constructor
Returns a new Destination object.
Constructor Details
#initialize(model, network_id: nil) ⇒ Destination
Returns a new Destination object.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/coinbase/destination.rb', line 23 def initialize(model, network_id: nil) case model when Coinbase::Destination raise ArgumentError, 'destination network must match destination' unless model.network_id == network_id @address_id = model.address_id @network_id = model.network_id when Coinbase::Wallet raise ArgumentError, 'destination network must match wallet' unless model.network_id == network_id raise ArgumentError, 'destination wallet must have default address' if model.default_address.nil? @address_id = model.default_address.id @network_id = model.network_id when Coinbase::Address raise ArgumentError, 'destination network must match address' unless model.network_id == network_id @address_id = model.id @network_id = model.network_id when String @address_id = model @network_id = network_id else raise ArgumentError, "unsupported destination type: #{model.class}" end end |
Instance Attribute Details
#address_id ⇒ Object (readonly)
Returns the value of attribute address_id.
49 50 51 |
# File 'lib/coinbase/destination.rb', line 49 def address_id @address_id end |
#network_id ⇒ Object (readonly)
Returns the value of attribute network_id.
49 50 51 |
# File 'lib/coinbase/destination.rb', line 49 def network_id @network_id end |