本文整理匯總了Golang中gx/ipfs/QmT8rehPR3F6bmwL6zjUN8XpiDBFFpMP2myPdC6ApsWfJf/go-base58.Decode函數的典型用法代碼示例。如果您正苦於以下問題:Golang Decode函數的具體用法?Golang Decode怎麽用?Golang Decode使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Decode函數的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: escapeDhtKey
func escapeDhtKey(s string) (string, error) {
parts := path.SplitList(s)
switch len(parts) {
case 1:
return string(b58.Decode(s)), nil
case 3:
k := b58.Decode(parts[2])
return path.Join(append(parts[:2], string(k))), nil
default:
return "", errors.New("invalid key")
}
}
示例2: InvertKey
// InvertKey returns a b58 decoded Datastore key
// TODO: this is hacky because it encodes every path component. some
// path components may be proper strings already...
func (b58KeyConverter) InvertKey(dsk ds.Key) ds.Key {
k := ds.NewKey("/")
for _, n := range dsk.Namespaces() {
k = k.ChildString(string(b58.Decode(n)))
}
return k
}
示例3: UnmarshalJSON
// UnmarshalJSON returns a JSON-encoded Key (string)
func (k *Key) UnmarshalJSON(mk []byte) error {
var s string
err := json.Unmarshal(mk, &s)
if err != nil {
return err
}
*k = Key(string(b58.Decode(s)))
if len(*k) == 0 && len(s) > 2 { // if b58.Decode fails, k == ""
return fmt.Errorf("Key.UnmarshalJSON: invalid b58 string: %v", mk)
}
return nil
}
示例4: ParseKeyToPath
func ParseKeyToPath(txt string) (Path, error) {
if txt == "" {
return "", ErrNoComponents
}
chk := b58.Decode(txt)
if len(chk) == 0 {
return "", errors.New("not a key")
}
if _, err := mh.Cast(chk); err != nil {
return "", err
}
return FromKey(key.Key(chk)), nil
}
示例5: loadID
func (n *IpfsNode) loadID() error {
if n.Identity != "" {
return errors.New("identity already loaded")
}
cfg, err := n.Repo.Config()
if err != nil {
return err
}
cid := cfg.Identity.PeerID
if cid == "" {
return errors.New("Identity was not set in config (was ipfs init run?)")
}
if len(cid) == 0 {
return errors.New("No peer ID in config! (was ipfs init run?)")
}
n.Identity = peer.ID(b58.Decode(cid))
return nil
}
示例6: B58KeyDecode
// B58KeyDecode returns Key from a b58 encoded string
func B58KeyDecode(s string) Key {
return Key(string(b58.Decode(s)))
}
示例7:
n, err := req.InvocContext().GetNode()
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
}
dht, ok := n.Routing.(*ipdht.IpfsDHT)
if !ok {
res.SetError(ErrNotDHT, cmds.ErrNormal)
return
}
events := make(chan *notif.QueryEvent)
ctx := notif.RegisterForQueryEvents(req.Context(), events)
k := string(b58.Decode(req.Arguments()[0]))
closestPeers, err := dht.GetClosestPeers(ctx, k)
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
}
go func() {
defer close(events)
for p := range closestPeers {
notif.PublishQueryEvent(ctx, ¬if.QueryEvent{
ID: p,
Type: notif.FinalPeer,
})
}