ethname 0.0.1 → 0.1.0

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: 450342f14ab626b337ad859811381f4185a11cfd805a887fb628be35427c6549
4
- data.tar.gz: 45b92de48f56083fad1e94975f1dfb58f7afeb4d64ee55a12650104ae87372af
3
+ metadata.gz: d4bca434fb0e9fdb4a5e75a8a8443585807d65400beef3049d67c2ed5ffd64f1
4
+ data.tar.gz: 61c6160602bb7f6c58e3e55633912db2db2e3e75538f9c033b10d0fd90d2b6fc
5
5
  SHA512:
6
- metadata.gz: 6e37ff7f85701c927c9f5fb8f78b8174b003f7a521f1e6d705c565f919f1d437d5b467ac044484379a45be52669de8cb427b45cf4f3c02b31c75fa313c1eddbc
7
- data.tar.gz: 0bcee46cf8ebb0b33de5e85c9ce93e7fc9b1dd33a40a6a771b92d99943362ef4758db0d9a022d838bdcbfdc127c8ce9fc33ab4e81233aff0ed7c43f50e0755bc
6
+ metadata.gz: 2e8e88f82a46551e92de34d39dd14711bacd3ad991b86389f5e96a2b8d4644301ea5890f60c2911cc95025c3666ece3c319888f8b2b1ea9bfb61f4806942d42c
7
+ data.tar.gz: 70b895437d14b8da3bd68622781b9400429defbdc5d9429e5f97b85227948ecdd1e550321f9431a3c92758bd63c63730af3dc8fde00c01b7cf7715836cbcd8c4
data/Manifest.txt CHANGED
@@ -6,5 +6,5 @@ config/contracts.2017.csv
6
6
  config/contracts.2021.csv
7
7
  config/contracts.2022.csv
8
8
  lib/ethname.rb
9
- lib/ethname/dictionary.rb
9
+ lib/ethname/directory.rb
10
10
  lib/ethname/version.rb
@@ -1,6 +1,6 @@
1
- address, names
2
- 0x6Ba6f2207e343923BA692e5Cae646Fb0F566DB8D, punks v1 | crypto punks v1
3
- 0xb47e3cd837ddf8e4c57f05d70ab865de6e193bbb, punks v2 | crypto punks v2 | crypto punks market
4
- 0x60cd862c9c687a9de49aecdc3a99b74a4fc54ab6, mooncats | mooncatrescue
1
+ address, names, interfaces
2
+ 0x6Ba6f2207e343923BA692e5Cae646Fb0F566DB8D, punks v1 | crypto punks v1, erc20
3
+ 0xb47e3cd837ddf8e4c57f05d70ab865de6e193bbb, punks v2 | crypto punks v2 | crypto punks market, erc20
4
+ 0x60cd862c9c687a9de49aecdc3a99b74a4fc54ab6, mooncats | mooncatrescue,
5
5
 
6
6
 
@@ -1,11 +1,11 @@
1
- address, names
2
- 0x16f5a35647d6f03d5d3da7b35409d65ba03af3b2, punks data | crypto punks data
3
- 0xf4a4644e818c2843ba0aabea93af6c80b5984114, punks v1 wrapped i | classic punks
1
+ address, names, interfaces
2
+ 0x16f5a35647d6f03d5d3da7b35409d65ba03af3b2, punks data | crypto punks data,
3
+ 0xf4a4644e818c2843ba0aabea93af6c80b5984114, punks v1 wrapped i | classic punks, erc721
4
4
 
5
- 0xa82f3a61f002f83eba7d184c50bb2a8b359ca1ce, phunks v1 | philips
6
- 0xf07468ead8cf26c752c676e43c814fee9c8cf402, phunks v2 | phunks
5
+ 0xa82f3a61f002f83eba7d184c50bb2a8b359ca1ce, phunks v1 | philips, erc721
6
+ 0xf07468ead8cf26c752c676e43c814fee9c8cf402, phunks v2 | phunks, erc721
7
7
 
8
- 0x031920cc2d9f5c10b444fd44009cd64f829e7be2, zunks
8
+ 0x031920cc2d9f5c10b444fd44009cd64f829e7be2, zunks, erc721
9
9
 
10
- 0x0d0167a823c6619d430b1a96ad85b888bcf97c37, xpunks | expansion punks
11
- 0x71eb5c179ceb640160853144cbb8df5bd24ab5cc, xphunks | expansion phunks
10
+ 0x0d0167a823c6619d430b1a96ad85b888bcf97c37, xpunks | expansion punks, erc721
11
+ 0x71eb5c179ceb640160853144cbb8df5bd24ab5cc, xphunks | expansion phunks, erc721
@@ -1,15 +1,15 @@
1
- address, names
2
- 0x282bdd42f4eb70e7a9d9f40c8fea0825b7f68c5d, punks v1 wrapped ii
1
+ address, names, interfaces
2
+ 0x282bdd42f4eb70e7a9d9f40c8fea0825b7f68c5d, punks v1 wrapped ii, erc721
3
3
 
4
- 0xD33c078C2486B7Be0F7B4DDa9B14F35163B949e0, punks v3
5
- 0xd12882c8b5d1bccca57c994c6af7d96355590dbd, punks v4
4
+ 0xD33c078C2486B7Be0F7B4DDa9B14F35163B949e0, punks v3, erc721
5
+ 0xd12882c8b5d1bccca57c994c6af7d96355590dbd, punks v4, erc721
6
6
 
7
- 0xA19f0378A6F3f3361d8e962F3589Ec28f4f8F159, phunks v3
7
+ 0xA19f0378A6F3f3361d8e962F3589Ec28f4f8F159, phunks v3, erc721
8
8
 
9
9
 
10
- 0xaf9CE4B327A3b690ABEA6F78eCCBfeFFfbEa9FDf, synthetic punks | synth punks
10
+ 0xaf9CE4B327A3b690ABEA6F78eCCBfeFFfbEa9FDf, synthetic punks | synth punks, erc721
11
11
 
12
- 0x58E90596C2065BEfD3060767736C829C18F3474c, punk blocks
12
+ 0x58E90596C2065BEfD3060767736C829C18F3474c, punk blocks,
13
13
 
14
14
 
15
- 0x23581767a106ae21c074b2276D25e5C3e136a68b, moonbirds
15
+ 0x23581767a106ae21c074b2276D25e5C3e136a68b, moonbirds, erc721
@@ -0,0 +1,121 @@
1
+
2
+ module Ethname
3
+
4
+ class Record
5
+ def self.directory() Ethname.directory; end
6
+
7
+ def self.find( addr ) directory.find_record( addr ); end
8
+ def self.find_by( name: ) directory.find_record_by( name: name ); end
9
+
10
+
11
+
12
+ def self.parse( row )
13
+ ## note: always downcase addresses for now
14
+ ## (do NOT use addresss checksum with mixed-hexchars) - why? why not?
15
+ address = row['address'].downcase
16
+
17
+ names = row['names'].split('|')
18
+ names = names.map {|name| name.strip } ## remove leading & trailing withespaces
19
+
20
+ ## note: always downcase and normalize (remove space and - for now)
21
+ # - why? why not?
22
+ ## e.g. ERC20 => erc20
23
+ ## ERC-20 | ERC-721 => erc20 | erc721
24
+ interfaces = (row['interfaces'] || '').split('|')
25
+ interfaces = interfaces.map {|inter| inter.downcase.gsub(/[ -]/, '' ) }
26
+
27
+ new( address: address,
28
+ names: names,
29
+ interfaces: interfaces )
30
+ end
31
+
32
+
33
+ attr_reader :address, :names, :interfaces
34
+
35
+ def initialize( address: nil,
36
+ names: [],
37
+ interfaces: [] )
38
+ @address = address
39
+ @names = names
40
+ @interfaces = interfaces
41
+ end
42
+
43
+ alias_method :addr, :address
44
+ def name() @names[0]; end
45
+
46
+ def erc20?() @interfaces.include?('erc20' ); end
47
+ def erc721?() @interfaces.include?('erc721' ); end
48
+
49
+
50
+ end # class Record
51
+
52
+
53
+
54
+ class Directory
55
+ ## let's you lookup up ethereum addresses by name
56
+
57
+ def self.read( *paths ) ## use load - why? why not?
58
+ dir = new
59
+ paths.each do |path|
60
+ rows= read_csv( path )
61
+ dir.add_rows( rows )
62
+ end
63
+ dir
64
+ end
65
+
66
+
67
+
68
+ def initialize
69
+ @recs = {} ## lookup (record) by (normalized) address
70
+ @reverse_table = {} ## lookup (address) by (normalized) name
71
+ end
72
+
73
+
74
+ def records() @recs.values; end
75
+ def size() @recs.size; end
76
+
77
+ def find_record( addr )
78
+ @recs[ addr.downcase ]
79
+ end
80
+
81
+ def find_record_by( name: )
82
+ key = normalize( name )
83
+ @reverse_table[ key ]
84
+ end
85
+
86
+
87
+ def []( name )
88
+ rec = find_record_by( name: name )
89
+ rec ? rec.addr : nil
90
+ end
91
+
92
+
93
+ def add_rows( rows )
94
+ rows.each do |row|
95
+ rec = Record.parse( row )
96
+ rec.names.each do |name|
97
+
98
+ key = normalize( name )
99
+ rec2 = @reverse_table[ key ]
100
+
101
+ ## check for duplicates
102
+ raise ArgumentError, "duplicate (normalized) key >#{key} for addr >#{rec.addr}<" if rec == rec2
103
+ raise ArgumentError, "duplicate (normalized) key >#{key}< for addr >#{rec.addr}; addr already in use >#{rec2.addr}<" if rec2
104
+ @reverse_table[ key ] = rec
105
+ end
106
+
107
+ @recs[rec.addr] = rec
108
+ end
109
+ end
110
+
111
+ #################
112
+ # convencience helpers
113
+ def self.normalize( str )
114
+ ## remove all non a-z (and 0-9) characters
115
+ str.downcase.gsub( /[^a-z0-9]/i, '' )
116
+ end
117
+
118
+ def normalize( str ) self.class.normalize( str ); end
119
+ end # class Directory
120
+ end # module Ethname
121
+
@@ -2,8 +2,8 @@
2
2
 
3
3
  module Ethname
4
4
  MAJOR = 0
5
- MINOR = 0
6
- PATCH = 1
5
+ MINOR = 1
6
+ PATCH = 0
7
7
  VERSION = [MAJOR,MINOR,PATCH].join('.')
8
8
 
9
9
  def self.version
data/lib/ethname.rb CHANGED
@@ -4,23 +4,23 @@ require 'cocos'
4
4
 
5
5
  ## our own code
6
6
  require_relative 'ethname/version'
7
- require_relative 'ethname/dictionary'
7
+ require_relative 'ethname/directory'
8
8
 
9
9
 
10
10
  module Ethname
11
11
 
12
- def self.dict
13
- @dict ||= Dictionary.read( "#{root}/config/contracts.2017.csv",
14
- "#{root}/config/contracts.2021.csv",
15
- "#{root}/config/contracts.2022.csv",
12
+ def self.dir
13
+ @dir ||= Directory.read( "#{root}/config/contracts.2017.csv",
14
+ "#{root}/config/contracts.2021.csv",
15
+ "#{root}/config/contracts.2022.csv",
16
16
  )
17
17
  end
18
-
19
- def self.lookup( q )
20
- dict.lookup( q )
21
- end
22
18
  class << self
23
- alias_method :[], :lookup
19
+ alias_method :directory, :dir
20
+ end
21
+
22
+ def self.[]( q )
23
+ dir[ q ]
24
24
  end
25
25
 
26
26
  end # module Ethname
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ethname
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gerald Bauer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-12-16 00:00:00.000000000 Z
11
+ date: 2022-12-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cocos
@@ -77,7 +77,7 @@ files:
77
77
  - config/contracts.2021.csv
78
78
  - config/contracts.2022.csv
79
79
  - lib/ethname.rb
80
- - lib/ethname/dictionary.rb
80
+ - lib/ethname/directory.rb
81
81
  - lib/ethname/version.rb
82
82
  homepage: https://github.com/rubycocos/blockchain
83
83
  licenses:
@@ -1,75 +0,0 @@
1
-
2
- module Ethname
3
-
4
- class Dictionary
5
- ## let's you lookup up ethereum addresses by name
6
-
7
- def self.read( *paths ) ## use load - why? why not?
8
- dict = new
9
- paths.each do |path|
10
- recs = read_csv( path )
11
- dict.add_recs( recs )
12
- end
13
- dict
14
- end
15
-
16
-
17
-
18
- def initialize
19
- @recs = []
20
- @reverse_table = {} ## lookup (address) by (normalized) name
21
- end
22
-
23
- def recs() @recs; end
24
- def size() @recs.size; end
25
-
26
-
27
-
28
- def lookup( q )
29
- key = normalize( q )
30
- addr = @reverse_table[ key ]
31
- addr
32
- end
33
- alias_method :[], :lookup
34
-
35
-
36
- def add_recs( recs )
37
- recs.each do |rec|
38
- ## note: always downcase addresses for now
39
- ## (do NOT use addresss checksum with mixed-hexchars) - why? why not?
40
- addr = rec['address'].downcase
41
- names = rec['names'].split('|')
42
- names.each do |name|
43
- _add( addr, name )
44
- end
45
- end
46
-
47
- @recs += recs
48
- end
49
-
50
-
51
- #################
52
- # convencience helpers
53
- def self.normalize( str )
54
- ## remove all non a-z (and 0-9) characters
55
- str.downcase.gsub( /[^a-z0-9]/i, '' )
56
- end
57
-
58
- def normalize( str ) self.class.normalize( str ); end
59
-
60
- ####
61
- # private (internal) helpers
62
- def _add( addr, name )
63
- key = normalize( name )
64
- addr2 = @reverse_table[ key ]
65
-
66
- ## check for duplicates
67
- raise ArgumentError, "duplicate (normalized) key >#{key} for addr >#{addr}<" if addr == addr2
68
- raise ArgumentError, "duplicate (normalized) key >#{key}< for addr >#{addr}; addr already in use >#{addr2}<" if addr2
69
- @reverse_table[ key ] = addr
70
- self
71
- end
72
-
73
- end
74
- end # module Ethname
75
-