lib/stellar/transaction.rb in stellar-base-0.0.1 vs lib/stellar/transaction.rb in stellar-base-0.0.2

- old
+ new

@@ -2,16 +2,19 @@ Transaction.class_eval do def self.payment(attributes={}) destination = attributes[:destination] amount = attributes[:amount] + path = attributes[:path] || [] + path = path.map{|p| Stellar::Currency.send(*p)} raise ArgumentError unless destination.is_a?(KeyPair) for_account(attributes).tap do |result| payment = PaymentOp.send(*amount) payment.destination = destination.public_key + payment.path = path payment.apply_defaults result.operations = [payment.to_operation] end end @@ -22,9 +25,28 @@ raise ArgumentError, "Bad :limit #{limit}" unless limit.is_a?(Integer) for_account(attributes).tap do |result| details = ChangeTrustOp.new(line: line, limit: limit) + result.operations = [details.to_operation] + end + end + + def self.create_offer(attributes={}) + taker_pays = Currency.send(*attributes[:taker_pays]) + taker_gets = Currency.send(*attributes[:taker_gets]) + amount = attributes[:amount] + offer_id = attributes[:offer_id] || 0 + price = Price.from_f(attributes[:price]) + + for_account(attributes).tap do |result| + details = CreateOfferOp.new({ + taker_pays: taker_pays, + taker_gets: taker_gets, + amount: amount, + price: price, + offer_id: offer_id + }) result.operations = [details.to_operation] end end def self.for_account(attributes={}) \ No newline at end of file