Module: QuorumSdk::Chain::Management
- Included in:
- QuorumSdk::Chain
- Defined in:
- lib/quorum_sdk/chain/management.rb
Overview
Wrapper for HTTP APIs for chain
Constant Summary collapse
- ARGUMENTS_FOR_UPDATE_CHAIN_CONFIG =
%i[config type].freeze
- ARGUMENTS_FOR_UPDATE_AUTH_MODE =
%i[trx_auth_mode].freeze
- ARGUMENTS_FOR_UPDATE_ALLOW_LIST =
%i[action pubkey].freeze
- ARGUMENTS_FOR_UPDATE_DENY_LIST =
%i[action pubkey].freeze
Instance Method Summary collapse
- #allow_list(group_id: nil) ⇒ Object
- #auth_type(trx_type, group_id: nil) ⇒ Object
- #deny_list(group_id: nil) ⇒ Object
- #update_allow_list(**kwargs) ⇒ Object
- #update_chain_config(**kwargs) ⇒ Object
- #update_deny_list(**kwargs) ⇒ Object
- #update_trx_auth_mode(**kwargs) ⇒ Object
Instance Method Details
#allow_list(group_id: nil) ⇒ Object
7 8 9 10 11 12 13 |
# File 'lib/quorum_sdk/chain/management.rb', line 7 def allow_list(group_id: nil) group_id ||= @group_id raise ArgumentError, 'group_id must be provided' if group_id.blank? path = "api/v1/group/#{group_id}/trx/allowlist" client.get(path).body end |
#auth_type(trx_type, group_id: nil) ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/quorum_sdk/chain/management.rb', line 23 def auth_type(trx_type, group_id: nil) group_id ||= @group_id raise ArgumentError, 'group_id must be provided' if group_id.blank? path = "api/v1/group/#{group_id}/trx/auth/#{trx_type}" client.get(path).body end |
#deny_list(group_id: nil) ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/quorum_sdk/chain/management.rb', line 15 def deny_list(group_id: nil) group_id ||= @group_id raise ArgumentError, 'group_id must be provided' if group_id.blank? path = "api/v1/group/#{group_id}/trx/denylist" client.get(path).body end |
#update_allow_list(**kwargs) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/quorum_sdk/chain/management.rb', line 79 def update_allow_list(**kwargs) raise ArgumentError, "Keyword arguments #{ARGUMENTS_FOR_UPDATE_ALLOW_LIST} must be provided" unless ARGUMENTS_FOR_UPDATE_ALLOW_LIST.all?(&->(arg) { arg.in? kwargs.keys }) trx_type = kwargs[:trx_type] || ['POST'] trx_type = [trx_type] if trx_type.is_a?(String) raise ArgumentError, 'trx type must be one of POST/ANNOUNCE/REQ_BLOCK_FORWARD/REQ_BLOCK_FORWARD' unless trx_type.all?(&->(op) { op.in? %w[POST ANNOUNCE REQ_BLOCK_RESP REQ_BLOCK_BACKWARD] }) action = kwargs[:action] raise ArgumentError, 'trx_auth_mode must be one of add/remove' unless action.in? %w[add remove] pubkey = kwargs[:pubkey] if Eth::Util.hex?(pubkey) pubkey = Secp256k1::PublicKey.from_data([pubkey].pack('H*')).compressed pubkey = Base64.urlsafe_encode64(pubkey) end group_id = kwargs[:group_id] || @group_id raise ArgumentError, 'group_id must be provided' if group_id.blank? update_chain_config( group_id:, type: 'upd_alw_list', config: { trx_type:, action:, pubkey: }, memo: kwargs[:memo] ) end |
#update_chain_config(**kwargs) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/quorum_sdk/chain/management.rb', line 32 def update_chain_config(**kwargs) raise ArgumentError, "Keyword arguments #{ARGUMENTS_FOR_UPDATE_CHAIN_CONFIG} must be provided" unless ARGUMENTS_FOR_UPDATE_CHAIN_CONFIG.all?(&->(arg) { arg.in? kwargs.keys }) type = kwargs[:type] raise ArgumentError, 'type must be one of set_trx_auth_mode/upd_alw_list/upd_dny_list' unless type.in? %w[set_trx_auth_mode upd_alw_list upd_dny_list] config = kwargs[:config] config = config.to_json if config.is_a?(Hash) group_id = kwargs[:group_id] || @group_id raise ArgumentError, 'group_id must be provided' if group_id.blank? path = 'api/v1/group/chainconfig' payload = { type:, config:, group_id:, memo: kwargs[:memo] }.compact client.post(path, **payload).body end |
#update_deny_list(**kwargs) ⇒ Object
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/quorum_sdk/chain/management.rb', line 111 def update_deny_list(**kwargs) raise ArgumentError, "Keyword arguments #{ARGUMENTS_FOR_UPDATE_DENY_LIST} must be provided" unless ARGUMENTS_FOR_UPDATE_DENY_LIST.all?(&->(arg) { arg.in? kwargs.keys }) trx_type = kwargs[:trx_type] || ['POST'] trx_type = [trx_type] if trx_type.is_a?(String) raise ArgumentError, 'trx type must be one of POST/ANNOUNCE/REQ_BLOCK_FORWARD/REQ_BLOCK_FORWARD' unless trx_type.all?(&->(op) { op.in? %w[POST ANNOUNCE REQ_BLOCK_RESP REQ_BLOCK_BACKWARD] }) action = kwargs[:action] raise ArgumentError, 'trx_auth_mode must be one of add/remove' unless action.in? %w[add remove] pubkey = kwargs[:pubkey] if Eth::Util.hex?(pubkey) pubkey = Secp256k1::PublicKey.from_data([pubkey].pack('H*')).compressed pubkey = Base64.urlsafe_encode64(pubkey) end group_id = kwargs[:group_id] || @group_id raise ArgumentError, 'group_id must be provided' if group_id.blank? update_chain_config( group_id:, type: 'upd_dny_list', config: { trx_type:, action:, pubkey: }, memo: kwargs[:memo] ) end |
#update_trx_auth_mode(**kwargs) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/quorum_sdk/chain/management.rb', line 55 def update_trx_auth_mode(**kwargs) raise ArgumentError, "Keyword arguments #{ARGUMENTS_FOR_UPDATE_AUTH_MODE} must be provided" unless ARGUMENTS_FOR_UPDATE_AUTH_MODE.all?(&->(arg) { arg.in? kwargs.keys }) trx_type = kwargs[:trx_type] || 'POST' raise ArgumentError, 'trx_type must be one of POST/ANNOUNCE/REQ_BLOCK_FORWARD/REQ_BLOCK_FORWARD' unless trx_type.in? %w[POST ANNOUNCE REQ_BLOCK_RESP REQ_BLOCK_BACKWARD] trx_auth_mode = kwargs[:trx_auth_mode] raise ArgumentError, 'trx_auth_mode must be one of follow_alw_list/follow_dny_list' unless trx_auth_mode.in? %w[follow_alw_list follow_dny_list] group_id = kwargs[:group_id] || @group_id raise ArgumentError, 'group_id must be provided' if group_id.blank? update_chain_config( group_id:, type: 'set_trx_auth_mode', config: { trx_type:, trx_auth_mode: }, memo: kwargs[:memo] ) end |