Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-merkledag
Commits
55f6c9ab
Commit
55f6c9ab
authored
Jul 05, 2014
by
Juan Batiz-Benet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
abstracted merkledag service
parent
eb9b75fb
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
40 additions
and
0 deletions
+40
-0
merkledag.go
merkledag.go
+40
-0
No files found.
merkledag.go
View file @
55f6c9ab
package
merkledag
package
merkledag
import
(
import
(
"fmt"
blocks
"github.com/jbenet/go-ipfs/blocks"
u
"github.com/jbenet/go-ipfs/util"
u
"github.com/jbenet/go-ipfs/util"
mh
"github.com/jbenet/go-multihash"
mh
"github.com/jbenet/go-multihash"
)
)
...
@@ -79,3 +81,41 @@ func (n *Node) Key() (u.Key, error) {
...
@@ -79,3 +81,41 @@ func (n *Node) Key() (u.Key, error) {
h
,
err
:=
n
.
Multihash
()
h
,
err
:=
n
.
Multihash
()
return
u
.
Key
(
h
),
err
return
u
.
Key
(
h
),
err
}
}
// An IPFS Merkle DAG service.
// the root is virtual (like a forest)
// stores nodes' data in a blockService
type
DAGService
struct
{
Blocks
*
blocks
.
BlockService
}
func
(
n
*
DAGService
)
Put
(
nd
*
Node
)
(
u
.
Key
,
error
)
{
if
n
==
nil
{
return
""
,
fmt
.
Errorf
(
"DAGService is nil"
)
}
d
,
err
:=
nd
.
Encoded
(
false
)
if
err
!=
nil
{
return
""
,
err
}
b
,
err
:=
blocks
.
NewBlock
(
d
)
if
err
!=
nil
{
return
""
,
err
}
return
n
.
Blocks
.
AddBlock
(
b
)
}
func
(
n
*
DAGService
)
Get
(
k
u
.
Key
)
(
*
Node
,
error
)
{
if
n
==
nil
{
return
nil
,
fmt
.
Errorf
(
"DAGService is nil"
)
}
b
,
err
:=
n
.
Blocks
.
GetBlock
(
k
)
if
err
!=
nil
{
return
nil
,
err
}
return
Decoded
(
b
.
Data
)
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment