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_program(params) ⇒ Builder
deprecated
Deprecated.
(as of version 1.1) Use #control_with_receiver instead.
-
#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.
322 323 324 |
# File 'lib/chain/transaction.rb', line 322 def initialize(&block) block.call(self) if block end |
Instance Method Details
#actions ⇒ Array<Hash>
327 328 329 |
# File 'lib/chain/transaction.rb', line 327 def actions @actions ||= [] end |
#add_action(params) ⇒ Builder
Add an action to the transaction builder
370 371 372 373 374 375 376 |
# File 'lib/chain/transaction.rb', line 370 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
333 334 335 336 337 338 339 340 |
# File 'lib/chain/transaction.rb', line 333 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.
440 441 442 |
# File 'lib/chain/transaction.rb', line 440 def control_with_account(params) add_action(params.merge(type: :control_account)) end |
#control_with_program(params) ⇒ Builder
(as of version 1.1) Use #control_with_receiver instead.
Add a control action taken on a control program.
468 469 470 |
# File 'lib/chain/transaction.rb', line 468 def control_with_program(params) add_action(params.merge(type: :control_program)) end |
#control_with_receiver(params) ⇒ Builder
Sends assets to the specified receiver.
454 455 456 |
# File 'lib/chain/transaction.rb', line 454 def control_with_receiver(params) add_action(params.merge(type: :control_receiver)) end |
#issue(params) ⇒ Builder
Add an issuance action.
398 399 400 |
# File 'lib/chain/transaction.rb', line 398 def issue(params) add_action(params.merge(type: :issue)) end |
#retire(params) ⇒ Builder
Add a retire action.
480 481 482 |
# File 'lib/chain/transaction.rb', line 480 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.
424 425 426 |
# File 'lib/chain/transaction.rb', line 424 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.
414 415 416 |
# File 'lib/chain/transaction.rb', line 414 def spend_from_account(params) add_action(params.merge(type: :spend_account)) end |
#to_h ⇒ Hash
349 350 351 352 353 354 355 356 357 358 359 |
# File 'lib/chain/transaction.rb', line 349 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
362 363 364 |
# File 'lib/chain/transaction.rb', line 362 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.
383 384 385 386 387 388 |
# File 'lib/chain/transaction.rb', line 383 def transaction_reference_data(reference_data) add_action( type: :set_transaction_reference_data, reference_data: reference_data, ) end |
#ttl(ttl) ⇒ Builder
343 344 345 346 |
# File 'lib/chain/transaction.rb', line 343 def ttl(ttl) @ttl = ttl self end |