Class: Chain::Transaction::Builder
- Inherits:
-
Object
- Object
- Chain::Transaction::Builder
- Defined in:
- lib/chain/transaction.rb
Instance Method Summary collapse
- #actions ⇒ Array<Hash>
-
#add_action(params) ⇒ Builder
Add an action to the transaction builder.
- #base_transaction(template_or_raw_tx) ⇒ Builder
-
#control_with_account(params) ⇒ Builder
Add a control action taken on a particular account.
-
#control_with_receiver(params) ⇒ Builder
Sends assets to the specified receiver.
-
#initialize(&block) ⇒ Builder
constructor
A new instance of Builder.
-
#issue(params) ⇒ Builder
Add an issuance action.
-
#retire(params) ⇒ Builder
Add a retire action.
-
#spend_account_unspent_output(params) ⇒ Builder
Add a spend action taken on a particular unspent output.
-
#spend_from_account(params) ⇒ Builder
Add a spend action taken on a particular account.
- #to_h ⇒ Hash
- #to_json(opts = nil) ⇒ String
-
#transaction_reference_data(reference_data) ⇒ Builder
Sets the transaction-level reference data.
- #ttl(ttl) ⇒ Builder
Constructor Details
#initialize(&block) ⇒ Builder
Returns a new instance of Builder.
293 294 295 |
# File 'lib/chain/transaction.rb', line 293 def initialize(&block) block.call(self) if block end |
Instance Method Details
#actions ⇒ Array<Hash>
298 299 300 |
# File 'lib/chain/transaction.rb', line 298 def actions @actions ||= [] end |
#add_action(params) ⇒ Builder
Add an action to the transaction builder
341 342 343 344 345 346 347 |
# File 'lib/chain/transaction.rb', line 341 def add_action(params) # Some actions require an idempotency token, so we'll add it here as a # generic parameter. params = {client_token: SecureRandom.uuid}.merge(params) actions << params self end |
#base_transaction(template_or_raw_tx) ⇒ Builder
304 305 306 307 308 309 310 311 |
# File 'lib/chain/transaction.rb', line 304 def base_transaction(template_or_raw_tx) if template_or_raw_tx.is_a?(Transaction::Template) @base_transaction = template_or_raw_tx.raw_transaction else @base_transaction = template_or_raw_tx end self end |
#control_with_account(params) ⇒ Builder
Add a control action taken on a particular account.
409 410 411 |
# File 'lib/chain/transaction.rb', line 409 def control_with_account(params) add_action(params.merge(type: :control_account)) end |
#control_with_receiver(params) ⇒ Builder
Sends assets to the specified receiver.
423 424 425 |
# File 'lib/chain/transaction.rb', line 423 def control_with_receiver(params) add_action(params.merge(type: :control_receiver)) end |
#issue(params) ⇒ Builder
Add an issuance action.
369 370 371 |
# File 'lib/chain/transaction.rb', line 369 def issue(params) add_action(params.merge(type: :issue)) end |
#retire(params) ⇒ Builder
Add a retire action.
435 436 437 |
# File 'lib/chain/transaction.rb', line 435 def retire(params) add_action(params.merge(type: :retire)) end |
#spend_account_unspent_output(params) ⇒ Builder
Add a spend action taken on a particular unspent output.
393 394 395 |
# File 'lib/chain/transaction.rb', line 393 def spend_account_unspent_output(params) add_action(params.merge(type: :spend_account_unspent_output)) end |
#spend_from_account(params) ⇒ Builder
Add a spend action taken on a particular account.
385 386 387 |
# File 'lib/chain/transaction.rb', line 385 def spend_from_account(params) add_action(params.merge(type: :spend_account)) end |
#to_h ⇒ Hash
320 321 322 323 324 325 326 327 328 329 330 |
# File 'lib/chain/transaction.rb', line 320 def to_h { actions: actions, base_transaction: @base_transaction, ttl: @ttl, }.select do |k,v| # TODO: Patches an issue in Chain Core 1.0 where nil values are rejected # Remove in 1.1.0 or later v != nil end end |
#to_json(opts = nil) ⇒ String
333 334 335 |
# File 'lib/chain/transaction.rb', line 333 def to_json(opts = nil) to_h.to_json(opts) end |
#transaction_reference_data(reference_data) ⇒ Builder
Sets the transaction-level reference data. May only be used once per transaction.
354 355 356 357 358 359 |
# File 'lib/chain/transaction.rb', line 354 def transaction_reference_data(reference_data) add_action( type: :set_transaction_reference_data, reference_data: reference_data, ) end |
#ttl(ttl) ⇒ Builder
314 315 316 317 |
# File 'lib/chain/transaction.rb', line 314 def ttl(ttl) @ttl = ttl self end |