Esempio n. 1
0
func handleLog(ctx *cli.Context, client *daemon.Client) error {
	log, err := client.Log(nil, nil)
	if err != nil {
		return err
	}

	for _, pnode := range log.Nodes {
		commitMH, err := multihash.Cast(pnode.Hash)
		if err != nil {
			return err
		}

		pcmt := pnode.Commit
		if pcmt == nil {
			return fmt.Errorf("Empty commit in log-commit")
		}

		rootMH, err := multihash.Cast(pcmt.Root)
		if err != nil {
			return err
		}

		fmt.Printf(
			"%s/%s by %s, %s\n",
			colors.Colorize(commitMH.B58String()[:10], colors.Green),
			colors.Colorize(rootMH.B58String()[:10], colors.Magenta),
			pcmt.Author,
			pcmt.Message,
		)
	}
	return nil
}
Esempio n. 2
0
func addressBytesToString(p Protocol, b []byte) (string, error) {
	switch p.Code {

	// ipv4,6
	case P_IP4, P_IP6:
		return net.IP(b).String(), nil

	// tcp udp dccp sctp
	case P_TCP, P_UDP, P_DCCP, P_SCTP:
		i := binary.BigEndian.Uint16(b)
		return strconv.Itoa(int(i)), nil

	case P_IPFS: // ipfs
		// the address is a varint-prefixed multihash string representation
		size, n := ReadVarintCode(b)
		b = b[n:]
		if len(b) != size {
			panic("inconsistent lengths")
		}
		m, err := mh.Cast(b)
		if err != nil {
			return "", err
		}
		return m.B58String(), nil
	}

	return "", fmt.Errorf("unknown protocol")
}
Esempio n. 3
0
func Decode(encoding, digest string) (mh.Multihash, error) {
	switch encoding {
	case "raw":
		return mh.Cast([]byte(digest))
	case "hex":
		return hex.DecodeString(digest)
	case "base58":
		return base58.Decode(digest), nil
	case "base64":
		return base64.StdEncoding.DecodeString(digest)
	default:
		return nil, fmt.Errorf("unknown encoding: %s", encoding)
	}
}
Esempio n. 4
0
// IDFromBytes cast a string to ID type, and validate
// the id to make sure it is a multihash.
func IDFromBytes(b []byte) (ID, error) {
	if _, err := mh.Cast(b); err != nil {
		return ID(""), err
	}
	return ID(b), nil
}
Esempio n. 5
0
// IDFromString cast a string to ID type, and validate
// the id to make sure it is a multihash.
func IDFromString(s string) (ID, error) {
	if _, err := mh.Cast([]byte(s)); err != nil {
		return ID(""), err
	}
	return ID(s), nil
}