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 ⇒ Object
readonly
Returns the value of attribute network.
Instance Method Summary collapse
-
#initialize(model, network:) ⇒ Destination
constructor
Returns a new Destination object.
Constructor Details
#initialize(model, network:) ⇒ 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 48 49 |
# File 'lib/coinbase/destination.rb', line 23 def initialize(model, network:) network = Coinbase::Network.from_id(network) case model when Coinbase::Destination raise ArgumentError, 'destination network must match destination' unless model.network == network @address_id = model.address_id @network = model.network when Coinbase::Wallet raise ArgumentError, 'destination network must match wallet' unless model.network == network raise ArgumentError, 'destination wallet must have default address' if model.default_address.nil? @address_id = model.default_address.id @network = model.network when Coinbase::Address raise ArgumentError, 'destination network must match address' unless model.network == network @address_id = model.id @network = model.network when String @address_id = model @network = network else raise ArgumentError, "unsupported destination type: #{model.class}" end end |
Instance Attribute Details
#address_id ⇒ Object (readonly)
Returns the value of attribute address_id.
51 52 53 |
# File 'lib/coinbase/destination.rb', line 51 def address_id @address_id end |
#network ⇒ Object (readonly)
Returns the value of attribute network.
51 52 53 |
# File 'lib/coinbase/destination.rb', line 51 def network @network end |