Class: StellarCoreCommander::OperationBuilder
- Inherits:
-
Object
- Object
- StellarCoreCommander::OperationBuilder
- Includes:
- Contracts
- Defined in:
- lib/stellar_core_commander/operation_builder.rb
Constant Summary collapse
- Currency =
Or[ [String, Symbol]
- Amount =
- OfferCurrencies =
Instance Method Summary collapse
- #allow_trust(account, trustor, code) ⇒ Object
- #change_trust(account, issuer, code, limit) ⇒ Object
- #create_account(account, funder = :master, starting_balance = 1000_0000000) ⇒ Object
-
#initialize(transactor) ⇒ OperationBuilder
constructor
A new instance of OperationBuilder.
- #offer(account, currencies, amount, price) ⇒ Object
- #payment(from, to, amount, options = {}) ⇒ Object
- #require_trust_auth(account) ⇒ Object
- #set_flags(account, flags) ⇒ Object
- #trust(account, issuer, code) ⇒ Object
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(account, trustor, code) currency = make_currency([code, account]) account = get_account account trustor = get_account trustor Stellar::Transaction.allow_trust({ account: account, sequence: next_sequence(account), currency: currency, trustor: trustor, authorize: true, }).to_envelope(account) 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(account, issuer, code, limit) account = get_account account Stellar::Transaction.change_trust({ account: account, sequence: next_sequence(account), line: make_currency([code, issuer]), limit: limit }).to_envelope(account) 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 create_account(account, funder=:master, starting_balance=1000_0000000) account = get_account account funder = get_account funder Stellar::Transaction.create_account({ account: funder, destination: account, 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(account, currencies, amount, price) account = get_account account 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: account, sequence: next_sequence(account), taker_gets: taker_gets, taker_pays: taker_pays, amount: amount, price: price, }).to_envelope(account) 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, ={}) from = get_account from to = get_account to attrs = { account: from, destination: to, sequence: next_sequence(from), amount: normalize_amount(amount), } tx = if [:with] attrs[:with] = normalize_amount([:with]) attrs[:path] = [: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(account) set_flags account, [: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(account, flags) account = get_account account tx = Stellar::Transaction.({ account: account, sequence: next_sequence(account), set: make_account_flags(flags), }) tx.to_envelope(account) end |
#trust(account, issuer, code) ⇒ Object
62 63 64 |
# File 'lib/stellar_core_commander/operation_builder.rb', line 62 def trust(account, issuer, code) change_trust account, issuer, code, (2**63)-1 end |