Exemplo n.º 1
0
// Return the instance, properly unmarshaled, given the entry in the database, which is
// the hash for the Instance (vv) followed by the source from which to unmarshal (v)
func (d *BoltDB) GetInstance(v []byte) fct.IBlock {

	var vv [32]byte
	copy(vv[:], v[:32])
	v = v[32:]

	var instance fct.IBlock = d.instances[vv]
	if instance == nil {
		vp := fct.NewHash(vv[:])
		fct.Prtln("Object hash: ", vp)
		panic("This should not happen.  Object stored in the database has no IBlock instance")
	}

	r := instance.GetNewInstance()
	if r == nil {
		panic("An IBlock has failed to implement GetNewInstance()")
	}

	datalen, v := binary.BigEndian.Uint32(v[0:4]), v[4:]
	if len(v) != int(datalen) {
		fct.Prtln("Lengths don't match.  Expected ", datalen, " and got ", len(v))
		panic("Data not returned properly")
	}
	err := r.UnmarshalBinary(v)
	if err != nil {
		panic("This should not happen.  IBlock failed to unmarshal.")
	}

	return r
}
Exemplo n.º 2
0
func (w1 WalletEntry) GetAddress() (fct.IAddress, error) {
	if w1.rcd == nil {
		return nil, fmt.Errorf("Should never happen. Missing the rcd block")
	}
	var adr fct.IHash
	var err error
	if w1.addrtype == "fct" {
		adr, err = w1.rcd.GetAddress()
	} else {
		if len(w1.public) == 0 {
			err = fmt.Errorf("No Public Key for WalletEntry")
		} else {
			adr = fct.NewHash(w1.public[0])
		}
	}
	if err != nil {
		return nil, err
	}
	return adr, nil
}
Exemplo n.º 3
0
func (fs *Test_state) Init(test *testing.T) {
	fs.stats.errors = make(map[string]int, 100)
	fs.stats.full = make(map[string]string, 100)

	fs.inputAddresses = make([]fct.IAddress, 0, 10)
	fs.outputAddresses = make([]fct.IAddress, 0, 10)
	fs.ecoutputAddresses = make([]fct.IAddress, 0, 10)
	fs.twallet = new(wallet.SCWallet) // Wallet for our tests
	fs.twallet.Init()

	for i := 0; i < 10; i++ {
		addr, err := fs.twallet.GenerateFctAddress([]byte("testin_"+cv.Itoa(i)), 1, 1)
		if err != nil {
			fct.Prtln(err)
			test.Fail()
		}
		fs.inputAddresses = append(fs.inputAddresses, addr)
		fs.outputAddresses = append(fs.outputAddresses, addr)
	}
	t := fct.NewHash([]byte(fmt.Sprintf("Test State and Balances %v", time.Now().UnixNano()))).String()
	fs.twallet.NewSeed([]byte("Test State and Balances" + t))

	for i := 0; i < 10000; i++ {
		addr, err := fs.twallet.GenerateFctAddress([]byte("testout_"+cv.Itoa(i)), 1, 1)
		if err != nil {
			fct.Prtln(err)
			test.Fail()
		}
		fs.outputAddresses = append(fs.outputAddresses, addr)
	}
	for i := 0; i < 1000; i++ {
		addr, err := fs.twallet.GenerateECAddress([]byte("testecout_" + cv.Itoa(i)))
		if err != nil {
			fct.Prtln(err)
			test.Fail()
		}
		fs.ecoutputAddresses = append(fs.ecoutputAddresses, addr)
	}
	fs.stats.begin()
}
Exemplo n.º 4
0
func (b *FBlock) SetPrevKeyMR(hash []byte) {
	h := fct.NewHash(hash)
	b.PrevKeyMR = h
}