Skip to content

Commit

Permalink
merge: branch '3438-well-known' into 'main'
Browse files Browse the repository at this point in the history
Define well-known networks [#3438]

Closes #3438

See merge request accumulatenetwork/accumulate!941
  • Loading branch information
firelizzard18 committed Oct 9, 2023
2 parents 27a00a9 + 5b42225 commit 8930c82
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
36 changes: 35 additions & 1 deletion pkg/accumulate/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@

package accumulate

import "github.com/multiformats/go-multiaddr"
import (
stdurl "net/url"
"strings"

"github.com/multiformats/go-multiaddr"
)

var BootstrapServers = func() []multiaddr.Multiaddr {
s := []string{
Expand All @@ -22,3 +27,32 @@ var BootstrapServers = func() []multiaddr.Multiaddr {
}
return addrs
}()

const MainNetEndpoint = "https://mainnet.accumulatenetwork.io"
const KermitEndpoint = "https://kermit.accumulatenetwork.io"
const FozzieEndpoint = "https://fozzie.accumulatenetwork.io"

var WellKnownNetworks = map[string]string{
"mainnet": MainNetEndpoint,
"kermit": KermitEndpoint,
"fozzie": FozzieEndpoint,

"testnet": "https://kermit.accumulatenetwork.io",
"local": "http://127.0.1.1:26660",
}

func ResolveWellKnownEndpoint(name string, version string) string {
addr, ok := WellKnownNetworks[strings.ToLower(name)]
if !ok {
addr = name
}

u, err := stdurl.Parse(addr)
if err != nil {
return addr
}
if u.Path == "" {
addr += "/"
}
return addr + version
}
25 changes: 25 additions & 0 deletions pkg/accumulate/api_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright 2023 The Accumulate Authors
//
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.

package accumulate

import (
"testing"

"github.com/stretchr/testify/require"
)

func TestResolveWellKnownEndpoint(t *testing.T) {
cases := map[string]string{
"mainnet": "https://mainnet.accumulatenetwork.io/v3",
"https://mainnet.accumulatenetwork.io": "https://mainnet.accumulatenetwork.io/v3",
}

for input, expect := range cases {
actual := ResolveWellKnownEndpoint(input, "v3")
require.Equal(t, expect, actual)
}
}

0 comments on commit 8930c82

Please sign in to comment.