Class: Stellar::Operation
- Inherits:
-
XDR::Struct
- Object
- XDR::Struct
- Stellar::Operation
- Includes:
- XDR::Namespace
- Defined in:
- lib/stellar/operation.rb,
generated/stellar/operation.rb,
generated/stellar/operation/body.rb
Defined Under Namespace
Classes: Body
Class Method Summary collapse
-
.account_merge(attributes = {}) ⇒ Stellar::Operation
Helper method to create an account merge operation.
-
.allow_trust(attributes = {}) ⇒ Stellar::Operation
Helper method to create a valid AllowTrustOp, wrapped in the necessary XDR structs to be included within a transactions ‘operations` array.
-
.change_trust(attributes = {}) ⇒ Stellar::Operation
Helper method to create a valid ChangeTrustOp, wrapped in the necessary XDR structs to be included within a transactions ‘operations` array.
- .create_offer(attributes = {}) ⇒ Object
-
.inflation(attributes = {}) ⇒ Stellar::Operation
Helper method to create an inflation operation.
-
.make(attributes = {}) ⇒ Stellar::Operation
Construct a new Stellar::Operation from the provided source account and body.
-
.payment(attributes = {}) ⇒ Stellar::Operation
Helper method to create a valid PaymentOp, wrapped in the necessary XDR structs to be included within a transactions ‘operations` array.
-
.set_options(attributes = {}) ⇒ Stellar::Operation
Helper method to create a valid SetOptionsOp, wrapped in the necessary XDR structs to be included within a transactions ‘operations` array.
Class Method Details
.account_merge(attributes = {}) ⇒ Stellar::Operation
Helper method to create an account merge operation
179 180 181 182 183 184 185 186 187 188 |
# File 'lib/stellar/operation.rb', line 179 def self.account_merge(attributes={}) destination = attributes[:destination] raise ArgumentError, "Bad :destination" unless destination.is_a?(KeyPair) # TODO: add source_account support return make(attributes.merge({ body:[:account_merge, destination.public_key] })) end |
.allow_trust(attributes = {}) ⇒ Stellar::Operation
Helper method to create a valid AllowTrustOp, wrapped in the necessary XDR structs to be included within a transactions ‘operations` array.
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/stellar/operation.rb', line 150 def self.allow_trust(attributes={}) op = AllowTrustOp.new() trustor = attributes[:trustor] = attributes[:authorize] currency = Currency.send(*attributes[:currency]) raise ArgumentError, "Bad :trustor" unless trustor.is_a?(Stellar::KeyPair) raise ArgumentError, "Bad :authorize" unless == !! # check boolean raise ArgumentError, "Bad :currency" unless currency.type == Stellar::CurrencyType.iso4217 atc = AllowTrustOp::Currency.new(:iso4217, currency.code) op.trustor = trustor.public_key op. = op.currency = atc return make(attributes.merge({ body:[:allow_trust, op] })) end |
.change_trust(attributes = {}) ⇒ Stellar::Operation
Helper method to create a valid ChangeTrustOp, wrapped in the necessary XDR structs to be included within a transactions ‘operations` array.
72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/stellar/operation.rb', line 72 def self.change_trust(attributes={}) line = Currency.send(*attributes[:line]) limit = attributes[:limit] raise ArgumentError, "Bad :limit #{limit}" unless limit.is_a?(Integer) op = ChangeTrustOp.new(line: line, limit: limit) return make(attributes.merge({ body:[:change_trust, op] })) end |
.create_offer(attributes = {}) ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/stellar/operation.rb', line 85 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]) op = CreateOfferOp.new({ taker_pays: taker_pays, taker_gets: taker_gets, amount: amount, price: price, offer_id: offer_id }) return make(attributes.merge({ body:[:create_offer, op] })) end |
.inflation(attributes = {}) ⇒ Stellar::Operation
Helper method to create an inflation operation
197 198 199 200 201 202 203 204 205 206 |
# File 'lib/stellar/operation.rb', line 197 def self.inflation(attributes={}) sequence = attributes[:sequence] raise ArgumentError, "Bad :sequence #{sequence}" unless sequence.is_a?(Integer) # TODO: add source_account support return make(attributes.merge({ body:[:inflation, sequence] })) end |
.make(attributes = {}) ⇒ Stellar::Operation
Construct a new Stellar::Operation from the provided source account and body
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/stellar/operation.rb', line 14 def self.make(attributes={}) source_account = attributes[:source_account] body = Stellar::Operation::Body.new(*attributes[:body]) op = Stellar::Operation.new(body:body) if source_account raise ArgumentError, "Bad :source_account" unless source_account.is_a?(Stellar::KeyPair) op.source_account = source_account.public_key end return op end |
.payment(attributes = {}) ⇒ Stellar::Operation
Helper method to create a valid PaymentOp, wrapped in the necessary XDR structs to be included within a transactions ‘operations` array.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/stellar/operation.rb', line 43 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) op = PaymentOp.send(*amount) op.destination = destination.public_key op.path = path op.apply_defaults return make(attributes.merge({ body:[:payment, op] })) end |
.set_options(attributes = {}) ⇒ Stellar::Operation
Helper method to create a valid SetOptionsOp, wrapped in the necessary XDR structs to be included within a transactions ‘operations` array.
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/stellar/operation.rb', line 119 def self.(attributes={}) op = SetOptionsOp.new() op.set_flags = Stellar::AccountFlags.make_mask attributes[:set] op.clear_flags = Stellar::AccountFlags.make_mask attributes[:clear] op.thresholds = attributes[:thresholds] op.signer = attributes[:signer] inflation_dest = attributes[:inflation_dest] if inflation_dest raise ArgumentError, "Bad :inflation_dest" unless inflation_dest.is_a?(Stellar::KeyPair) op.inflation_dest = inflation_dest.public_key end return make(attributes.merge({ body:[:set_options, op] })) end |