Skip to content
This repository has been archived by the owner on Oct 24, 2024. It is now read-only.

Commit

Permalink
Merge pull request #119 from mycel-domain/feat/foxy-registry-default-…
Browse files Browse the repository at this point in the history
…networks

Add default to each networks
  • Loading branch information
taryune authored Jan 11, 2024
2 parents 9043572 + d0419f2 commit 669d667
Show file tree
Hide file tree
Showing 5 changed files with 163 additions and 34 deletions.
9 changes: 9 additions & 0 deletions proto/mycel/registry/network_name.proto
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ enum NetworkName {
// BTC 1xxx
BITCOIN_MAINNET_MAINNET = 10000;
BITCOIN_TESTNET_TESTNET = 10001;
// DEFAULT
BITCOIN_DEFAULT_DEFAULT = 19999;

// EVM 2xxxx
// Etheruem
Expand Down Expand Up @@ -42,6 +44,8 @@ enum NetworkName {
// Zetachain
// ZETA_MAINNET_MAINNET = 20018;
ZETA_TESTNET_ATHENS = 20019;
// DEFAULT
EVM_DEFAULT_DEFAULT = 29999;

// MOVE 3xxxx
//Aptos
Expand All @@ -50,8 +54,13 @@ enum NetworkName {
// Sui
SUI_MAINNET_MAINNET = 30002;
SUI_TESTNET_TESTNET = 30003;
// DEFAULT
MOVE_DEFAULT_DEFAULT = 39999;

// SOLANA 4xxxx
SOLANA_MAINNET_MAINNET = 40000;
SOLANA_TESTNET_TESTNET = 40001;
// DEFAULT
SOLANA_DEFAULT_DEFAULT = 49999;

}
80 changes: 49 additions & 31 deletions x/registry/types/network_name.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,31 @@ func (secondLevelDomain SecondLevelDomain) ParseParent() (parent string) {
}

func (secondLevelDomain *SecondLevelDomain) GetWalletRecord(walletRecordType string) string {
var defaultWalletRecordValue string
defaultWalletRecordType := GetDefaultWalletRecordType(walletRecordType)

// Validate walletRecordType
err := ValidateWalletRecordType(walletRecordType)
if err != nil {
return ""
}

for _, rec := range secondLevelDomain.Records {
if rec.GetWalletRecord() != nil && rec.GetWalletRecord().WalletRecordType.String() == walletRecordType {
return rec.GetWalletRecord().Value
walletRecord := rec.GetWalletRecord()
if walletRecord != nil {
// Get default wallet record value
if walletRecord.WalletRecordType.String() == defaultWalletRecordType {
defaultWalletRecordValue = walletRecord.Value
}
// Get wallet record value
if walletRecord.WalletRecordType.String() == walletRecordType && walletRecord.Value != "" {
// Return wallet record value if found
return walletRecord.Value
}
}
}
return ""
// Return default wallet record value if no wallet record is found
return defaultWalletRecordValue
}

func (secondLevelDomain *SecondLevelDomain) GetDnsRecord(dnsRecordType string) string {
Expand Down
55 changes: 55 additions & 0 deletions x/registry/types/second_level_domain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,61 @@ func TestDomainValidate(t *testing.T) {
}
}

func TestGetWalletRecord(t *testing.T) {
domain := SecondLevelDomain{Name: "foo", Parent: "myc"}
testCases := []struct {
desc string
walletRecordType string
resp string
fn func()
}{
// BITCOIN
{desc: "Bitcoin Default", walletRecordType: "BITCOIN_MAINNET_MAINNET", resp: "1BvBMSEYstWetqTFn5Au4m4GFg7xJaNVN2", fn: func() {
err := domain.UpdateWalletRecord("BITCOIN_DEFAULT_DEFAULT", "1BvBMSEYstWetqTFn5Au4m4GFg7xJaNVN2")
require.Nil(t, err)
}},
{desc: "Bitcoin Mainnet", walletRecordType: "BITCOIN_MAINNET_MAINNET", resp: "1BvBMSEYstWetqTFn5Au4m4GFg7xJaNVN2", fn: func() {
err := domain.UpdateWalletRecord("BITCOIN_MAINNET_MAINNET", "1BvBMSEYstWetqTFn5Au4m4GFg7xJaNVN2")
require.Nil(t, err)
}},
// EVM
{desc: "Ethereum Default", walletRecordType: "ETHEREUM_MAINNET_MAINNET", resp: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", fn: func() {
err := domain.UpdateWalletRecord("EVM_DEFAULT_DEFAULT", "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266")
require.Nil(t, err)
}},
{desc: "Ethereum Mainnet", walletRecordType: "ETHEREUM_MAINNET_MAINNET", resp: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", fn: func() {
err := domain.UpdateWalletRecord("ETHEREUM_MAINNET_MAINNET", "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266")
require.Nil(t, err)
}},
// MOVE
{desc: "Aptos Default", walletRecordType: "APTOS_MAINNET_MAINNET", resp: "0xeeff357ea5c1a4e7bc11b2b17ff2dc2dcca69750bfef1e1ebcaccf8c8018175b", fn: func() {
err := domain.UpdateWalletRecord("MOVE_DEFAULT_DEFAULT", "0xeeff357ea5c1a4e7bc11b2b17ff2dc2dcca69750bfef1e1ebcaccf8c8018175b")
require.Nil(t, err)
}},
{desc: "Aptos Mainnet", walletRecordType: "APTOS_MAINNET_MAINNET", resp: "0xeeff357ea5c1a4e7bc11b2b17ff2dc2dcca69750bfef1e1ebcaccf8c8018175b", fn: func() {
err := domain.UpdateWalletRecord("APTOS_MAINNET_MAINNET", "0xeeff357ea5c1a4e7bc11b2b17ff2dc2dcca69750bfef1e1ebcaccf8c8018175b")
require.Nil(t, err)
}},
// SOLANA
{desc: "Solana Default", walletRecordType: "SOLANA_MAINNET_MAINNET", resp: "HN7cABqLq46Es1jh92dQQisAq662SmxELLLsHHe4YWrH", fn: func() {
err := domain.UpdateWalletRecord("SOLANA_DEFAULT_DEFAULT", "HN7cABqLq46Es1jh92dQQisAq662SmxELLLsHHe4YWrH")
require.Nil(t, err)
}},
{desc: "Solana Mainnet", walletRecordType: "SOLANA_MAINNET_MAINNET", resp: "HN7cABqLq46Es1jh92dQQisAq662SmxELLLsHHe4YWrH", fn: func() {
err := domain.UpdateWalletRecord("SOLANA_MAINNET_MAINNET", "HN7cABqLq46Es1jh92dQQisAq662SmxELLLsHHe4YWrH")
require.Nil(t, err)
}},
}

for _, tc := range testCases {
t.Run(tc.desc, func(t *testing.T) {
tc.fn()
rec := domain.GetWalletRecord(tc.walletRecordType)
require.Equal(t, tc.resp, rec)
})
}
}

func TestDomainUpdateWalletRecord(t *testing.T) {
testCases := []struct {
walletRecordType string
Expand Down
28 changes: 28 additions & 0 deletions x/registry/types/wallet_record.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ func WalletRecordFormats() map[string]string {
// Bitcoin
"BITCOIN_MAINNET_MAINNET": "BITCOIN",
"BITCOIN_TESTNET_TESTNET": "BITCOIN",
// DEFAULT
"BITCOIN_DEFAULT_DEFAULT": "BITCOIN",

// EVM
"ETHEREUM_MAINNET_MAINNET": "ETHEREUM",
Expand Down Expand Up @@ -42,16 +44,22 @@ func WalletRecordFormats() map[string]string {
"SHARDEUM_BETANET_SPHINX": "ETHEREUM",
// ZetaChain
"ZETA_TESTNET_ATHENS": "ETHEREUM",
// DEFAULT
"EVM_DEFAULT_DEFAULT": "ETHEREUM",

// Move
"APTOS_MAINNET_MAINNET": "MOVE",
"APTOS_TESTNET_TESTNET": "MOVE",
"SUI_MAINNET_MAINNET": "MOVE",
"SUI_TESTNET_TESTNET": "MOVE",
// DEFAULT
"MOVE_DEFAULT_DEFAULT": "MOVE",

// Solana
"SOLANA_MAINNET_MAINNET": "SOLANA",
"SOLANA_TESTNET_TESTNET": "SOLANA",
// DEFAULT
"SOLANA_DEFAULT_DEFAULT": "SOLANA",
}
}

Expand Down Expand Up @@ -97,3 +105,23 @@ func ValidateWalletAddress(walletAddressFormat string, address string) (err erro
}
return err
}

// GetDefaultRecordType(walletRecordType) returns the default wallet address for a given wallet record type.
// This is used when a wallet record is not found in the domain record.
func GetDefaultWalletRecordType(walletRecordType string) string {
wrf := WalletRecordFormats()
network := wrf[walletRecordType]
switch network {
case "BITCOIN":
return "BITCOIN_DEFAULT_DEFAULT"
case "ETHEREUM":
return "EVM_DEFAULT_DEFAULT"
case "MOVE":
return "MOVE_DEFAULT_DEFAULT"
case "SOLANA":
return "SOLANA_DEFAULT_DEFAULT"
default:
// This should never happen
panic(fmt.Sprintf("Wallet record type %s is not found in WalletRecordFormats", walletRecordType))
}
}

0 comments on commit 669d667

Please sign in to comment.