Class: Bytom::Accounts

Inherits:
Object
  • Object
show all
Defined in:
lib/bytom/api/accounts.rb

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Accounts

Returns a new instance of Accounts.



6
7
8
# File 'lib/bytom/api/accounts.rb', line 6

def initialize(client)
  @client = client
end

Instance Method Details

#create_account(root_xpubs: [], alias_name:, quorum: 1, access_token: nil) ⇒ Hash

Create account to manage addresses. single sign account contain only one root_xpubs and quorum; however multi sign account contain many number of root_xpubs and quorum, quorum is the number of verify signature, the range is [1, len(root_xpubs)].

Parameters:

  • root_xpubs (Array) (defaults to: [])
  • alias_name (Object)
  • quorum (Object) (defaults to: 1)
  • access_token (Object) (defaults to: nil)

    optional

Returns:

  • (Hash)


20
21
22
23
24
25
26
27
28
# File 'lib/bytom/api/accounts.rb', line 20

def (root_xpubs:[], alias_name:, quorum: 1, access_token: nil)
  params = {
      root_xpubs: root_xpubs,
      alias: alias_name,
      quorum: quorum,
      access_token: access_token
  }
  client.make_request('/create-account', 'post', params: params)
end

#create_account_receiver(account_id: nil, account_alias: nil) ⇒ Hash

create address and control program, the address and control program is are one to one relationship. in build-transaction API, receiver is address when action type is control_address, and receiver is control program when action type is control_program, they are the same result.

Parameters:

  • account_id (String) (defaults to: nil)
  • account_alias (String) (defaults to: nil)

Returns:

  • (Hash)


103
104
105
106
107
108
109
# File 'lib/bytom/api/accounts.rb', line 103

def (account_id: nil, account_alias: nil )
  params = {}
  params = { account_id:  } if 
  params = { account_alias:  } if 
  return {status: 'failed'} if not params
  client.make_request('/create-account-receiver', 'post', params: params)
end

#delete_account_by_alias(account_alias:) ⇒ Nil

Delete existed account by account alias, please make sure that there is no balance in the related addresses.

Parameters:

  • account_alias (String)

Returns:

  • (Nil)

    nil if the account alias is updated successfully.



91
92
93
# File 'lib/bytom/api/accounts.rb', line 91

def (account_alias:)
  client.make_request('/delete-account', 'post', params: {account_alias: })
end

#delete_account_by_id(account_id:) ⇒ Nil

Delete existed account by account id, please make sure that there is no balance in the related addresses.

Parameters:

  • account_id (String)

Returns:

  • (Nil)

    nil if the account alias is updated successfully.



81
82
83
# File 'lib/bytom/api/accounts.rb', line 81

def (account_id:)
  client.make_request('/delete-account', 'post', params: {account_id: })
end

#list_accounts(id: nil, alias_name: nil) ⇒ Hash

Returns the list of all available accounts.

Returns:

  • (Hash)


35
36
37
38
39
40
# File 'lib/bytom/api/accounts.rb', line 35

def list_accounts(id: nil, alias_name:nil)
  params = {}
  params = {id: id} if id
  params = {alias: alias_name} if alias_name
  client.make_request('/list-accounts', 'post', params: params)
end

#update_account_alias_by_alias(account_alias:, new_alias:) ⇒ Nil

By account alias to update alias for the existed account.

Parameters:

  • account_alias (String)
  • new_alias (String)

Returns:

  • (Nil)

    nil if the account alias is updated successfully.



66
67
68
69
70
71
72
# File 'lib/bytom/api/accounts.rb', line 66

def (account_alias:, new_alias:)
  params = {
      account_alias: ,
      new_alias: new_alias
  }
  client.make_request('/update-account-alias', 'post', params: params)
end

#update_account_alias_by_id(account_id:, new_alias:) ⇒ nil

By account id to update alias for the existed account.

Parameters:

  • account_id (String)
  • new_alias (String)

Returns:

  • (nil)

    nil if the account alias is updated successfully.



50
51
52
53
54
55
56
# File 'lib/bytom/api/accounts.rb', line 50

def (account_id:, new_alias:)
  params = {
      account_id: ,
      new_alias: new_alias
  }
  client.make_request('/update-account-alias', 'post', params: params)
end