Skip to content
This repository has been archived by the owner on Aug 2, 2021. It is now read-only.

Add unfiltered chunk retrieval API #1955

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions direct.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package swarm

import (
"context"

"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethersphere/swarm/chunk"
"github.com/ethersphere/swarm/storage"
)

type directAccessAPI struct {
chunkStore storage.ChunkStore
}

func NewDirectAccessAPI(chunkStore storage.ChunkStore) *directAccessAPI {
return &directAccessAPI{
chunkStore: chunkStore,
}
}

func (d *directAccessAPI) GetByReference(addr storage.Address) (hexutil.Bytes, error) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
chunk, err := d.chunkStore.Get(ctx, chunk.ModeGetRequest, addr)
if err != nil {
return nil, err
}
return hexutil.Bytes(chunk.Data()), nil
}
11 changes: 9 additions & 2 deletions swarm.go
Original file line number Diff line number Diff line change
Expand Up @@ -559,14 +559,14 @@ func (s *Swarm) APIs() []rpc.API {
// public APIs
{
Namespace: "bzz",
Version: "4.0",
Version: "4.1",
Service: &Info{s.config},
Public: true,
},
// admin APIs
{
Namespace: "bzz",
Version: "4.0",
Version: "4.1",
Service: s.inspector,
Public: false,
},
Expand All @@ -582,6 +582,13 @@ func (s *Swarm) APIs() []rpc.API {
Service: protocols.NewAccountingApi(s.accountingMetrics),
Public: false,
},
{

Namespace: "bzz",
Version: "4.1",
Service: NewDirectAccessAPI(storage.NewLNetStore(s.netStore)),
Public: true,
},
}

apis = append(apis, s.bzz.APIs()...)
Expand Down