Class: Stellar::Operation
- Inherits:
-
Object
- Object
- Stellar::Operation
- Extended by:
- DSL
- Defined in:
- lib/stellar/compat.rb,
lib/stellar/operation.rb
Constant Summary collapse
- MAX_INT64 =
2**63 - 1
- TRUST_LINE_FLAGS_MAPPING =
{ full: Stellar::TrustLineFlags., maintain_liabilities: Stellar::TrustLineFlags., clawback_enabled: Stellar::TrustLineFlags.trustline_clawback_enabled_flag }.freeze
Class Method Summary collapse
-
.account_merge(destination:, source_account: nil) ⇒ Stellar::Operation
Account Merge operation builder.
-
.begin_sponsoring_future_reserves(sponsored:, source_account: nil) ⇒ Operation
Begin Sponsoring Future Reserves operation builder.
-
.bump_sequence(bump_to:, source_account: nil) ⇒ Stellar::Operation
Bump Sequence operation builder.
-
.change_trust(asset: nil, limit: nil, source_account: nil, **attrs) ⇒ Stellar::Operation
Change Trust operation builder.
-
.claim_claimable_balance(balance_id:, source_account: nil) ⇒ Operation
Helper method to create a valid CreateClaimableBalanceOp, ready to be used within a transactions ‘operations` array.
-
.clawback(from:, amount:, source_account: nil) ⇒ Stellar::Operation
Clawback operation builder.
-
.clawback_claimable_balance(balance_id:, source_account: nil) ⇒ Stellar::Operation
Clawback Claimable Balance operation builder.
-
.create_account(destination:, starting_balance:, source_account: nil) ⇒ Stellar::Operation
Create Account operation builder.
-
.create_claimable_balance(asset:, amount:, claimants:, source_account: nil) ⇒ Operation
Create Claimable Balance operation builder.
- .create_passive_offer ⇒ Object
-
.create_passive_sell_offer(selling:, buying:, amount:, price:, source_account: nil) ⇒ Operation
Create Passive Sell Offer operation builder.
-
.end_sponsoring_future_reserves(source_account: nil) ⇒ Operation
End Sponsoring Future Reserves operation builder.
-
.inflation(source_account: nil) ⇒ Stellar::Operation
Inflation operation builder.
-
.liquidity_pool_deposit(liquidity_pool_id:, max_amount_a:, max_amount_b:, min_price:, max_price:, source_account: nil) ⇒ Stellar::Operation
Liquidity Pool Deposit operation builder.
-
.liquidity_pool_withdraw(liquidity_pool_id:, amount:, min_amount_a:, min_amount_b:, source_account: nil) ⇒ Stellar::Operation
Liquidity Pool Withdraw operation builder.
-
.make(body:, source_account: nil) ⇒ Stellar::Operation
Construct a new Stellar::Operation from the provided source account and body.
-
.manage_buy_offer(buying:, selling:, amount:, price:, offer_id: 0, source_account: nil) ⇒ Operation
Manage Buy Offer operation builder.
-
.manage_data(name:, value: nil, source_account: nil) ⇒ Stellar::Operation
Manage Data operation builder.
- .manage_offer ⇒ Object
-
.manage_sell_offer(selling:, buying:, amount:, price:, offer_id: 0, source_account: nil) ⇒ Operation
Manage Sell Offer operation builder.
-
.path_payment_strict_receive(destination:, amount:, with:, path: [], source_account: nil) ⇒ Stellar::Operation
(also: path_payment)
Path Payment Strict Receive operation builder.
-
.path_payment_strict_send(destination:, amount:, with:, path: [], source_account: nil) ⇒ Stellar::Operation
Path Payment Strict Receive operation builder.
-
.payment(destination:, amount:, source_account: nil) ⇒ Stellar::Operation
Payment Operation builder.
-
.revoke_sponsorship(sponsored:, source_account: nil, **attributes) ⇒ Operation
Revoke Sponsorship operation builder.
-
.set_options(set: [], clear: [], home_domain: nil, signer: nil, inflation_dest: nil, source_account: nil, **attributes) ⇒ Stellar::Operation
Set Options operation builder.
-
.set_trust_line_flags(asset:, trustor:, flags: {}, source_account: nil) ⇒ Stellar::Operation
Set Trustline Flags operation builder.
Methods included from DSL
Account, Asset, ClaimPredicate, Claimant, KeyPair, SignerKey
Class Method Details
.account_merge(destination:, source_account: nil) ⇒ Stellar::Operation
Account Merge operation builder
55 56 57 58 59 |
# File 'lib/stellar/operation.rb', line 55 def account_merge(destination:, source_account: nil) raise ArgumentError, "Bad destination" unless destination.is_a?(KeyPair) make(source_account: source_account, body: [:account_merge, destination.muxed_account]) end |
.begin_sponsoring_future_reserves(sponsored:, source_account: nil) ⇒ Operation
Begin Sponsoring Future Reserves operation builder
441 442 443 444 445 446 447 |
# File 'lib/stellar/operation.rb', line 441 def begin_sponsoring_future_reserves(sponsored:, source_account: nil) op = BeginSponsoringFutureReservesOp.new( sponsored_id: KeyPair(sponsored).account_id ) make(source_account: source_account, body: [:begin_sponsoring_future_reserves, op]) end |
.bump_sequence(bump_to:, source_account: nil) ⇒ Stellar::Operation
Bump Sequence operation builder
95 96 97 98 99 100 101 102 103 |
# File 'lib/stellar/operation.rb', line 95 def bump_sequence(bump_to:, source_account: nil) raise ArgumentError, ":bump_to too big" unless bump_to <= MAX_INT64 op = BumpSequenceOp.new( bump_to: bump_to ) make(source_account: source_account, body: [:bump_sequence, op]) end |
.change_trust(asset: nil, limit: nil, source_account: nil, **attrs) ⇒ Stellar::Operation
Change Trust operation builder
132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/stellar/operation.rb', line 132 def change_trust(asset: nil, limit: nil, source_account: nil, **attrs) if attrs.key?(:line) && !asset Stellar::Deprecation.warn("`line` parameter is deprecated, use `asset` instead") asset = attrs[:line] end op = ChangeTrustOp.new( line: Asset(asset).to_change_trust_asset, limit: limit ? interpret_amount(limit) : MAX_INT64 ) make(source_account: source_account, body: [:change_trust, op]) end |
.claim_claimable_balance(balance_id:, source_account: nil) ⇒ Operation
Helper method to create a valid CreateClaimableBalanceOp, ready to be used within a transactions ‘operations` array.
218 219 220 221 222 |
# File 'lib/stellar/operation.rb', line 218 def claim_claimable_balance(balance_id:, source_account: nil) op = ClaimClaimableBalanceOp.new(balance_id: balance_id) make(source_account: source_account, body: [:claim_claimable_balance, op]) end |
.clawback(from:, amount:, source_account: nil) ⇒ Stellar::Operation
Clawback operation builder
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
# File 'lib/stellar/operation.rb', line 171 def clawback(from:, amount:, source_account: nil) asset, amount = get_asset_amount(amount) if amount == 0 raise ArgumentError, "Amount can not be zero" end if amount < 0 raise ArgumentError, "Negative amount is not allowed" end op = ClawbackOp.new( amount: amount, from: KeyPair(from).muxed_account, asset: asset ) make(source_account: source_account, body: [:clawback, op]) end |
.clawback_claimable_balance(balance_id:, source_account: nil) ⇒ Stellar::Operation
Clawback Claimable Balance operation builder
230 231 232 233 234 235 236 237 |
# File 'lib/stellar/operation.rb', line 230 def clawback_claimable_balance(balance_id:, source_account: nil) balance_id = Stellar::ClaimableBalanceID.from_xdr(balance_id, :hex) op = ClawbackClaimableBalanceOp.new(balance_id: balance_id) make(source_account: source_account, body: [:clawback_claimable_balance, op]) rescue XDR::ReadError raise ArgumentError, "Claimable balance id '#{balance_id}' is invalid" end |
.create_account(destination:, starting_balance:, source_account: nil) ⇒ Stellar::Operation
Create Account operation builder
40 41 42 43 44 45 46 47 |
# File 'lib/stellar/operation.rb', line 40 def create_account(destination:, starting_balance:, source_account: nil) op = CreateAccountOp.new( destination: KeyPair(destination).account_id, starting_balance: interpret_amount(starting_balance) ) make(source_account: source_account, body: [:create_account, op]) end |
.create_claimable_balance(asset:, amount:, claimants:, source_account: nil) ⇒ Operation
Create Claimable Balance operation builder.
202 203 204 205 206 |
# File 'lib/stellar/operation.rb', line 202 def create_claimable_balance(asset:, amount:, claimants:, source_account: nil) op = CreateClaimableBalanceOp.new(asset: asset, amount: amount, claimants: claimants) make(source_account: source_account, body: [:create_claimable_balance, op]) end |
.create_passive_offer ⇒ Object
3 |
# File 'lib/stellar/compat.rb', line 3 alias_method :create_passive_offer, :create_passive_sell_offer |
.create_passive_sell_offer(selling:, buying:, amount:, price:, source_account: nil) ⇒ Operation
Create Passive Sell Offer operation builder
376 377 378 379 380 381 382 383 384 385 386 387 388 |
# File 'lib/stellar/operation.rb', line 376 def create_passive_sell_offer(selling:, buying:, amount:, price:, source_account: nil) selling = Asset.send(*selling) if selling.is_a?(Array) = Asset.send(*) if .is_a?(Array) op = CreatePassiveSellOfferOp.new( buying: , selling: selling, amount: interpret_amount(amount), price: Price.from(price) ) make(source_account: source_account, body: [:create_passive_sell_offer, op]) end |
.end_sponsoring_future_reserves(source_account: nil) ⇒ Operation
End Sponsoring Future Reserves operation builder
454 455 456 |
# File 'lib/stellar/operation.rb', line 454 def end_sponsoring_future_reserves(source_account: nil) make(source_account: source_account, body: [:end_sponsoring_future_reserves]) end |
.inflation(source_account: nil) ⇒ Stellar::Operation
Inflation operation builder
482 483 484 |
# File 'lib/stellar/operation.rb', line 482 def inflation(source_account: nil) make(source_account: source_account, body: [:inflation]) end |
.liquidity_pool_deposit(liquidity_pool_id:, max_amount_a:, max_amount_b:, min_price:, max_price:, source_account: nil) ⇒ Stellar::Operation
Liquidity Pool Deposit operation builder
400 401 402 403 404 405 406 407 408 409 410 411 412 |
# File 'lib/stellar/operation.rb', line 400 def liquidity_pool_deposit(liquidity_pool_id:, max_amount_a:, max_amount_b:, min_price:, max_price:, source_account: nil) op = LiquidityPoolDepositOp.new( liquidity_pool_id: PoolID.from_xdr(liquidity_pool_id, :hex), max_amount_a: interpret_amount(max_amount_a), max_amount_b: interpret_amount(max_amount_b), min_price: Price.from(min_price), max_price: Price.from(max_price) ) make(source_account: source_account, body: [:liquidity_pool_deposit, op]) rescue XDR::ReadError raise ArgumentError, "invalid liquidity pool ID '#{balance_id}'" end |
.liquidity_pool_withdraw(liquidity_pool_id:, amount:, min_amount_a:, min_amount_b:, source_account: nil) ⇒ Stellar::Operation
Liquidity Pool Withdraw operation builder
423 424 425 426 427 428 429 430 431 432 433 434 |
# File 'lib/stellar/operation.rb', line 423 def liquidity_pool_withdraw(liquidity_pool_id:, amount:, min_amount_a:, min_amount_b:, source_account: nil) op = LiquidityPoolWithdrawOp.new( liquidity_pool_id: PoolID.from_xdr(liquidity_pool_id, :hex), amount: interpret_amount(amount), min_amount_a: interpret_amount(min_amount_a), min_amount_b: interpret_amount(min_amount_b) ) make(source_account: source_account, body: [:liquidity_pool_withdraw, op]) rescue XDR::ReadError raise ArgumentError, "invalid liquidity pool ID '#{balance_id}'" end |
.make(body:, source_account: nil) ⇒ Stellar::Operation
Construct a new Stellar::Operation from the provided source account and body
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/stellar/operation.rb', line 22 def make(body:, source_account: nil) raise ArgumentError, "Bad :source_account" if source_account && !source_account.is_a?(Stellar::KeyPair) body = Stellar::Operation::Body.new(*body) Stellar::Operation.new( source_account: source_account&.muxed_account, body: body ) end |
.manage_buy_offer(buying:, selling:, amount:, price:, offer_id: 0, source_account: nil) ⇒ Operation
Manage Buy Offer operation builder
352 353 354 355 356 357 358 359 360 361 362 363 364 365 |
# File 'lib/stellar/operation.rb', line 352 def manage_buy_offer(buying:, selling:, amount:, price:, offer_id: 0, source_account: nil) = Asset.send(*) if .is_a?(Array) selling = Asset.send(*selling) if selling.is_a?(Array) op = ManageBuyOfferOp.new( buying: , selling: selling, buy_amount: interpret_amount(amount), price: Price.from(price), offer_id: offer_id ) make(source_account: source_account, body: [:manage_buy_offer, op]) end |
.manage_data(name:, value: nil, source_account: nil) ⇒ Stellar::Operation
Manage Data operation builder
112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/stellar/operation.rb', line 112 def manage_data(name:, value: nil, source_account: nil) raise ArgumentError, "Invalid :name" unless name.is_a?(String) raise ArgumentError, ":name too long" if name.bytesize > 64 raise ArgumentError, ":value too long" if value && value.bytesize > 64 op = ManageDataOp.new( data_name: name, data_value: value ) make(source_account: source_account, body: [:manage_data, op]) end |
.manage_offer ⇒ Object
2 |
# File 'lib/stellar/compat.rb', line 2 alias_method :manage_offer, :manage_sell_offer |
.manage_sell_offer(selling:, buying:, amount:, price:, offer_id: 0, source_account: nil) ⇒ Operation
Manage Sell Offer operation builder
327 328 329 330 331 332 333 334 335 336 337 338 339 340 |
# File 'lib/stellar/operation.rb', line 327 def manage_sell_offer(selling:, buying:, amount:, price:, offer_id: 0, source_account: nil) selling = Asset.send(*selling) if selling.is_a?(Array) = Asset.send(*) if .is_a?(Array) op = ManageSellOfferOp.new( buying: , selling: selling, amount: interpret_amount(amount), price: Price.from(price), offer_id: offer_id ) make(source_account: source_account, body: [:manage_sell_offer, op]) end |
.path_payment_strict_receive(destination:, amount:, with:, path: [], source_account: nil) ⇒ Stellar::Operation Also known as: path_payment
Path Payment Strict Receive operation builder.
271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 |
# File 'lib/stellar/operation.rb', line 271 def path_payment_strict_receive(destination:, amount:, with:, path: [], source_account: nil) raise ArgumentError unless destination.is_a?(KeyPair) dest_asset, dest_amount = get_asset_amount(amount) send_asset, send_max = get_asset_amount(with) op = PathPaymentStrictReceiveOp.new( destination: destination.muxed_account, dest_asset: dest_asset, dest_amount: dest_amount, send_asset: send_asset, send_max: send_max, path: path.map { |p| Asset(p) } ) make(source_account: source_account, body: [:path_payment_strict_receive, op]) end |
.path_payment_strict_send(destination:, amount:, with:, path: [], source_account: nil) ⇒ Stellar::Operation
Path Payment Strict Receive operation builder.
299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 |
# File 'lib/stellar/operation.rb', line 299 def path_payment_strict_send(destination:, amount:, with:, path: [], source_account: nil) raise ArgumentError unless destination.is_a?(KeyPair) dest_asset, dest_min = get_asset_amount(amount) send_asset, send_amount = get_asset_amount(with) op = PathPaymentStrictSendOp.new( destination: destination.muxed_account, send_asset: send_asset, send_amount: send_amount, dest_asset: dest_asset, dest_min: dest_min, path: path.map { |p| Asset(p) } ) make(source_account: source_account, body: [:path_payment_strict_send, op]) end |
.payment(destination:, amount:, source_account: nil) ⇒ Stellar::Operation
Payment Operation builder
246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 |
# File 'lib/stellar/operation.rb', line 246 def payment(destination:, amount:, source_account: nil) raise ArgumentError unless destination.is_a?(KeyPair) asset, amount = get_asset_amount(amount) op = PaymentOp.new( asset: asset, amount: amount, destination: destination.muxed_account ) make( source_account: source_account, body: [:payment, op] ) end |
.revoke_sponsorship(sponsored:, source_account: nil, **attributes) ⇒ Operation
Revoke Sponsorship operation builder
464 465 466 467 468 469 470 471 472 473 474 475 |
# File 'lib/stellar/operation.rb', line 464 def revoke_sponsorship(sponsored:, source_account: nil, **attributes) key_fields = attributes.slice(:offer_id, :data_name, :balance_id, :liquidity_pool_id, :asset, :signer) raise ArgumentError, "conflicting attributes: #{key_fields.keys.join(", ")}" if key_fields.size > 1 account_id = KeyPair(sponsored).account_id key, value = key_fields.first op = if key == :signer RevokeSponsorshipOp.signer(account_id: account_id, signer_key: SignerKey(value)) else RevokeSponsorshipOp.ledger_key(LedgerKey.from(account_id: account_id, **key_fields)) end make(source_account: source_account, body: [:revoke_sponsorship, op]) end |
.set_options(set: [], clear: [], home_domain: nil, signer: nil, inflation_dest: nil, source_account: nil, **attributes) ⇒ Stellar::Operation
Set Options operation builder.
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/stellar/operation.rb', line 71 def (set: [], clear: [], home_domain: nil, signer: nil, inflation_dest: nil, source_account: nil, **attributes) raise ArgumentError, "Bad inflation_dest" if inflation_dest && !inflation_dest.is_a?(KeyPair) op = SetOptionsOp.new( set_flags: Stellar::AccountFlags.make_mask(set), clear_flags: Stellar::AccountFlags.make_mask(clear), master_weight: attributes[:master_weight], low_threshold: attributes[:low_threshold], med_threshold: attributes[:med_threshold], high_threshold: attributes[:high_threshold], signer: signer, home_domain: home_domain, inflation_dest: inflation_dest&.account_id ) make(source_account: source_account, body: [:set_options, op]) end |
.set_trust_line_flags(asset:, trustor:, flags: {}, source_account: nil) ⇒ Stellar::Operation
Set Trustline Flags operation builder
154 155 156 157 158 159 160 161 162 |
# File 'lib/stellar/operation.rb', line 154 def set_trust_line_flags(asset:, trustor:, flags: {}, source_account: nil) op = Stellar::SetTrustLineFlagsOp.new( trustor: KeyPair(trustor).account_id, asset: Asset(asset), attributes: TrustLineFlags.set_clear_masks(flags) ) make(source_account: source_account, body: [:set_trust_line_flags, op]) end |