-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #196 from cloudstruct/feat/networks
feat: allow specifying pre-defined networks
- Loading branch information
Showing
6 changed files
with
105 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package ouroboros | ||
|
||
// Network definitions | ||
var ( | ||
NetworkTestnet = Network{Id: 0, Name: "testnet", NetworkMagic: 1097911063} | ||
NetworkMainnet = Network{Id: 1, Name: "mainnet", NetworkMagic: 764824073} | ||
NetworkPreprod = Network{Id: 2, Name: "preprod", NetworkMagic: 1} | ||
NetworkPreview = Network{Id: 3, Name: "preview", NetworkMagic: 2} | ||
|
||
NetworkInvalid = Network{Id: 0, Name: "invalid", NetworkMagic: 0} // NetworkInvalid is used as a return value for lookup functions when a network isn't found | ||
) | ||
|
||
// List of valid networks for use in lookup functions | ||
var networks = []Network{NetworkTestnet, NetworkMainnet, NetworkPreprod, NetworkPreview} | ||
|
||
// NetworkByName returns a predefined network by name | ||
func NetworkByName(name string) Network { | ||
for _, network := range networks { | ||
if network.Name == name { | ||
return network | ||
} | ||
} | ||
return NetworkInvalid | ||
} | ||
|
||
// NetworkById returns a predefined network by ID | ||
func NetworkById(id uint) Network { | ||
for _, network := range networks { | ||
if network.Id == id { | ||
return network | ||
} | ||
} | ||
return NetworkInvalid | ||
} | ||
|
||
// NetworkByNetworkMagic returns a predefined network by network magic | ||
func NetworkByNetworkMagic(networkMagic uint32) Network { | ||
for _, network := range networks { | ||
if network.NetworkMagic == networkMagic { | ||
return network | ||
} | ||
} | ||
return NetworkInvalid | ||
} | ||
|
||
// Network represents a Cardano network | ||
type Network struct { | ||
Id uint | ||
Name string | ||
NetworkMagic uint32 | ||
} | ||
|
||
func (n Network) String() string { | ||
return n.Name | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters