File tree Expand file tree Collapse file tree 2 files changed +24
-2
lines changed
Expand file tree Collapse file tree 2 files changed +24
-2
lines changed Original file line number Diff line number Diff line change @@ -164,9 +164,19 @@ public byte[] data(MerkleNode merkleObject) throws IOException {
164164 }
165165
166166 class Name {
167- // TODO publish
167+ public Map publish (MerkleNode node ) throws IOException {
168+ return publish (Optional .empty (), node );
169+ }
168170
169- // TODO resolve
171+ public Map publish (Optional <String > id , MerkleNode node ) throws IOException {
172+ Map res = (Map ) retrieveAndParse ("name/publish?arg=" + (id .isPresent () ? id +"&arg=" : "" ) + "/ipfs/" +node .hash );
173+ return res ;
174+ }
175+
176+ public String resolve (String addr ) throws IOException {
177+ Map res = (Map ) retrieveAndParse ("name/resolve?arg=" + addr );
178+ return (String )res .get ("Path" );
179+ }
170180 }
171181
172182 class DHT {
Original file line number Diff line number Diff line change @@ -96,6 +96,18 @@ public void fileTest() {
9696 }
9797 }
9898
99+ @ org .junit .Test
100+ public void nameTest () {
101+ try {
102+ MerkleNode pointer = new MerkleNode ("QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB" );
103+ Map pub = ipfs .name .publish (pointer );
104+ String resolved = ipfs .name .resolve ((String )pub .get ("Name" ));
105+ System .out .println (resolved );
106+ } catch (IOException e ) {
107+ throw new RuntimeException (e );
108+ }
109+ }
110+
99111 @ org .junit .Test
100112 public void dnsTest () {
101113 try {
You can’t perform that action at this time.
0 commit comments