Class: Chain::Account::ClientModule

Inherits:
ClientModule show all
Defined in:
lib/chain/account.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

#create(opts) ⇒ Account

Parameters:

  • opts (Hash)

    Options hash specifiying account creation details.

Options Hash (opts):

  • alias (String)

    User specified, unique identifier.

  • root_xpubs (Array<String>)

    The list of keys used to create control programs under the account.

  • quorum (Integer)

    The number of keys required to sign transactions for the account.

  • tags (Hash)

    User-specified tag structure for the account.

Returns:



44
45
46
47
# File 'lib/chain/account.rb', line 44

def create(opts)
  opts = {client_token: SecureRandom.uuid}.merge(opts)
  client.conn.singleton_batch_request('create-account', [opts]) { |item| .new(item) }
end

#create_batch(opts) ⇒ BatchResponse<Account>

Parameters:

  • opts (Array<Hash>)

    An array of options hashes. See #create for a description of the hash structure.

Returns:



51
52
53
54
# File 'lib/chain/account.rb', line 51

def create_batch(opts)
  opts = opts.map { |i| {client_token: SecureRandom.uuid}.merge(i) }
  client.conn.batch_request('create-account', opts) { |item| .new(item) }
end

#create_control_program(opts = {}) ⇒ ControlProgram

Deprecated.

(as of version 1.1) Use #create_receiver instead.

Parameters:

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

Returns:



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

def create_control_program(opts = {})
  # We don't use keyword params here because 'alias' is a Ruby reserverd
  # word.
  params = {}
  params[:account_alias] = opts[:alias] if opts.key?(:alias)
  params[:account_id] = opts[:id] if opts.key?(:id)

  client.conn.singleton_batch_request(
    'create-control-program',
    [{type: :account, params: params}]
  ) { |item| ControlProgram.new(item) }
end

#create_receiver(opts) ⇒ Receiver

Creates a new receiver under the specified account.

Parameters:

  • opts (Hash)

    Options hash

Options Hash (opts):

  • :account_alias (String)

    Unique alias for an account. Either account_alias or account_id is required.

  • :account_id (String)

    Unique ID for an account. Either account_alias or account_id is required.

  • :expires_at (String)

    An RFC3339 timestamp indicating when the receiver will expire. Defaults to 30 days in the future.

Returns:



79
80
81
# File 'lib/chain/account.rb', line 79

def create_receiver(opts)
  client.conn.singleton_batch_request('create-account-receiver', [opts]) { |item| Receiver.new(item) }
end

#create_receiver_batch(opts_list) ⇒ BatchResponse<Receiver>

Creates new receivers under the specified accounts.

Parameters:

  • opts_list (Array<Hash>)

    Array of options hashes. See #create_receiver for a description of the hash structure.

Returns:



87
88
89
# File 'lib/chain/account.rb', line 87

def create_receiver_batch(opts_list)
  client.conn.batch_request('create-account-receiver', opts_list) { |item| Receiver.new(item) }
end

#query(opts = {}) ⇒ Query

Parameters:

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

    Filtering information

Options Hash (opts):

Returns:



95
96
97
# File 'lib/chain/account.rb', line 95

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