Module: QuorumSdk::Chain::Group

Included in:
QuorumSdk::Chain
Defined in:
lib/quorum_sdk/chain/group.rb

Overview

Wrapper for HTTP APIs for group

Constant Summary collapse

ARGUMENTS_FOR_CREATE_GROUP =
%i[app_key group_name].freeze

Instance Method Summary collapse

Instance Method Details

#clear_group(group_id) ⇒ Object



49
50
51
52
53
# File 'lib/quorum_sdk/chain/group.rb', line 49

def clear_group(group_id)
  path = 'api/v1/group/clear'
  payload = { group_id: }
  client.post(path, **payload).body
end

#create_content(group_id, data = nil, **kwargs) ⇒ Object



61
62
63
64
65
66
# File 'lib/quorum_sdk/chain/group.rb', line 61

def create_content(group_id, data = nil, **kwargs)
  data ||= kwargs
  path = "api/v1/group/#{group_id}/content"
  payload = { data: }
  client.post(path, **payload).body
end

#create_group(**kwargs) ⇒ Object

Raises:



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/quorum_sdk/chain/group.rb', line 13

def create_group(**kwargs)
  raise ArgumentError, "Keyword arguments #{ARGUMENTS_FOR_CREATE_GROUP} must be provided" unless ARGUMENTS_FOR_CREATE_GROUP.all?(&->(arg) { arg.in? kwargs.keys })

  consensus_type = kwargs[:consensus_type] || 'poa'
  raise ArgumentError, 'consensus_type should be poa or pos' unless consensus_type.in?(%w[poa pos])

  encryption_type = kwargs[:encryption_type] || 'public'
  raise ArgumentError, 'encryption_type should be public or private' unless encryption_type.in?(%w[public private])

  path = 'api/v1/group'

  payload = {
    consensus_type:,
    encryption_type:,
    app_key: kwargs[:app_key],
    group_name: kwargs[:group_name]
  }
  client.post(path, **payload).body
end

#group(group_id) ⇒ Object



7
8
9
10
# File 'lib/quorum_sdk/chain/group.rb', line 7

def group(group_id)
  path = "api/v1/group/#{group_id}"
  client.get(path).body
end

#groupsObject



33
34
35
36
# File 'lib/quorum_sdk/chain/group.rb', line 33

def groups
  path = 'api/v1/groups'
  client.get(path).body
end

#join_group(seed) ⇒ Object



43
44
45
46
47
# File 'lib/quorum_sdk/chain/group.rb', line 43

def join_group(seed)
  path = 'api/v2/group/join'
  payload = { seed: }
  client.post(path, **payload).body
end

#leave_group(group_id) ⇒ Object



55
56
57
58
59
# File 'lib/quorum_sdk/chain/group.rb', line 55

def leave_group(group_id)
  path = 'api/v1/group/leave'
  payload = { group_id: }
  client.post(path, **payload).body
end

#seed(group_id) ⇒ Object



38
39
40
41
# File 'lib/quorum_sdk/chain/group.rb', line 38

def seed(group_id)
  path = "api/v1/group/#{group_id}/seed"
  client.get(path).body
end