diff --git a/direct.go b/direct.go new file mode 100644 index 0000000000..85fc21807d --- /dev/null +++ b/direct.go @@ -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 +} diff --git a/swarm.go b/swarm.go index 0f98387795..862710e4f2 100644 --- a/swarm.go +++ b/swarm.go @@ -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, }, @@ -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()...)