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

Class Method Summary collapse

Class Method Details

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

Helper method to create an account merge operation

Parameters:

  • attributes (Hash) (defaults to: {})

    the attributes to create the operation with

Options Hash (attributes):

Returns:

Raises:

  • (ArgumentError)


319
320
321
322
323
324
325
326
327
328
# File 'lib/stellar/operation.rb', line 319

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.

Parameters:

  • attributes (Hash) (defaults to: {})

    the attributes to create the operation with

Options Hash (attributes):

Returns:

Raises:

  • (ArgumentError)


290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
# File 'lib/stellar/operation.rb', line 290

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

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

Parameters:

  • attributes (Hash) (defaults to: {})

    the attributes to create the operation with

Options Hash (attributes):

  • :line (Stellar::Currrency)

    the asset to trust

  • :limit (Fixnum)

    the maximum amount to trust

Returns:

Raises:

  • (ArgumentError)


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

def self.change_trust(attributes={})
  line  = Asset.send(*attributes[:line])
  limit =interpret_amount(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_account(attributes = {}) ⇒ Object

Raises:

  • (ArgumentError)


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

def self.(attributes={})
  destination      = attributes[:destination]
  code_kyc         = attributes[:code_kyc]
  raise ArgumentError unless destination.is_a?(KeyPair)

  op = CreateAccountOp.new()
  op.destination = destination.
  op.code_kyc = code_kyc
  return make(attributes.merge({
    body:[:create_account, op]
  }))
end

.create_lot(attributes = {}) ⇒ Object



139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# File 'lib/stellar/operation.rb', line 139

def self.create_lot(attributes={})
  lot_name      = attributes[:lot_name]
  type = attributes[:type]
  lot_code = attributes[:lot_code]
  lot_address = attributes[:lot_address]
  lot_branch = attributes[:lot_branch]
  lot_location = attributes[:lot_location]
  start_price = attributes[:start_price]
  best_price = attributes[:best_price]
  min_step = attributes[:min_step]
  max_step = attributes[:max_step]
  published = attributes[:published]
  auc_started = attributes[:auc_started]
  duration = attributes[:duration]
  pledge = attributes[:pledge]
  publisher_id = attributes[:publisher_id]
  details = attributes[:details]
  op = CreateLotOp.new()
  op.lot_name = lot_name
  op.type = type
  op.lot_code = lot_code
  op.lot_address = lot_address
  op.lot_branch = lot_branch
  op.lot_location = lot_location
  op.start_price = start_price
  op.best_price = best_price
  op.min_step = min_step
  op.max_step = max_step
  op.published = published
  op.auc_started = auc_started
  op.duration = duration
  op.pledge = pledge
  op.details = details
  op.publisher_id = publisher_id
  return make(attributes.merge({
    body:[:create_lot, op]
  }))
end

.create_passive_offer(attributes = {}) ⇒ Object



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

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

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

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

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

Helper method to create an inflation operation

Parameters:

  • attributes (Hash) (defaults to: {})

    the attributes to create the operation with

Options Hash (attributes):

  • :sequence (Integer)

Returns:

Raises:

  • (ArgumentError)


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

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

Parameters:

  • attributes (Hash) (defaults to: {})

    the attributes to create the operation with

Options Hash (attributes):

Returns:



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

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



202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
# File 'lib/stellar/operation.rb', line 202

def self.manage_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 = ManageOfferOp.new({
    buying:     buying,
    selling:    selling,
    amount:     amount,
    price:      price,
    offer_id:   offer_id
  })

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

Parameters:

  • attributes (Hash) (defaults to: {})

    the attributes to create the operation with

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

Returns:

Raises:

  • (ArgumentError)

See Also:



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

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.

Parameters:

  • attributes (Hash) (defaults to: {})

    the attributes to create the operation with

Options Hash (attributes):

  • :destination (Stellar::KeyPair)

    the receiver of the payment

  • :amount (Array)

    the amount to pay

Returns:

Raises:

  • (ArgumentError)

See Also:



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

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

.provide_proof(attributes = {}) ⇒ Object



109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/stellar/operation.rb', line 109

def self.provide_proof(attributes={})
  lot_id      = attributes[:lot_id]
  quantity = attributes[:quantity]
  proof = attributes[:proof]
  bank_id = attributes[:bank_id]

  op = ProvideProofOp.new()
  op.lot_id = lot_id
  op.quantity = quantity
  op.proof = attributes[:proof]
  op.bank_id = attributes[:bank_id]
  return make(attributes.merge({
    body:[:provide_proof, op]
  }))
end

.register_participant(attributes = {}) ⇒ Object



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

def self.register_participant(attributes={})
  lot_id      = attributes[:lot_id]
   = attributes[:account_id]
  best_bid      = attributes[:best_bid]

  op = RegisterParticipantOp.new()
  op.lot_id = lot_id
  op. = .
  op.best_bid = best_bid
  return make(attributes.merge({
    body:[:register_participant, 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.

Parameters:

  • attributes (Hash) (defaults to: {})

    the attributes to create the operation with

Options Hash (attributes):

Returns:



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

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