Commit ce425318 authored by Ralph Pichler's avatar Ralph Pichler Committed by GitHub

add ethereum address to /addresses (#771)

parent fbe2a596
...@@ -28,6 +28,8 @@ components: ...@@ -28,6 +28,8 @@ components:
type: array type: array
items: items:
$ref: '#/components/schemas/P2PUnderlay' $ref: '#/components/schemas/P2PUnderlay'
ethereum:
$ref: '#/components/schemas/EthereumAddress'
public_key: public_key:
$ref: '#/components/schemas/PublicKey' $ref: '#/components/schemas/PublicKey'
......
...@@ -8,6 +8,7 @@ import ( ...@@ -8,6 +8,7 @@ import (
"crypto/ecdsa" "crypto/ecdsa"
"net/http" "net/http"
"github.com/ethereum/go-ethereum/common"
"github.com/ethersphere/bee/pkg/accounting" "github.com/ethersphere/bee/pkg/accounting"
"github.com/ethersphere/bee/pkg/logging" "github.com/ethersphere/bee/pkg/logging"
"github.com/ethersphere/bee/pkg/p2p" "github.com/ethersphere/bee/pkg/p2p"
...@@ -31,6 +32,7 @@ type Service interface { ...@@ -31,6 +32,7 @@ type Service interface {
type server struct { type server struct {
Overlay swarm.Address Overlay swarm.Address
PublicKey ecdsa.PublicKey PublicKey ecdsa.PublicKey
EthereumAddress common.Address
P2P p2p.DebugService P2P p2p.DebugService
Pingpong pingpong.Interface Pingpong pingpong.Interface
TopologyDriver topology.Driver TopologyDriver topology.Driver
...@@ -47,10 +49,11 @@ type server struct { ...@@ -47,10 +49,11 @@ type server struct {
http.Handler http.Handler
} }
func New(overlay swarm.Address, publicKey ecdsa.PublicKey, p2p p2p.DebugService, pingpong pingpong.Interface, topologyDriver topology.Driver, storer storage.Storer, logger logging.Logger, tracer *tracing.Tracer, tags *tags.Tags, accounting accounting.Interface, settlement settlement.Interface, chequebookEnabled bool, swap swap.ApiInterface, chequebook chequebook.Service) Service { func New(overlay swarm.Address, publicKey ecdsa.PublicKey, ethereumAddress common.Address, p2p p2p.DebugService, pingpong pingpong.Interface, topologyDriver topology.Driver, storer storage.Storer, logger logging.Logger, tracer *tracing.Tracer, tags *tags.Tags, accounting accounting.Interface, settlement settlement.Interface, chequebookEnabled bool, swap swap.ApiInterface, chequebook chequebook.Service) Service {
s := &server{ s := &server{
Overlay: overlay, Overlay: overlay,
PublicKey: publicKey, PublicKey: publicKey,
EthereumAddress: ethereumAddress,
P2P: p2p, P2P: p2p,
Pingpong: pingpong, Pingpong: pingpong,
TopologyDriver: topologyDriver, TopologyDriver: topologyDriver,
......
...@@ -12,6 +12,7 @@ import ( ...@@ -12,6 +12,7 @@ import (
"net/url" "net/url"
"testing" "testing"
"github.com/ethereum/go-ethereum/common"
accountingmock "github.com/ethersphere/bee/pkg/accounting/mock" accountingmock "github.com/ethersphere/bee/pkg/accounting/mock"
"github.com/ethersphere/bee/pkg/debugapi" "github.com/ethersphere/bee/pkg/debugapi"
"github.com/ethersphere/bee/pkg/logging" "github.com/ethersphere/bee/pkg/logging"
...@@ -30,18 +31,19 @@ import ( ...@@ -30,18 +31,19 @@ import (
) )
type testServerOptions struct { type testServerOptions struct {
Overlay swarm.Address Overlay swarm.Address
PublicKey ecdsa.PublicKey PublicKey ecdsa.PublicKey
P2P *p2pmock.Service EthereumAddress common.Address
Pingpong pingpong.Interface P2P *p2pmock.Service
Storer storage.Storer Pingpong pingpong.Interface
Resolver resolver.Interface Storer storage.Storer
TopologyOpts []topologymock.Option Resolver resolver.Interface
Tags *tags.Tags TopologyOpts []topologymock.Option
AccountingOpts []accountingmock.Option Tags *tags.Tags
SettlementOpts []settlementmock.Option AccountingOpts []accountingmock.Option
ChequebookOpts []chequebookmock.Option SettlementOpts []settlementmock.Option
SwapOpts []swapmock.Option ChequebookOpts []chequebookmock.Option
SwapOpts []swapmock.Option
} }
type testServer struct { type testServer struct {
...@@ -55,7 +57,7 @@ func newTestServer(t *testing.T, o testServerOptions) *testServer { ...@@ -55,7 +57,7 @@ func newTestServer(t *testing.T, o testServerOptions) *testServer {
settlement := settlementmock.NewSettlement(o.SettlementOpts...) settlement := settlementmock.NewSettlement(o.SettlementOpts...)
chequebook := chequebookmock.NewChequebook(o.ChequebookOpts...) chequebook := chequebookmock.NewChequebook(o.ChequebookOpts...)
swapserv := swapmock.NewApiInterface(o.SwapOpts...) swapserv := swapmock.NewApiInterface(o.SwapOpts...)
s := debugapi.New(o.Overlay, o.PublicKey, o.P2P, o.Pingpong, topologyDriver, o.Storer, logging.New(ioutil.Discard, 0), nil, o.Tags, acc, settlement, true, swapserv, chequebook) s := debugapi.New(o.Overlay, o.PublicKey, o.EthereumAddress, o.P2P, o.Pingpong, topologyDriver, o.Storer, logging.New(ioutil.Discard, 0), nil, o.Tags, acc, settlement, true, swapserv, chequebook)
ts := httptest.NewServer(s) ts := httptest.NewServer(s)
t.Cleanup(ts.Close) t.Cleanup(ts.Close)
......
...@@ -8,6 +8,7 @@ import ( ...@@ -8,6 +8,7 @@ import (
"encoding/hex" "encoding/hex"
"net/http" "net/http"
"github.com/ethereum/go-ethereum/common"
"github.com/ethersphere/bee/pkg/crypto" "github.com/ethersphere/bee/pkg/crypto"
"github.com/ethersphere/bee/pkg/jsonhttp" "github.com/ethersphere/bee/pkg/jsonhttp"
"github.com/ethersphere/bee/pkg/swarm" "github.com/ethersphere/bee/pkg/swarm"
...@@ -17,6 +18,7 @@ import ( ...@@ -17,6 +18,7 @@ import (
type addressesResponse struct { type addressesResponse struct {
Overlay swarm.Address `json:"overlay"` Overlay swarm.Address `json:"overlay"`
Underlay []multiaddr.Multiaddr `json:"underlay"` Underlay []multiaddr.Multiaddr `json:"underlay"`
Ethereum common.Address `json:"ethereum"`
PublicKey string `json:"public_key"` PublicKey string `json:"public_key"`
} }
...@@ -30,6 +32,7 @@ func (s *server) addressesHandler(w http.ResponseWriter, r *http.Request) { ...@@ -30,6 +32,7 @@ func (s *server) addressesHandler(w http.ResponseWriter, r *http.Request) {
jsonhttp.OK(w, addressesResponse{ jsonhttp.OK(w, addressesResponse{
Overlay: s.Overlay, Overlay: s.Overlay,
Underlay: underlay, Underlay: underlay,
Ethereum: s.EthereumAddress,
PublicKey: hex.EncodeToString(crypto.EncodeSecp256k1PublicKey(&s.PublicKey)), PublicKey: hex.EncodeToString(crypto.EncodeSecp256k1PublicKey(&s.PublicKey)),
}) })
} }
...@@ -10,6 +10,7 @@ import ( ...@@ -10,6 +10,7 @@ import (
"net/http" "net/http"
"testing" "testing"
"github.com/ethereum/go-ethereum/common"
"github.com/ethersphere/bee/pkg/crypto" "github.com/ethersphere/bee/pkg/crypto"
"github.com/ethersphere/bee/pkg/debugapi" "github.com/ethersphere/bee/pkg/debugapi"
"github.com/ethersphere/bee/pkg/jsonhttp" "github.com/ethersphere/bee/pkg/jsonhttp"
...@@ -31,9 +32,12 @@ func TestAddresses(t *testing.T) { ...@@ -31,9 +32,12 @@ func TestAddresses(t *testing.T) {
mustMultiaddr(t, "/ip4/127.0.0.1/udp/7071/quic/p2p/16Uiu2HAmTBuJT9LvNmBiQiNoTsxE5mtNy6YG3paw79m94CRa9sRb"), mustMultiaddr(t, "/ip4/127.0.0.1/udp/7071/quic/p2p/16Uiu2HAmTBuJT9LvNmBiQiNoTsxE5mtNy6YG3paw79m94CRa9sRb"),
} }
ethereumAddress := common.HexToAddress("abcd")
testServer := newTestServer(t, testServerOptions{ testServer := newTestServer(t, testServerOptions{
PublicKey: privateKey.PublicKey, PublicKey: privateKey.PublicKey,
Overlay: overlay, Overlay: overlay,
EthereumAddress: ethereumAddress,
P2P: mock.New(mock.WithAddressesFunc(func() ([]multiaddr.Multiaddr, error) { P2P: mock.New(mock.WithAddressesFunc(func() ([]multiaddr.Multiaddr, error) {
return addresses, nil return addresses, nil
})), })),
...@@ -45,6 +49,7 @@ func TestAddresses(t *testing.T) { ...@@ -45,6 +49,7 @@ func TestAddresses(t *testing.T) {
Overlay: overlay, Overlay: overlay,
Underlay: addresses, Underlay: addresses,
PublicKey: hex.EncodeToString(crypto.EncodeSecp256k1PublicKey(&privateKey.PublicKey)), PublicKey: hex.EncodeToString(crypto.EncodeSecp256k1PublicKey(&privateKey.PublicKey)),
Ethereum: ethereumAddress,
}), }),
) )
}) })
......
...@@ -439,7 +439,7 @@ func NewBee(addr string, swarmAddress swarm.Address, publicKey ecdsa.PublicKey, ...@@ -439,7 +439,7 @@ func NewBee(addr string, swarmAddress swarm.Address, publicKey ecdsa.PublicKey,
if o.DebugAPIAddr != "" { if o.DebugAPIAddr != "" {
// Debug API server // Debug API server
debugAPIService := debugapi.New(swarmAddress, publicKey, p2ps, pingPong, kad, storer, logger, tracer, tagg, acc, settlement, o.SwapEnable, swapService, chequebookService) debugAPIService := debugapi.New(swarmAddress, publicKey, overlayEthAddress, p2ps, pingPong, kad, storer, logger, tracer, tagg, acc, settlement, o.SwapEnable, swapService, chequebookService)
// register metrics from components // register metrics from components
debugAPIService.MustRegisterMetrics(p2ps.Metrics()...) debugAPIService.MustRegisterMetrics(p2ps.Metrics()...)
debugAPIService.MustRegisterMetrics(pingPong.Metrics()...) debugAPIService.MustRegisterMetrics(pingPong.Metrics()...)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment