(no commit message provided)

This commit is contained in:
Prad Nukala
2024-07-05 22:20:13 -04:00
committed by Prad Nukala (aider)
commit 5fd43dfd6b
457 changed files with 115535 additions and 0 deletions
+69
View File
@@ -0,0 +1,69 @@
package coins
// Coin represents a cryptocurrency
type Coin interface {
// FormatAddress formats a public key into an address
FormatAddress(pubKey []byte) (string, error)
// GetIndex returns the coin type index
GetIndex() int64
// GetPath returns the coin component path
GetPath() uint32
// GetSymbol returns the coin symbol
GetSymbol() string
// GetMethod returns the coin DID method
GetMethod() string
// GetName returns the coin name
GetName() string
}
// DefaultCoins is a list of default coins used in the vault
var DefaultCoins = []Coin{
CoinBTC,
CoinETH,
CoinSNR,
}
var (
// Bitcoin mainnet
CoinBTC = &coin{
Name: "Bitcoin",
Index: 0,
Path: 0x80000000,
Symbol: "BTC",
Hrp: "bc",
Method: "btcr",
}
// Ethereum
CoinETH = &coin{
Name: "Ethereum",
Index: 60,
Path: 0x8000003c,
Symbol: "ETH",
Method: "ethr",
}
// Sonr
CoinSNR = &coin{
Name: "Sonr",
Index: 703,
Path: 0x800002bf,
Symbol: "SNR",
Hrp: "idx",
Method: "sonr",
}
)
// CoinBTCType is the coin type for BTC
const CoinBTCType = int64(0)
// CoinETHType is the coin type for ETH
const CoinETHType = int64(60)
// CoinSNRType is the coin type for SNR
const CoinSNRType = int64(703)
+54
View File
@@ -0,0 +1,54 @@
package coins
import (
"fmt"
"github.com/cosmos/cosmos-sdk/types/bech32"
)
type coin struct {
Name string `json:"name"`
Symbol string `json:"symbol"`
Hrp string `json:"hrp"`
Method string `json:"method"`
Index int64 `json:"index"`
Path uint32 `json:"path"`
}
// FormatAddress formats the address based on the coin
func (c *coin) FormatAddress(pubKey []byte) (string, error) {
if c.Hrp != "" {
return bech32.ConvertAndEncode(c.Hrp, pubKey)
}
return "", fmt.Errorf("unsupported coin")
}
// GetIndex returns the coin index
func (c *coin) GetIndex() int64 {
return c.Index
}
// GetName returns the coin name
func (c *coin) GetName() string {
return c.Name
}
// GetSymbol returns the coin symbol
func (c *coin) GetSymbol() string {
return c.Symbol
}
// GetHrp returns the coin hrp
func (c *coin) GetHrp() string {
return c.Hrp
}
// GetPath returns the coin path
func (c *coin) GetPath() uint32 {
return c.Path
}
// GetMethod returns the DID method for the coin
func (c *coin) GetMethod() string {
return c.Method
}