func (tran *TransactionList) Print() {

	for _, tx := range tran.Txs {

		log.Printf("TxId: %v", tx.Hash)

		log.Print("TxIns:")
		if tx.TxInCnt == 1 && tx.TxIns[0].InputVout == 4294967295 {
			log.Printf("TxIn coinbase, newly generated coins")
		} else {
			for txin_index, txin := range tx.TxIns {
				log.Printf("TxIn index: %v", txin_index)
				log.Printf("TxIn Input_Hash: %v", txin.InputHash)
				log.Printf("TxIn Input_Index: %v", txin.InputVout)
			}
		}

		log.Print("TxOuts:")

		for txo_index, txout := range tx.TxOuts {
			log.Printf("TxOut index: %v", txo_index)
			log.Printf("TxOut value: %v", txout.Value)
			txout_addr := txout.Addr
			if txout_addr != "" {
				log.Printf("TxOut address: %v", txout_addr)
			} else {
				log.Printf("TxOut address: can't decode address")
			}
		}
	}

}
Exemple #2
0
// Run initiates a RandHound simulation
func (rhs *RHSimulation) Run(config *sda.SimulationConfig) error {
	leader, err := config.Overlay.CreateProtocolSDA(config.Tree, "RandHound")
	if err != nil {
		return err
	}
	rh := leader.(*RandHound)
	err = rh.Setup(uint32(rhs.Hosts), rhs.Trustees, rhs.Purpose)
	if err != nil {
		return err
	}
	log.Printf("RandHound - group config: %d %d %d %d %d %d\n", rh.Group.N, rh.Group.F, rh.Group.L, rh.Group.K, rh.Group.R, rh.Group.T)
	log.Printf("RandHound - shards: %d\n", rhs.Shards)
	if err := rh.StartProtocol(); err != nil {
		log.Error("Error while starting protcol:", err)
	}

	select {
	case <-rh.Leader.Done:
		log.Print("RandHound - done")
		rnd, err := rh.Random()
		if err != nil {
			panic(err)
		}
		sharding, err := rh.Shard(rnd, rhs.Shards)
		if err != nil {
			panic(err)
		}
		log.Printf("RandHound - random bytes: %v\n", rnd)
		log.Printf("RandHound - sharding: %v\n", sharding)
	case <-time.After(time.Second * 60):
		log.Print("RandHound - time out")
	}

	return nil

}
Exemple #3
0
func TestRandHound(t *testing.T) {

	// Setup parameters
	var name string = "RandHound"             // Protocol name
	var nodes uint32 = 10                     // Number of nodes (peers + leader)
	var trustees uint32 = 5                   // Number of trustees
	var purpose string = "RandHound test run" // Purpose
	var shards uint32 = 2                     // Number of shards created from the randomness

	local := sda.NewLocalTest()
	_, _, tree := local.GenTree(int(nodes), false, true, true)
	defer local.CloseAll()

	log.TestOutput(testing.Verbose(), 1)

	// Setup and Start RandHound
	log.Printf("RandHound - starting")
	leader, err := local.CreateProtocol(tree, name)
	if err != nil {
		t.Fatal("Couldn't initialise RandHound protocol:", err)
	}
	rh := leader.(*randhound.RandHound)
	err = rh.Setup(nodes, trustees, purpose)
	if err != nil {
		t.Fatal("Couldn't initialise RandHound protocol:", err)
	}
	log.Printf("RandHound - group config: %d %d %d %d %d %d\n", rh.Group.N, rh.Group.F, rh.Group.L, rh.Group.K, rh.Group.R, rh.Group.T)
	log.Printf("RandHound - shards: %d\n", shards)
	leader.Start()

	select {
	case <-rh.Leader.Done:
		log.Printf("RandHound - done")
		rnd, err := rh.Random()
		if err != nil {
			t.Fatal(err)
		}
		sharding, err := rh.Shard(rnd, shards)
		if err != nil {
			t.Fatal(err)
		}
		log.Printf("RandHound - random bytes: %v\n", rnd)
		log.Printf("RandHound - sharding: %v\n", sharding)
	case <-time.After(time.Second * 60):
		t.Fatal("RandHound – time out")
	}
}