Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use correct address network ID for testnets #474

Merged
merged 1 commit into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion ledger/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,9 @@ const (
AddressHeaderNetworkMask = 0x0F
AddressHashSize = 28

AddressNetworkTestnet = 0
AddressNetworkMainnet = 1

AddressTypeKeyKey = 0b0000
AddressTypeScriptKey = 0b0001
AddressTypeKeyScript = 0b0010
Expand Down Expand Up @@ -323,7 +326,7 @@ func (a Address) generateHRP() string {
ret = "addr"
}
// Add test_ suffix if not mainnet
if a.networkId != 1 {
if a.networkId != AddressNetworkMainnet {
ret += "_test"
}
return ret
Expand Down
20 changes: 14 additions & 6 deletions networks.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,32 +14,40 @@

package ouroboros

import (
"github.com/blinklabs-io/gouroboros/ledger"
)

// Network definitions
var (
NetworkTestnet = Network{Id: 0, Name: "testnet", NetworkMagic: 1097911063}
NetworkTestnet = Network{
Id: ledger.AddressNetworkTestnet,
Name: "testnet",
NetworkMagic: 1097911063,
}
NetworkMainnet = Network{
Id: 1,
Id: ledger.AddressNetworkMainnet,
Name: "mainnet",
NetworkMagic: 764824073,
PublicRootAddress: "backbone.cardano-mainnet.iohk.io",
PublicRootPort: 3001,
}
NetworkPreprod = Network{
Id: 2,
Id: ledger.AddressNetworkTestnet,
Name: "preprod",
NetworkMagic: 1,
PublicRootAddress: "preprod-node.world.dev.cardano.org",
PublicRootPort: 30000,
}
NetworkPreview = Network{
Id: 3,
Id: ledger.AddressNetworkTestnet,
Name: "preview",
NetworkMagic: 2,
PublicRootAddress: "preview-node.play.dev.cardano.org",
PublicRootPort: 3001,
}
NetworkSancho = Network{
Id: 4,
Id: ledger.AddressNetworkTestnet,
Name: "sanchonet",
NetworkMagic: 4,
PublicRootAddress: "sanchonet-node.play.dev.cardano.org",
Expand Down Expand Up @@ -94,7 +102,7 @@ func NetworkByNetworkMagic(networkMagic uint32) Network {

// Network represents a Cardano network
type Network struct {
Id uint8
Id uint8 // network ID used for addresses
Name string
NetworkMagic uint32
PublicRootAddress string
Expand Down
Loading