Skip to content

Commit

Permalink
Disable old prefix address compatibility. (#787)
Browse files Browse the repository at this point in the history
* Disable old prefix address compatibility.
  • Loading branch information
skyargos authored Nov 16, 2023
1 parent 9e47c55 commit 11baca2
Show file tree
Hide file tree
Showing 8 changed files with 5 additions and 907 deletions.
248 changes: 0 additions & 248 deletions app/upgrade_handler_test.go

This file was deleted.

18 changes: 0 additions & 18 deletions common/prefix.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,6 @@ const (
Bech32PrefixConsPub = Bech32MainPrefix + sdk.PrefixValidator + sdk.PrefixConsensus + sdk.PrefixPublic
)

// PrefixToCertik convert shentu prefix address to certik prefix address
func PrefixToCertik(address string) (string, error) {
hrp, data, err := bech32.DecodeAndConvert(address)
if err != nil {
return "", err
}
if !strings.HasPrefix(hrp, "shentu") {
return "", fmt.Errorf("invalid address:%s", address)
}

newhrp := strings.Replace(hrp, "shentu", "certik", 1)
certikAddr, err := bech32.ConvertAndEncode(newhrp, data)
if err != nil {
return "", err
}
return certikAddr, nil
}

// PrefixToShentu convert certik prefix address to shentu prefix address
func PrefixToShentu(address string) (string, error) {
hrp, data, err := bech32.DecodeAndConvert(address)
Expand Down
22 changes: 3 additions & 19 deletions common/prefix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,14 @@ package common

import (
"crypto/sha256"
"github.com/stretchr/testify/require"
"strings"
"testing"

"github.com/stretchr/testify/require"

"github.com/cosmos/cosmos-sdk/types/bech32"
)

func TestPrefixToCertik(t *testing.T) {
sum := sha256.Sum256([]byte("hello world\n"))
ss := "shentu"

address, err := bech32.ConvertAndEncode(ss, sum[:])
require.NoError(t, err)

certikAddr, err := PrefixToCertik(address)
require.NoError(t, err)
require.True(t, strings.HasPrefix(certikAddr, "certik"))

address, err = bech32.ConvertAndEncode("certik", sum[:])
require.NoError(t, err)
_, err = PrefixToCertik(address)
require.Error(t, err)
}

func TestPrefixToShentu(t *testing.T) {
sum := sha256.Sum256([]byte("hello world\n"))
ss := "certik"
Expand All @@ -40,5 +24,5 @@ func TestPrefixToShentu(t *testing.T) {
address, err = bech32.ConvertAndEncode("shentu", sum[:])
require.NoError(t, err)
_, err = PrefixToShentu(address)
require.Error(t, err)
require.NoError(t, err)
}
2 changes: 0 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -304,5 +304,3 @@ require (
replace google.golang.org/grpc => google.golang.org/grpc v1.33.2

replace github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.2-alpha.regen.4

replace github.com/cosmos/cosmos-sdk => github.com/shentufoundation/cosmos-sdk v0.45.11-3
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,8 @@ github.com/cosmos/btcutil v1.0.4 h1:n7C2ngKXo7UC9gNyMNLbzqz7Asuf+7Qv4gnX/rOdQ44=
github.com/cosmos/btcutil v1.0.4/go.mod h1:Ffqc8Hn6TJUdDgHBwIZLtrLQC1KdJ9jGJl/TvgUaxbU=
github.com/cosmos/cosmos-proto v1.0.0-beta.3 h1:VitvZ1lPORTVxkmF2fAp3IiA61xVwArQYKXTdEcpW6o=
github.com/cosmos/cosmos-proto v1.0.0-beta.3/go.mod h1:t8IASdLaAq+bbHbjq4p960BvcTqtwuAxid3b/2rOD6I=
github.com/cosmos/cosmos-sdk v0.45.11 h1:Pc44fFEkai0KXFND5Ys/2ZJkfVdstMIBzKBN8MY7Ll0=
github.com/cosmos/cosmos-sdk v0.45.11/go.mod h1:45z8Q1Ah4iypFycu2Kl4kBPIsQKUiND8G2CUX+HTtPM=
github.com/cosmos/go-bip39 v0.0.0-20180819234021-555e2067c45d/go.mod h1:tSxLoYXyBmiFeKpvmq4dzayMdCjCnu8uqmCysIGBT2Y=
github.com/cosmos/go-bip39 v1.0.0 h1:pcomnQdrdH22njcAatO0yWojsUnCO3y2tNoV1cb6hHY=
github.com/cosmos/go-bip39 v1.0.0/go.mod h1:RNJv0H/pOIVgxw6KS7QeX2a0Uo0aKUlfhZ4xuwvCdJw=
Expand Down Expand Up @@ -1055,8 +1057,6 @@ github.com/securego/gosec/v2 v2.13.1/go.mod h1:EO1sImBMBWFjOTFzMWfTRrZW6M15gm60l
github.com/segmentio/fasthash v1.0.3/go.mod h1:waKX8l2N8yckOgmSsXJi7x1ZfdKZ4x7KRMzBtS3oedY=
github.com/shazow/go-diff v0.0.0-20160112020656-b6b7b6733b8c h1:W65qqJCIOVP4jpqPQ0YvHYKwcMEMVWIzWC5iNQQfBTU=
github.com/shazow/go-diff v0.0.0-20160112020656-b6b7b6733b8c/go.mod h1:/PevMnwAxekIXwN8qQyfc5gl2NlkB3CQlkizAbOkeBs=
github.com/shentufoundation/cosmos-sdk v0.45.11-3 h1:c3x/2g02HVE36OkHCC7WHqxEvvdZaeMrPTXYTiqQDew=
github.com/shentufoundation/cosmos-sdk v0.45.11-3/go.mod h1:45z8Q1Ah4iypFycu2Kl4kBPIsQKUiND8G2CUX+HTtPM=
github.com/shirou/gopsutil v2.20.5+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
github.com/shurcooL/go v0.0.0-20180423040247-9e1955d9fb6e/go.mod h1:TDJrrUr11Vxrven61rcy3hJMUqaf/CLWYhHNPmT14Lk=
github.com/shurcooL/go-goon v0.0.0-20170922171312-37c2f522c041/go.mod h1:N5mDOmsrJOB+vfqUK+7DmDyjhSLIIBnXo9lvZJj3MWQ=
Expand Down
Loading

0 comments on commit 11baca2

Please sign in to comment.