diff --git a/lib/coinbase/fund_operation.rb b/lib/coinbase/fund_operation.rb index 166f21b9..1581d373 100644 --- a/lib/coinbase/fund_operation.rb +++ b/lib/coinbase/fund_operation.rb @@ -32,7 +32,7 @@ class << self # @param asset_id [Symbol] The Asset ID of the Asset to send # @return [FundOperation] The new pending FundOperation object # @raise [Coinbase::ApiError] If the FundOperation fails - def create(wallet_id:, address_id:, amount:, asset_id:, network:) + def create(wallet_id:, address_id:, amount:, asset_id:, network:, quote: nil) network = Coinbase::Network.from_id(network) asset = network.get_asset(asset_id) @@ -43,7 +43,8 @@ def create(wallet_id:, address_id:, amount:, asset_id:, network:) { amount: asset.to_atomic_amount(amount).to_i.to_s, asset_id: asset.primary_denomination.to_s, - } + fund_quote_id: quote&.id + }.compact ) end diff --git a/lib/coinbase/fund_quote.rb b/lib/coinbase/fund_quote.rb index 3e2bb62a..1352db06 100644 --- a/lib/coinbase/fund_quote.rb +++ b/lib/coinbase/fund_quote.rb @@ -57,6 +57,20 @@ def id @model.fund_quote_id end + # Creates a fund operation using the quote. + # @return [Coinbase::FundOperation] The FundOperation object + # @raise [Coinbase::ApiError] If the FundOperation fails + def execute! + FundOperation.create( + wallet_id: wallet_id, + address_id: address_id, + amount: amount.amount, + asset_id: asset.asset_id, + network: network.id, + quote: self + ) + end + # Returns the Network of the FundOperatoin. # @return [Coinbase::Network] The Network def network @@ -131,5 +145,11 @@ def to_s def inspect to_s end + + private + + def fund_api + @fund_api ||= Coinbase::Client::FundApi.new(Coinbase.configuration.api_client) + end end end