mixin_bot 0.11.1 → 0.11.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1555506a74f1562be6b92eb661ee0a870bfe2a1a027d808984d4214c1ecde0cc
4
- data.tar.gz: 6d93e542cf33a92cd3088944ee1ee22a7bd3be3e974760e6ad802e29d003c1b6
3
+ metadata.gz: 630485777ae51872c9c3f5835375f63bc192918dfd354c9ac2d2346b1fcf1835
4
+ data.tar.gz: fbcc1ca362beed41d977e2a9f6e0ebdf1c23fc0ee1ee373593372b221e6d0a43
5
5
  SHA512:
6
- metadata.gz: 4ac6e4f3ac3cd7ed3477794d34d47b9dbdd2fdbb47e2a4bd502976393faec0376d7833dad77fd43c24a04254ce456248af952b8e3f1db85cd2a04323fcb36970
7
- data.tar.gz: 83eecbd6f63ffb8caa4b295bf8f5ded53608e3036d1570104417089a1370c55216395adc7d79da7e958414052f1bb894dfabe95607a77b8dce9e89f130eb0072
6
+ metadata.gz: 37ee5ff2ecd52af503fa3d2ae49fc1ea730201b34ab99d9c184cab3d914bb565b245940b4df67d2801615a144f3daedb13ff4e921c597e11b0c8e4b18b017457
7
+ data.tar.gz: b77cb941c1a9dac7abb840190a333eda86b8a2536a876ea81ff2471d2951ba867ded88ae6a3dfc36fb803dfbd7898f8a0bbadf43cfd01336b050f9c7ee751750
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MixinBot
4
- VERSION = '0.11.1'
4
+ VERSION = '0.11.2'
5
5
  end
data/lib/mvm/bridge.rb CHANGED
@@ -8,6 +8,10 @@ module MVM
8
8
  @client = MVM::Client.new 'bridge.mvm.dev'
9
9
  end
10
10
 
11
+ def info
12
+ client.get '/'
13
+ end
14
+
11
15
  def user(public_key)
12
16
  path = '/users'
13
17
 
data/lib/mvm/nft.rb CHANGED
@@ -2,18 +2,15 @@
2
2
 
3
3
  module MVM
4
4
  class Nft
5
- RPC_URL = 'https://geth.mvm.dev'
6
- MIRROR_ADDRESS = '0xC193486e6Bf3E8461cb8fcdF178676a5D75c066A'
5
+ attr_reader :rpc, :mirror
7
6
 
8
- attr_reader :client, :mirror
9
-
10
- def initialize
11
- @client = Eth::Client.create RPC_URL
12
- @mirror = Eth::Contract.from_abi name: 'Mirror', address: MIRROR_ADDRESS, abi: File.open(File.expand_path('./abis/mirror.json', __dir__)).read
7
+ def initialize(rpc_url: MVM::RPC_URL, mirror_address: MVM::MIRROR_ADDRESS)
8
+ @rpc = Eth::Client.create rpc_url
9
+ @mirror = Eth::Contract.from_abi name: 'Mirror', address: mirror_address, abi: File.open(File.expand_path('./abis/mirror.json', __dir__)).read
13
10
  end
14
11
 
15
12
  def collection_from_contract(address)
16
- collection = @client.call @mirror, 'collections', address
13
+ collection = @rpc.call @mirror, 'collections', address
17
14
  return if collection.zero?
18
15
 
19
16
  MixinBot::Utils::UUID.new(hex: collection.to_fs(16)).unpacked
@@ -21,7 +18,7 @@ module MVM
21
18
 
22
19
  def contract_from_collection(uuid)
23
20
  collection = uuid.to_s.gsub('-', '').to_i(16)
24
- contract = @client.call @mirror, 'contracts', collection
21
+ contract = @rpc.call @mirror, 'contracts', collection
25
22
  address = Eth::Address.new contract
26
23
  return unless address.valid?
27
24
 
@@ -33,7 +30,7 @@ module MVM
33
30
  return if address.blank? || address.to_i(16).zero?
34
31
 
35
32
  contract = Eth::Contract.from_abi name: 'Collectible', address: address, abi: File.open(File.expand_path('./abis/erc721.json', __dir__)).read
36
- owner = @client.call contract, 'ownerOf', token_id.to_i
33
+ owner = @rpc.call contract, 'ownerOf', token_id.to_i
37
34
  address = Eth::Address.new owner
38
35
  return unless address.valid?
39
36
 
@@ -45,7 +42,7 @@ module MVM
45
42
  def token_of_owner_by_index(contract, owner, index)
46
43
  contract = Eth::Contract.from_abi name: 'Collectible', address: contract, abi: File.open(File.expand_path('./abis/erc721.json', __dir__)).read
47
44
 
48
- @client.call contract, 'tokenOfOwnerByIndex', owner, index
45
+ @rpc.call contract, 'tokenOfOwnerByIndex', owner, index
49
46
  rescue IOError
50
47
  nil
51
48
  end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MVM
4
+ class Registry
5
+ attr_reader :rpc, :registry
6
+
7
+ def initialize(rpc_url: MVM::RPC_URL, registry_address: MVM::REGISTRY_ADDRESS)
8
+ @rpc = Eth::Client.create rpc_url
9
+ @registry = Eth::Contract.from_abi name: 'Registry', address: registry_address, abi: File.open(File.expand_path('./abis/registry.json', __dir__)).read
10
+ end
11
+
12
+ def asset(asset_id)
13
+ @rpc.call @registry, 'contracts', asset_id.gsub('-', '').to_i(16)
14
+ end
15
+
16
+ def user(user_id)
17
+ multisig [user_id], 1
18
+ end
19
+
20
+ def multisig(user_ids, threshold)
21
+ bytes = []
22
+ bytes += MixinBot::Utils.encode_int(user_ids.length)
23
+ bytes += [user_ids.sort.join('').gsub('-', '')].pack('H*').bytes
24
+ bytes += MixinBot::Utils.encode_int(threshold)
25
+
26
+ hash = Eth::Util.bin_to_prefixed_hex(Eth::Util.keccak256(bytes.pack('C*')))
27
+ @rpc.call @registry, 'contracts', hash.to_i(16)
28
+ end
29
+ end
30
+ end
data/lib/mvm.rb CHANGED
@@ -7,9 +7,14 @@ require 'eth'
7
7
  require_relative './mvm/bridge'
8
8
  require_relative './mvm/client'
9
9
  require_relative './mvm/nft'
10
+ require_relative './mvm/registry'
10
11
  require_relative './mvm/scan'
11
12
 
12
13
  module MVM
14
+ RPC_URL = 'https://geth.mvm.dev'
15
+ MIRROR_ADDRESS = '0xC193486e6Bf3E8461cb8fcdF178676a5D75c066A'
16
+ REGISTRY_ADDRESS = '0x3c84B6C98FBeB813e05a7A7813F0442883450B1F'
17
+
13
18
  class Error < StandardError; end
14
19
  class HttpError < Error; end
15
20
  class ResponseError < Error; end
@@ -18,11 +23,15 @@ module MVM
18
23
  @bridge ||= MVM::Bridge.new
19
24
  end
20
25
 
21
- def self.nft
22
- @nft ||= MVM::Nft.new
26
+ def self.nft(**params)
27
+ @nft ||= MVM::Nft.new(**params)
23
28
  end
24
29
 
25
30
  def self.scan
26
31
  @scan ||= MVM::Scan.new
27
32
  end
33
+
34
+ def self.registry(**params)
35
+ @registry ||= MVM::Registry.new(**params)
36
+ end
28
37
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mixin_bot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.1
4
+ version: 0.11.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - an-lee
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-10-21 00:00:00.000000000 Z
11
+ date: 2022-11-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -326,6 +326,7 @@ files:
326
326
  - lib/mvm/bridge.rb
327
327
  - lib/mvm/client.rb
328
328
  - lib/mvm/nft.rb
329
+ - lib/mvm/registry.rb
329
330
  - lib/mvm/scan.rb
330
331
  homepage: https://github.com/an-lee/mixin_bot
331
332
  licenses: