本文整理汇总了Golang中gx/ipfs/QmYf7ng2hG5XBtJA3tN34DQ2GUN5HNksEw1rLDkmr6vGku/go-multihash.FromB58String函数的典型用法代码示例。如果您正苦于以下问题:Golang FromB58String函数的具体用法?Golang FromB58String怎么用?Golang FromB58String使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了FromB58String函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: deserializeNode
// converts the Node object into a real dag.Node
func deserializeNode(node *Node, dataFieldEncoding string) (*dag.Node, error) {
dagnode := new(dag.Node)
switch dataFieldEncoding {
case "text":
dagnode.SetData([]byte(node.Data))
case "base64":
data, _ := base64.StdEncoding.DecodeString(node.Data)
dagnode.SetData(data)
default:
return nil, fmt.Errorf("Unkown data field encoding")
}
dagnode.Links = make([]*dag.Link, len(node.Links))
for i, link := range node.Links {
hash, err := mh.FromB58String(link.Hash)
if err != nil {
return nil, err
}
dagnode.Links[i] = &dag.Link{
Name: link.Name,
Size: link.Size,
Hash: hash,
}
}
return dagnode, nil
}
示例2: IDB58Decode
// IDB58Decode returns a b58-decoded Peer
func IDB58Decode(s string) (ID, error) {
m, err := mh.FromB58String(s)
if err != nil {
return "", err
}
return ID(m), err
}
示例3: deserializeNode
// converts the Node object into a real dag.Node
func deserializeNode(node *Node) (*dag.Node, error) {
dagnode := new(dag.Node)
dagnode.Data = []byte(node.Data)
dagnode.Links = make([]*dag.Link, len(node.Links))
for i, link := range node.Links {
hash, err := mh.FromB58String(link.Hash)
if err != nil {
return nil, err
}
dagnode.Links[i] = &dag.Link{
Name: link.Name,
Size: link.Size,
Hash: hash,
}
}
return dagnode, nil
}
示例4: addressStringToBytes
func addressStringToBytes(p Protocol, s string) ([]byte, error) {
switch p.Code {
case P_IP4: // ipv4
i := net.ParseIP(s).To4()
if i == nil {
return nil, fmt.Errorf("failed to parse ip4 addr: %s", s)
}
return i, nil
case P_IP6: // ipv6
i := net.ParseIP(s).To16()
if i == nil {
return nil, fmt.Errorf("failed to parse ip6 addr: %s", s)
}
return i, nil
// tcp udp dccp sctp
case P_TCP, P_UDP, P_DCCP, P_SCTP:
i, err := strconv.Atoi(s)
if err != nil {
return nil, fmt.Errorf("failed to parse %s addr: %s", p.Name, err)
}
if i >= 65536 {
return nil, fmt.Errorf("failed to parse %s addr: %s", p.Name, "greater than 65536")
}
b := make([]byte, 2)
binary.BigEndian.PutUint16(b, uint16(i))
return b, nil
case P_IPFS: // ipfs
// the address is a varint prefixed multihash string representation
m, err := mh.FromB58String(s)
if err != nil {
return nil, fmt.Errorf("failed to parse ipfs addr: %s %s", s, err)
}
size := CodeToVarint(len(m))
b := append(size, m...)
return b, nil
}
return []byte{}, fmt.Errorf("failed to parse %s addr: unknown", p.Name)
}
示例5: SplitAbsPath
// SplitAbsPath clean up and split fpath. It extracts the first component (which
// must be a Multihash) and return it separately.
func SplitAbsPath(fpath Path) (mh.Multihash, []string, error) {
log.Debugf("Resolve: '%s'", fpath)
parts := fpath.Segments()
if parts[0] == "ipfs" {
parts = parts[1:]
}
// if nothing, bail.
if len(parts) == 0 {
return nil, nil, ErrNoComponents
}
// first element in the path is a b58 hash (for now)
h, err := mh.FromB58String(parts[0])
if err != nil {
log.Debug("given path element is not a base58 string.\n")
return nil, nil, err
}
return h, parts[1:], nil
}
示例6: getBlockForKey
func getBlockForKey(req cmds.Request, skey string) (blocks.Block, error) {
n, err := req.InvocContext().GetNode()
if err != nil {
return nil, err
}
if !u.IsValidHash(skey) {
return nil, errors.New("Not a valid hash")
}
h, err := mh.FromB58String(skey)
if err != nil {
return nil, err
}
k := key.Key(h)
b, err := n.Blocks.GetBlock(req.Context(), k)
if err != nil {
return nil, err
}
log.Debugf("ipfs block: got block with key: %q", b.Key())
return b, nil
}
示例7: resolveOnce
// resolveOnce implements resolver. Uses the IPFS routing system to
// resolve SFS-like names.
func (r *routingResolver) resolveOnce(ctx context.Context, name string) (path.Path, error) {
log.Debugf("RoutingResolve: '%s'", name)
cached, ok := r.cacheGet(name)
if ok {
return cached, nil
}
hash, err := mh.FromB58String(name)
if err != nil {
// name should be a multihash. if it isn't, error out here.
log.Warningf("RoutingResolve: bad input hash: [%s]\n", name)
return "", err
}
// use the routing system to get the name.
// /ipns/<name>
h := []byte("/ipns/" + string(hash))
var entry *pb.IpnsEntry
var pubkey ci.PubKey
resp := make(chan error, 2)
go func() {
ipnsKey := key.Key(h)
val, err := r.routing.GetValue(ctx, ipnsKey)
if err != nil {
log.Warning("RoutingResolve get failed.")
resp <- err
}
entry = new(pb.IpnsEntry)
err = proto.Unmarshal(val, entry)
if err != nil {
resp <- err
}
resp <- nil
}()
go func() {
// name should be a public key retrievable from ipfs
pubk, err := routing.GetPublicKey(r.routing, ctx, hash)
if err != nil {
resp <- err
}
pubkey = pubk
resp <- nil
}()
for i := 0; i < 2; i++ {
err = <-resp
if err != nil {
return "", err
}
}
hsh, _ := pubkey.Hash()
log.Debugf("pk hash = %s", key.Key(hsh))
// check sig with pk
if ok, err := pubkey.Verify(ipnsEntryDataForSig(entry), entry.GetSignature()); err != nil || !ok {
return "", fmt.Errorf("Invalid value. Not signed by PrivateKey corresponding to %v", pubkey)
}
// ok sig checks out. this is a valid name.
// check for old style record:
valh, err := mh.Cast(entry.GetValue())
if err != nil {
// Not a multihash, probably a new record
p, err := path.ParsePath(string(entry.GetValue()))
if err != nil {
return "", err
}
r.cacheSet(name, p, entry)
return p, nil
} else {
// Its an old style multihash record
log.Warning("Detected old style multihash record")
p := path.FromKey(key.Key(valh))
r.cacheSet(name, p, entry)
return p, nil
}
}