Class: StellarCoreCommander::OperationBuilder

Inherits:
Object
  • Object
show all
Includes:
Contracts
Defined in:
lib/stellar_core_commander/operation_builder.rb

Constant Summary collapse

Currency =
Or[
[String, Symbol]
Amount =
OfferCurrencies =

Instance Method Summary collapse

Constructor Details

#initialize(transactor) ⇒ OperationBuilder

Returns a new instance of OperationBuilder.



21
22
23
# File 'lib/stellar_core_commander/operation_builder.rb', line 21

def initialize(transactor)
  @transactor = transactor
end

Instance Method Details

#allow_trust(account, trustor, code) ⇒ Object



79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/stellar_core_commander/operation_builder.rb', line 79

def allow_trust(, trustor, code)
  currency = make_currency([code, ])
   =  
  trustor =  trustor


  Stellar::Transaction.allow_trust({
    account:  ,
    sequence: next_sequence(),
    currency: currency,
    trustor:  trustor,
    authorize: true,
  }).to_envelope()
end

#change_trust(account, issuer, code, limit) ⇒ Object



67
68
69
70
71
72
73
74
75
76
# File 'lib/stellar_core_commander/operation_builder.rb', line 67

def change_trust(, issuer, code, limit)
   =  

  Stellar::Transaction.change_trust({
    account:  ,
    sequence: next_sequence(),
    line:     make_currency([code, issuer]),
    limit:    limit
  }).to_envelope()
end

#create_account(account, funder = :master, starting_balance = 1000_0000000) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
# File 'lib/stellar_core_commander/operation_builder.rb', line 49

def (, funder=:master, starting_balance=1000_0000000)
   =  
  funder  =  funder

  Stellar::Transaction.({
    account:          funder,
    destination:      ,
    sequence:         next_sequence(funder),
    starting_balance: starting_balance,
  }).to_envelope(funder)
end

#offer(account, currencies, amount, price) ⇒ Object



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/stellar_core_commander/operation_builder.rb', line 95

def offer(, currencies, amount, price)
   =  

  if currencies.has_key?(:sell)
    taker_pays = make_currency currencies[:for]
    taker_gets = make_currency currencies[:sell]
  else
    taker_pays = make_currency currencies[:buy]
    taker_gets = make_currency currencies[:with]
    price = 1 / price
    amount = (amount * price).floor
  end

  Stellar::Transaction.create_offer({
    account:  ,
    sequence: next_sequence(),
    taker_gets: taker_gets,
    taker_pays: taker_pays,
    amount: amount,
    price: price,
  }).to_envelope()
end

#payment(from, to, amount, options = {}) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/stellar_core_commander/operation_builder.rb', line 26

def payment(from, to, amount, options={})
  from =  from
  to   =  to

  attrs = {
    account:     from,
    destination: to,
    sequence:    next_sequence(from),
    amount:      normalize_amount(amount),
  }

  tx =  if options[:with]
          attrs[:with] = normalize_amount(options[:with])
          attrs[:path] = options[:path].map{|p| make_currency p}
          Stellar::Transaction.path_payment(attrs)
        else
          Stellar::Transaction.payment(attrs)
        end

  tx.to_envelope(from)
end

#require_trust_auth(account) ⇒ Object



120
121
122
# File 'lib/stellar_core_commander/operation_builder.rb', line 120

def require_trust_auth()
  set_flags , [:auth_required_flag]
end

#set_flags(account, flags) ⇒ Object



125
126
127
128
129
130
131
132
133
134
135
# File 'lib/stellar_core_commander/operation_builder.rb', line 125

def set_flags(, flags)
   =  

  tx = Stellar::Transaction.set_options({
    account:  ,
    sequence: next_sequence(),
    set:      (flags),
  })

  tx.to_envelope()
end

#trust(account, issuer, code) ⇒ Object



62
63
64
# File 'lib/stellar_core_commander/operation_builder.rb', line 62

def trust(, issuer, code)
  change_trust , issuer, code, (2**63)-1
end