Class: StellarCoreCommander::Transactor

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

Overview

A transactor plays transactions against a stellar-core test node.

Defined Under Namespace

Classes: FailedTransaction

Instance Method Summary collapse

Constructor Details

#initialize(commander) ⇒ Transactor

Returns a new instance of Transactor.



15
16
17
18
19
20
21
22
# File 'lib/stellar_core_commander/transactor.rb', line 15

def initialize(commander)
  @commander         = commander
  @named             = {}.with_indifferent_access
  @unverified        = []
  @operation_builder = OperationBuilder.new(self)

   :master, Stellar::KeyPair.from_raw_seed("allmylifemyhearthasbeensearching")
end

Instance Method Details

#account(name, keypair = Stellar::KeyPair.random) ⇒ Object

Registered an account for this scenario. Future calls may refer to the name provided.

Parameters:

  • name (Symbol)

    the name to register the keypair at

  • keypair=Stellar::KeyPair.random (Stellar::KeyPair)

    the keypair to use for this account



50
51
52
53
54
55
56
# File 'lib/stellar_core_commander/transactor.rb', line 50

def (name, keypair=Stellar::KeyPair.random)
  unless keypair.is_a?(Stellar::KeyPair)
    raise ArgumentError, "`#{keypair.class.name}` is not `Stellar::KeyPair`"
  end

  add_named name, keypair
end

#allow_trust(*args) ⇒ Object



114
115
116
117
# File 'lib/stellar_core_commander/transactor.rb', line 114

def allow_trust(*args)
  envelope = @operation_builder.allow_trust(*args)
  submit_transaction envelope
end

#change_trust(*args) ⇒ Object



86
87
88
89
# File 'lib/stellar_core_commander/transactor.rb', line 86

def change_trust(*args)
  envelope = @operation_builder.change_trust(*args)
  submit_transaction envelope
end

#close_ledgerObject

Triggers a ledger close. Any unvalidated transaction will be validated, which will trigger an error if any fail to be validated



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

def close_ledger
  @process.close_ledger

  @unverified.each do |eb|
    begin
      envelope, after_confirmation = *eb
      result = validate_transaction envelope
      after_confirmation.call(result) if after_confirmation
    rescue FailedTransaction
      $stderr.puts "Failed to validate tx: #{Convert.to_hex envelope.tx.hash}"
      $stderr.puts "failed result: #{result.to_xdr(:hex)}"
      exit 1
    end
  end

  @unverified.clear
end

#create_account(*args) ⇒ Object



72
73
74
75
# File 'lib/stellar_core_commander/transactor.rb', line 72

def (*args)
  envelope = @operation_builder.(*args)
  submit_transaction envelope
end

#get_account(name) ⇒ Object



143
144
145
146
147
148
149
# File 'lib/stellar_core_commander/transactor.rb', line 143

def (name)
  @named[name].tap do |found|
    unless found.is_a?(Stellar::KeyPair)
      raise ArgumentError, "#{name.inspect} is not account"
    end
  end
end

#get_process(name) ⇒ Object



152
153
154
155
156
157
158
# File 'lib/stellar_core_commander/transactor.rb', line 152

def get_process(name)
  @named[name].tap do |found|
    unless found.is_a?(Process)
      raise ArgumentError, "#{name.inspect} is not process"
    end
  end
end

#next_sequence(account) ⇒ Object



161
162
163
164
165
166
# File 'lib/stellar_core_commander/transactor.rb', line 161

def next_sequence()
  base_sequence  = @process.sequence_for()
  inflight_count = @unverified.select{|e| e.first.tx. == .public_key}.length

  base_sequence + inflight_count + 1
end

#offer(*args) ⇒ Object



93
94
95
96
# File 'lib/stellar_core_commander/transactor.rb', line 93

def offer(*args)
  envelope = @operation_builder.offer(*args)
  submit_transaction envelope
end

#payment(*args) ⇒ Object



61
62
63
64
65
66
67
68
# File 'lib/stellar_core_commander/transactor.rb', line 61

def payment(*args)
  envelope = @operation_builder.payment(*args)

  submit_transaction envelope do |result|
    payment_result = result.result.results!.first.tr!.value
    raise FailedTransaction unless payment_result.code.value >= 0
  end
end

#require_trust_auth(*args) ⇒ Object



100
101
102
103
# File 'lib/stellar_core_commander/transactor.rb', line 100

def require_trust_auth(*args)
  envelope = @operation_builder.require_trust_auth(*args)
  submit_transaction envelope
end

#run_recipe(recipe_path) ⇒ Object

Runs the provided recipe against the process identified by @process

Parameters:

  • recipe_path (String)

    path to the recipe file



30
31
32
33
34
35
36
37
38
39
# File 'lib/stellar_core_commander/transactor.rb', line 30

def run_recipe(recipe_path)
  @process = @commander.make_process
  @process.run
  @process.wait_for_ready

  add_named :process, @process

  recipe_content = IO.read(recipe_path)
  instance_eval recipe_content
end

#set_flags(*args) ⇒ Object



107
108
109
110
# File 'lib/stellar_core_commander/transactor.rb', line 107

def set_flags(*args)
  envelope = @operation_builder.set_flags(*args)
  submit_transaction envelope
end

#trust(*args) ⇒ Object



79
80
81
82
# File 'lib/stellar_core_commander/transactor.rb', line 79

def trust(*args)
  envelope = @operation_builder.trust(*args)
  submit_transaction envelope
end