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:



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

def create(opts)
  opts = {client_token: SecureRandom.uuid}.merge(opts)
  client.conn.singleton_batch_request('create-account', [opts]) { |item| Account.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:



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

def create_batch(opts)
  opts = opts.map { |i| {client_token: SecureRandom.uuid}.merge(i) }
  client.conn.batch_request('create-account', opts) { |item| Account.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:



77
78
79
# File 'lib/chain/account.rb', line 77

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:



85
86
87
# File 'lib/chain/account.rb', line 85

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:



93
94
95
# File 'lib/chain/account.rb', line 93

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

#update_tags(opts) ⇒ Hash

Returns a success message.

Parameters:

  • opts (Hash)

    Options hash specifiying account creation details.

Options Hash (opts):

  • id (String)

    The ID of the account. Either an ID or alias should be provided, but not both.

  • alias (String)

    The alias of the account. Either an ID or alias should be provided, but not both.

  • tags (Hash)

    A new set of tags, which will replace the existing tags.

Returns:

  • (Hash)

    a success message.



60
61
62
# File 'lib/chain/account.rb', line 60

def update_tags(opts)
  client.conn.singleton_batch_request('update-account-tags', [opts])
end

#update_tags_batch(opts) ⇒ BatchResponse<Hash>

Parameters:

  • opts (Array<Hash>)

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

Returns:



66
67
68
# File 'lib/chain/account.rb', line 66

def update_tags_batch(opts)
  client.conn.batch_request('update-account-tags', opts)
end