Class: Stellar::Operation

Inherits:
XDR::Struct
  • Object
show all
Includes:
XDR::Namespace
Defined in:
lib/stellar/operation.rb,
generated/stellar/operation.rb,
generated/stellar/operation/body.rb

Defined Under Namespace

Classes: Body

Constant Summary collapse

MAX_INT64 =
2**63 - 1

Class Method Summary collapse

Class Method Details

.account_merge(attributes = {}) ⇒ Stellar::Operation

Helper method to create an account merge operation

Options Hash (attributes):

Raises:

  • (ArgumentError)


281
282
283
284
285
286
287
288
289
290
# File 'lib/stellar/operation.rb', line 281

def self.(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.]
  }))
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.

Options Hash (attributes):

Raises:

  • (ArgumentError)


252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
# File 'lib/stellar/operation.rb', line 252

def self.allow_trust(attributes={})
  op = AllowTrustOp.new()

  trustor   = attributes[:trustor]
  authorize = attributes[:authorize]
  asset     = Asset.send(*attributes[:asset])

  raise ArgumentError, "Bad :trustor" unless trustor.is_a?(Stellar::KeyPair)
  raise ArgumentError, "Bad :authorize" unless authorize == !!authorize # check boolean
  raise ArgumentError, "Bad :asset" unless asset.type == Stellar::AssetType.asset_type_credit_alphanum4

  atc = AllowTrustOp::Asset.new(:asset_type_credit_alphanum4, asset.code)

  op.trustor   = trustor.
  op.authorize = authorize
  op.asset     = atc

  return make(attributes.merge({
    body:[:allow_trust, op]
  }))
end

.bump_sequence(attributes = {}) ⇒ Object

Raises:

  • (ArgumentError)


338
339
340
341
342
343
344
345
346
347
348
349
350
# File 'lib/stellar/operation.rb', line 338

def self.bump_sequence(attributes={})
  op = BumpSequenceOp.new()

  bump_to = attributes[:bump_to]

  raise ArgumentError, ":bump_to too big" unless bump_to <= MAX_INT64

  op.bump_to  = bump_to

  return make(attributes.merge({
    body:[:bump_sequence, 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.

Options Hash (attributes):

  • :line (Stellar::Asset)

    the asset to trust

  • :limit (Fixnum)

    the maximum amount to trust, defaults to max int64, if the limit is set to 0 it deletes the trustline.

Raises:

  • (ArgumentError)


124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/stellar/operation.rb', line 124

def self.change_trust(attributes={})
  line = attributes[:line]
  if !line.is_a?(Asset)
    if !Asset::TYPES.include?(line[0])
      fail ArgumentError, "must be one of #{Asset::TYPES}"
    end
    line = Asset.send(*line)
  end

  limit = attributes.key?(:limit) ? interpret_amount(attributes[:limit]) : MAX_INT64

  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_account(attributes = {}) ⇒ Object

Raises:

  • (ArgumentError)


97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/stellar/operation.rb', line 97

def self.(attributes={})
  destination      = attributes[:destination]
  starting_balance = interpret_amount(attributes[:starting_balance])

  raise ArgumentError unless destination.is_a?(KeyPair)

  op = CreateAccountOp.new()
  op.destination = destination.
  op.starting_balance = starting_balance

  return make(attributes.merge({
    body:[:create_account, op]
  }))
end

.create_passive_sell_offer(attributes = {}) ⇒ Object Also known as: create_passive_offer



184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
# File 'lib/stellar/operation.rb', line 184

def self.create_passive_sell_offer(attributes={})
  buying     = Asset.send(*attributes[:buying])
  selling    = Asset.send(*attributes[:selling])
  amount     = interpret_amount(attributes[:amount])
  price      = interpret_price(attributes[:price])

  op = CreatePassiveSellOfferOp.new({
    buying:     buying,
    selling:    selling,
    amount:     amount,
    price:      price,
  })

  return make(attributes.merge({
    body:[:create_passive_sell_offer, op]
  }))
end

.inflation(attributes = {}) ⇒ Stellar::Operation

Helper method to create an inflation operation

Options Hash (attributes):

  • :sequence (Integer)

Raises:

  • (ArgumentError)


299
300
301
302
303
304
305
306
307
308
# File 'lib/stellar/operation.rb', line 299

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]
  }))
end

.make(attributes = {}) ⇒ Stellar::Operation

Construct a new Stellar::Operation from the provided source account and body

Options Hash (attributes):



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/stellar/operation.rb', line 17

def self.make(attributes={})
   = attributes[:source_account]
  body           = Stellar::Operation::Body.new(*attributes[:body])

  op = Stellar::Operation.new(body:body)

  if 
    raise ArgumentError, "Bad :source_account" unless .is_a?(Stellar::KeyPair)
    op. = .
  end

  return op
end

.manage_buy_offer(attributes = {}) ⇒ Object



164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# File 'lib/stellar/operation.rb', line 164

def self.manage_buy_offer(attributes={})
  buying     = Asset.send(*attributes[:buying])
  selling    = Asset.send(*attributes[:selling])
  amount     = interpret_amount(attributes[:amount])
  offer_id   = attributes[:offer_id] || 0
  price      = interpret_price(attributes[:price])

  op = ManageBuyOfferOp.new({
    buying:     buying,
    selling:    selling,
    amount:     amount,
    price:      price,
    offer_id:   offer_id
  })

  return make(attributes.merge({
    body:[:manage_buy_offer, op]
  }))
end

.manage_data(attributes = {}) ⇒ Stellar::Operation

Helper method to create an manage data operation

Options Hash (attributes):

  • :sequence (Integer)

Raises:

  • (ArgumentError)


317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
# File 'lib/stellar/operation.rb', line 317

def self.manage_data(attributes={})
  op = ManageDataOp.new()

  name  = attributes[:name]
  value = attributes[:value]

  raise ArgumentError, "Invalid :name" unless name.is_a?(String)
  raise ArgumentError, ":name too long" unless name.bytesize <= 64

  if value.present?
    raise ArgumentError, ":value too long" unless value.bytesize <= 64
  end

  op.data_name  = name
  op.data_value = value

  return make(attributes.merge({
    body:[:manage_data, op]
  }))
end

.manage_sell_offer(attributes = {}) ⇒ Object Also known as: manage_offer



144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# File 'lib/stellar/operation.rb', line 144

def self.manage_sell_offer(attributes={})
  buying     = Asset.send(*attributes[:buying])
  selling    = Asset.send(*attributes[:selling])
  amount     = interpret_amount(attributes[:amount])
  offer_id   = attributes[:offer_id] || 0
  price      = interpret_price(attributes[:price])

  op = ManageSellOfferOp.new({
    buying:     buying,
    selling:    selling,
    amount:     amount,
    price:      price,
    offer_id:   offer_id
  })

  return make(attributes.merge({
    body:[:manage_sell_offer, op]
  }))
end

.path_payment(attributes = {}) ⇒ Stellar::Operation

Helper method to create a valid PathPaymentOp, wrapped in the necessary XDR structs to be included within a transactions ‘operations` array.

Options Hash (attributes):

  • :destination (Stellar::KeyPair)

    the receiver of the payment

  • :amount (Array)

    the amount to pay

  • :with (Array)

    the source asset and maximum allowed source amount to pay with

  • :path (Array<Stellar::Asset>)

    the payment path to use

Raises:

  • (ArgumentError)

See Also:



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/stellar/operation.rb', line 76

def self.path_payment(attributes={})
  destination             = attributes[:destination]
  asset, amount           = extract_amount(attributes[:amount])
  send_asset, send_max    = extract_amount(attributes[:with])
  path                    = (attributes[:path] || []).map{|p| Stellar::Asset.send(*p)}

  raise ArgumentError unless destination.is_a?(KeyPair)

  op               = PathPaymentOp.new
  op.send_asset    = send_asset
  op.send_max      = send_max
  op.destination   = destination.
  op.dest_asset    = asset
  op.dest_amount   = amount
  op.path          = path

  return make(attributes.merge({
    body:[:path_payment, 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.

Options Hash (attributes):

  • :destination (Stellar::KeyPair)

    the receiver of the payment

  • :amount (Array)

    the amount to pay

Raises:

  • (ArgumentError)

See Also:



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/stellar/operation.rb', line 44

def self.payment(attributes={})
  destination = attributes[:destination]
  asset, amount = extract_amount(attributes[:amount])

  raise ArgumentError unless destination.is_a?(KeyPair)


  op             = PaymentOp.new
  op.asset       = asset
  op.amount      = amount
  op.destination = destination.

  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.

Options Hash (attributes):



216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
# File 'lib/stellar/operation.rb', line 216

def self.set_options(attributes={})
  op                = SetOptionsOp.new()
  op.set_flags      = Stellar::AccountFlags.make_mask attributes[:set]
  op.clear_flags    = Stellar::AccountFlags.make_mask attributes[:clear]
  op.master_weight  = attributes[:master_weight]
  op.low_threshold  = attributes[:low_threshold]
  op.med_threshold  = attributes[:med_threshold]
  op.high_threshold = attributes[:high_threshold]

  op.signer      = attributes[:signer]
  op.home_domain = attributes[:home_domain]


  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.
  end


  return make(attributes.merge({
    body:[:set_options, op]
  }))
end