Class: Chain::Transaction::ClientModule

Inherits:
ClientModule show all
Defined in:
lib/chain/transaction.rb

Instance Attribute Summary

Attributes inherited from ClientModule

#client

Instance Method Summary collapse

Methods inherited from ClientModule

#initialize

Constructor Details

This class inherits a constructor from Chain::ClientModule

Instance Method Details

#build(builder = nil) { ... } ⇒ Template

Build an unsigned transaction from a set of actions.

Parameters:

  • builder (Builder) (defaults to: nil)

    Builder object with actions defined. If provided, overrides block parameter.

Yields:

  • Block defining transaction actions. A Builder object is passed as the only parameter.

Returns:

  • (Template)

    Unsigned transaction template, or error.



60
61
62
63
64
65
66
67
68
69
# File 'lib/chain/transaction.rb', line 60

def build(builder = nil, &block)
  if builder.nil?
    builder = Builder.new(&block)
  end

  client.conn.singleton_batch_request(
    'build-transaction',
    [builder]
  ) { |item| Template.new(item) }
end

#build_batch(builders) ⇒ BatchResponse<Template>

Build multiple unsigned transactions from multiple sets of actions.

Parameters:

  • builders (Array<Builder>)

    Multiple builder objects with actions defined.

Returns:



74
75
76
77
78
79
# File 'lib/chain/transaction.rb', line 74

def build_batch(builders)
  client.conn.batch_request(
    'build-transaction',
    builders
  ) { |item| Template.new(item) }
end

#query(opts = {}) ⇒ Query

List all transactions, optionally filtered

Parameters:

  • opts (Hash) (defaults to: {})

    Filtering information

Options Hash (opts):

  • filter (String)
  • filter_params (Array<String|Integer>)

    Parameter values for filter string (if needed).

  • start_time (Integer)

    A Unix timestamp in milliseconds. When specified, only transactions with a block time greater than the start time will be returned.

  • end_time (Integer)

    A Unix timestamp in milliseconds. When specified, only transactions with a block time less than the start time will be returned.

  • timeout (Integer)

    A time in milliseconds after which a server timeout should occur. Defaults to 1000 (1 second).

Returns:



109
110
111
# File 'lib/chain/transaction.rb', line 109

def query(opts = {})
  Query.new(client, opts)
end

#submit(template) ⇒ SubmitResponse

Submit a signed transaction to the blockchain.

Parameters:

  • template (Template)

    Signed transaction template.

Returns:



84
85
86
87
88
89
# File 'lib/chain/transaction.rb', line 84

def submit(template)
  client.conn.singleton_batch_request(
    'submit-transaction',
    {transactions: [template]}
  ) { |item| SubmitResponse.new(item) }
end

#submit_batch(templates) ⇒ BatchResponse<SubmitResponse>

Submit multiple signed transactions to the blockchain.

Parameters:

  • templates (Array<Template>)

    Array of signed transaction templates.

Returns:



94
95
96
97
98
99
# File 'lib/chain/transaction.rb', line 94

def submit_batch(templates)
  client.conn.batch_request(
    'submit-transaction',
    {transactions: templates}
  ) { |item| SubmitResponse.new(item) }
end