@@ -43,7 +43,7 @@ def self.make(attributes={})
4343 # Stellar::PaymentOp body
4444 def self . payment ( attributes = { } )
4545 destination = attributes [ :destination ]
46- asset , amount = extract_amount ( attributes [ :amount ] )
46+ asset , amount = get_asset_amount ( attributes [ :amount ] )
4747
4848 raise ArgumentError unless destination . is_a? ( KeyPair )
4949
@@ -96,9 +96,11 @@ def self.path_payment(attributes={})
9696 #
9797 def self . path_payment_strict_receive ( attributes = { } )
9898 destination = attributes [ :destination ]
99- asset , amount = extract_amount ( attributes [ :amount ] )
100- send_asset , send_max = extract_amount ( attributes [ :with ] )
101- path = ( attributes [ :path ] || [ ] ) . map { |p | Stellar ::Asset . send ( *p ) }
99+ asset , amount = get_asset_amount ( attributes [ :amount ] )
100+ send_asset , send_max = get_asset_amount ( attributes [ :with ] )
101+ path = ( attributes [ :path ] || [ ] ) . map {
102+ |p | p . is_a? ( Array ) ? Stellar ::Asset . send ( *p ) : p
103+ }
102104
103105 raise ArgumentError unless destination . is_a? ( KeyPair )
104106
@@ -132,9 +134,11 @@ def self.path_payment_strict_receive(attributes={})
132134 #
133135 def self . path_payment_strict_send ( attributes = { } )
134136 destination = attributes [ :destination ]
135- asset , dest_min = extract_amount ( attributes [ :amount ] )
136- send_asset , send_amount = extract_amount ( attributes [ :with ] )
137- path = ( attributes [ :path ] || [ ] ) . map { |p | Stellar ::Asset . send ( *p ) }
137+ asset , dest_min = get_asset_amount ( attributes [ :amount ] )
138+ send_asset , send_amount = get_asset_amount ( attributes [ :with ] )
139+ path = ( attributes [ :path ] || [ ] ) . map {
140+ |p | p . is_a? ( Array ) ? Stellar ::Asset . send ( *p ) : p
141+ }
138142
139143 raise ArgumentError unless destination . is_a? ( KeyPair )
140144
@@ -199,11 +203,17 @@ def self.change_trust(attributes={})
199203 end
200204
201205 def self . manage_sell_offer ( attributes = { } )
202- buying = Asset . send ( *attributes [ :buying ] )
203- selling = Asset . send ( *attributes [ :selling ] )
204- amount = interpret_amount ( attributes [ :amount ] )
205- offer_id = attributes [ :offer_id ] || 0
206- price = interpret_price ( attributes [ :price ] )
206+ buying = attributes [ :buying ]
207+ if buying . is_a? ( Array )
208+ buying = Asset . send ( *buying )
209+ end
210+ selling = attributes [ :selling ]
211+ if selling . is_a? ( Array )
212+ selling = Asset . send ( *selling )
213+ end
214+ amount = interpret_amount ( attributes [ :amount ] )
215+ offer_id = attributes [ :offer_id ] || 0
216+ price = interpret_price ( attributes [ :price ] )
207217
208218 op = ManageSellOfferOp . new ( {
209219 buying : buying ,
@@ -219,11 +229,17 @@ def self.manage_sell_offer(attributes={})
219229 end
220230
221231 def self . manage_buy_offer ( attributes = { } )
222- buying = Asset . send ( *attributes [ :buying ] )
223- selling = Asset . send ( *attributes [ :selling ] )
224- amount = interpret_amount ( attributes [ :amount ] )
225- offer_id = attributes [ :offer_id ] || 0
226- price = interpret_price ( attributes [ :price ] )
232+ buying = attributes [ :buying ]
233+ if buying . is_a? ( Array )
234+ buying = Asset . send ( *buying )
235+ end
236+ selling = attributes [ :selling ]
237+ if selling . is_a? ( Array )
238+ selling = Asset . send ( *selling )
239+ end
240+ amount = interpret_amount ( attributes [ :amount ] )
241+ offer_id = attributes [ :offer_id ] || 0
242+ price = interpret_price ( attributes [ :price ] )
227243
228244 op = ManageBuyOfferOp . new ( {
229245 buying : buying ,
@@ -239,10 +255,16 @@ def self.manage_buy_offer(attributes={})
239255 end
240256
241257 def self . create_passive_sell_offer ( attributes = { } )
242- buying = Asset . send ( *attributes [ :buying ] )
243- selling = Asset . send ( *attributes [ :selling ] )
244- amount = interpret_amount ( attributes [ :amount ] )
245- price = interpret_price ( attributes [ :price ] )
258+ buying = attributes [ :buying ]
259+ if buying . is_a? ( Array )
260+ buying = Asset . send ( *buying )
261+ end
262+ selling = attributes [ :selling ]
263+ if selling . is_a? ( Array )
264+ selling = Asset . send ( *selling )
265+ end
266+ amount = interpret_amount ( attributes [ :amount ] )
267+ price = interpret_price ( attributes [ :price ] )
246268
247269 op = CreatePassiveSellOfferOp . new ( {
248270 buying : buying ,
@@ -309,9 +331,12 @@ def self.set_options(attributes={})
309331 def self . allow_trust ( attributes = { } )
310332 op = AllowTrustOp . new ( )
311333
312- trustor = attributes [ :trustor ]
334+ trustor = attributes [ :trustor ]
313335 authorize = attributes [ :authorize ]
314- asset = Asset . send ( *attributes [ :asset ] )
336+ asset = attributes [ :asset ]
337+ if asset . is_a? ( Array )
338+ asset = Asset . send ( *asset )
339+ end
315340
316341 raise ArgumentError , "Bad :trustor" unless trustor . is_a? ( Stellar ::KeyPair )
317342 raise ArgumentError , "Bad :authorize" unless authorize == !!authorize # check boolean
@@ -407,9 +432,13 @@ def self.bump_sequence(attributes={})
407432 end
408433
409434 private
410- def self . extract_amount ( a )
411- amount = interpret_amount ( a . last )
412- asset = Stellar ::Asset . send ( *a [ 0 ...-1 ] )
435+ def self . get_asset_amount ( values )
436+ amount = interpret_amount ( values . last )
437+ if values [ 0 ] . is_a? ( Stellar ::Asset )
438+ asset = values . first
439+ else
440+ asset = Stellar ::Asset . send ( *values [ 0 ...-1 ] )
441+ end
413442
414443 return asset , amount
415444 end
0 commit comments