1 Star 0 Fork 0

符策委/wallet-grpc

Create your Gitee Account
Explore and code with more than 13.5 million developers,Free private repositories !:)
Sign up
文件
Clone or Download
address_util.go 1.25 KB
Copy Edit Raw Blame History
符策委 authored 2023-10-03 00:48 +08:00 . fix: solana;
package solana
import (
"github.com/centrifuge/go-substrate-rpc-client/v4/types"
"github.com/portto/solana-go-sdk/common"
)
type Util struct {
}
func NewUtil() *Util {
return &Util{}
}
// MARK - Implement the protocol wallet.Util
func (u *Util) EncodePublicKeyToAddress(publicKey string) (string, error) {
return EncodePublicKeyToAddress(publicKey)
}
// Warning: eth cannot support decode address to public key
func (u *Util) DecodeAddressToPublicKey(address string) (string, error) {
return DecodeAddressToPublicKey(address)
}
// Check if address is 40 hexadecimal characters
func (u *Util) IsValidAddress(address string) bool {
return IsValidAddress(address)
}
// MARK - like wallet.Util
func EncodePublicKeyToAddress(publicKey string) (string, error) {
bytes, err := types.HexDecodeString(publicKey)
if err != nil {
return "", err
}
pubKey := common.PublicKeyFromBytes(bytes)
return pubKey.ToBase58(), nil
}
func DecodeAddressToPublicKey(address string) (string, error) {
pubKey := common.PublicKeyFromString(address)
return types.HexEncodeToString(pubKey.Bytes()), nil
}
func IsValidAddress(address string) bool {
if len(address) != 44 {
return false
}
pub := common.PublicKeyFromString(address)
addr2 := pub.ToBase58()
return address == addr2
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/fu-ce-wei/wallet-grpc.git
git@gitee.com:fu-ce-wei/wallet-grpc.git
fu-ce-wei
wallet-grpc
wallet-grpc
3f3ae683dd35

Search