Class: MVM::Registry
- Inherits:
-
Object
- Object
- MVM::Registry
- Defined in:
- lib/mvm/registry.rb
Instance Attribute Summary collapse
-
#registry ⇒ Object
readonly
Returns the value of attribute registry.
-
#rpc ⇒ Object
readonly
Returns the value of attribute rpc.
Instance Method Summary collapse
- #asset_from_contract(contract) ⇒ Object
- #contract_from_asset(asset_id) ⇒ Object
- #contract_from_multisig(user_ids, threshold) ⇒ Object
- #contract_from_user(user_id) ⇒ Object
-
#initialize(rpc_url: MVM::RPC_URL, registry_address: MVM::REGISTRY_ADDRESS) ⇒ Registry
constructor
A new instance of Registry.
- #pid ⇒ Object
- #user_from_contract(contract) ⇒ Object
- #users_from_contract(contract) ⇒ Object
- #version ⇒ Object
Constructor Details
#initialize(rpc_url: MVM::RPC_URL, registry_address: MVM::REGISTRY_ADDRESS) ⇒ Registry
Returns a new instance of Registry.
7 8 9 10 |
# File 'lib/mvm/registry.rb', line 7 def initialize(rpc_url: MVM::RPC_URL, registry_address: MVM::REGISTRY_ADDRESS) @rpc = Eth::Client.create rpc_url @registry = Eth::Contract.from_abi name: 'Registry', address: registry_address, abi: File.read(File.('./abis/registry.json', __dir__)) end |
Instance Attribute Details
#registry ⇒ Object (readonly)
Returns the value of attribute registry.
5 6 7 |
# File 'lib/mvm/registry.rb', line 5 def registry @registry end |
#rpc ⇒ Object (readonly)
Returns the value of attribute rpc.
5 6 7 |
# File 'lib/mvm/registry.rb', line 5 def rpc @rpc end |
Instance Method Details
#asset_from_contract(contract) ⇒ Object
21 22 23 24 |
# File 'lib/mvm/registry.rb', line 21 def asset_from_contract(contract) hex = @rpc.call(@registry, 'assets', contract).to_s(16) MixinBot::UUID.new(hex:).unpacked end |
#contract_from_asset(asset_id) ⇒ Object
45 46 47 |
# File 'lib/mvm/registry.rb', line 45 def contract_from_asset(asset_id) @rpc.call @registry, 'contracts', asset_id.gsub('-', '').to_i(16) end |
#contract_from_multisig(user_ids, threshold) ⇒ Object
53 54 55 56 57 58 59 60 61 |
# File 'lib/mvm/registry.rb', line 53 def contract_from_multisig(user_ids, threshold) bytes = [] bytes += MixinBot.utils.encode_uint16(user_ids.length) bytes += [user_ids.sort.join.gsub('-', '')].pack('H*').bytes bytes += MixinBot.utils.encode_uint16(threshold) hash = Eth::Util.bin_to_prefixed_hex(Eth::Util.keccak256(bytes.pack('C*'))) @rpc.call @registry, 'contracts', hash.to_i(16) end |
#contract_from_user(user_id) ⇒ Object
49 50 51 |
# File 'lib/mvm/registry.rb', line 49 def contract_from_user(user_id) contract_from_multisig [user_id], 1 end |
#pid ⇒ Object
12 13 14 15 |
# File 'lib/mvm/registry.rb', line 12 def pid hex = @rpc.call(@registry, 'PID').to_s(16) MixinBot::UUID.new(hex:).unpacked end |
#user_from_contract(contract) ⇒ Object
40 41 42 43 |
# File 'lib/mvm/registry.rb', line 40 def user_from_contract(contract) group = users_from_contract contract group[:members].first end |
#users_from_contract(contract) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/mvm/registry.rb', line 26 def users_from_contract(contract) bytes = @rpc.call(@registry, 'users', contract).bytes members = [] length = bytes.shift(2).reverse.pack('C*').unpack1('S*') length.times do members << MixinBot::UUID.new(raw: bytes.shift(16).pack('C*')).unpacked end threshold = bytes.shift(2).reverse.pack('C*').unpack1('S*') { members:, threshold: }.with_indifferent_access end |
#version ⇒ Object
17 18 19 |
# File 'lib/mvm/registry.rb', line 17 def version @rpc.call @registry, 'VERSION' end |