Example #1
0
func (addr *address) Stream() (uint64, error) {

	b, err := base58.Decode(addr.Identifier[3:])
	if err != nil {
		return 0, err
	}
	_, nb := varint.Decode(b)
	s, _ := varint.Decode(b[nb:])

	return s, nil
}
Example #2
0
func ValidateNonce(payload []byte) bool {

	if len(payload) < 2 {
		return false
	}

	var offset int
	var nonce, trials_test uint64
	var hash_test, initial_payload []byte

	nonce, offset = varint.Decode(payload)
	initial_payload = payload[offset:]

	sha := sha512.New()
	sha.Write(initial_payload)
	initial_hash := sha.Sum(nil)

	var target uint64 = MAX_UINT64 / uint64((len(payload)+PAYLOAD_LENGTH_EXTRA_BYTES+8)*AVERAGE_PROOF_OF_WORK_NONCE_TRIALS_PER_BYTE)

	hash_test = varint.Encode(nonce)
	hash_test = append(hash_test, initial_hash...)
	sha1, sha2 := sha512.New(), sha512.New()
	sha1.Write(hash_test)
	sha2.Write(sha1.Sum(nil))

	trials_test = binary.BigEndian.Uint64(sha2.Sum(nil)[:8])

	return trials_test <= target
}
Example #3
0
func (addr *address) Version() (uint64, error) {

	b, err := base58.Decode(addr.Identifier[3:])
	if err != nil {
		return 0, err
	}
	v, _ := varint.Decode(b)

	return v, nil
}
Example #4
0
func (a *addr) Deserialize(packet []byte) error {

	if len(packet) < 1 {
		return errors.New("addr.Deserialize: packet is too short for count extraction")
	}

	cnt, nb := varint.Decode(packet[:])

	if uint64(len(packet)) < uint64(nb)+(cnt*38) { // sizeof(netaddr) == 38
		return errors.New("addr.Deserialize: packet is too short for netaddr extraction")
	}

	for i := uint64(0); i < cnt; i++ {
		off := uint64(nb) + (i * 38)
		na := NewNetaddr()
		if err := na.Deserialize(packet[off : off+38]); err != nil {
			return err
		}
		a.Add(na)
	}

	return nil
}