예제 #1
0
func setUpLoadAllSeries(t *testing.T, namespace walletdb.Namespace, mgr *waddrmgr.Manager,
	test testLoadAllSeriesTest) *vp.Pool {
	pool, err := vp.Create(namespace, mgr, []byte{byte(test.id + 1)})
	if err != nil {
		t.Fatalf("Voting Pool creation failed: %v", err)
	}

	for _, series := range test.series {
		err := pool.CreateSeries(series.version, series.id,
			series.reqSigs, series.pubKeys)
		if err != nil {
			t.Fatalf("Test #%d Series #%d: failed to create series: %v",
				test.id, series.id, err)
		}

		for _, privKey := range series.privKeys {
			vp.TstRunWithManagerUnlocked(t, mgr, func() {
				if err := pool.EmpowerSeries(series.id, privKey); err != nil {
					t.Fatalf("Test #%d Series #%d: empower with privKey %v failed: %v",
						test.id, series.id, privKey, err)
				}
			})
		}
	}
	return pool
}
예제 #2
0
func exampleCreatePoolAndSeries(mgr *waddrmgr.Manager, vpNamespace walletdb.Namespace) (
	*votingpool.Pool, uint32, error) {
	pool, err := votingpool.Create(vpNamespace, mgr, []byte{0x00})
	if err != nil {
		return nil, 0, err
	}

	// Create a 2-of-3 series.
	seriesID := uint32(1)
	requiredSignatures := uint32(2)
	pubKeys := []string{
		"xpub661MyMwAqRbcFDDrR5jY7LqsRioFDwg3cLjc7tML3RRcfYyhXqqgCH5SqMSQdpQ1Xh8EtVwcfm8psD8zXKPcRaCVSY4GCqbb3aMEs27GitE",
		"xpub661MyMwAqRbcGsxyD8hTmJFtpmwoZhy4NBBVxzvFU8tDXD2ME49A6JjQCYgbpSUpHGP1q4S2S1Pxv2EqTjwfERS5pc9Q2yeLkPFzSgRpjs9",
		"xpub661MyMwAqRbcEbc4uYVXvQQpH9L3YuZLZ1gxCmj59yAhNy33vXxbXadmRpx5YZEupNSqWRrR7PqU6duS2FiVCGEiugBEa5zuEAjsyLJjKCh",
	}
	err = pool.CreateSeries(votingpool.CurrentVersion, seriesID, requiredSignatures, pubKeys)
	if err != nil {
		return nil, 0, err
	}
	err = pool.ActivateSeries(seriesID)
	if err != nil {
		return nil, 0, err
	}
	return pool, seriesID, nil
}
예제 #3
0
func TestCreatePoolWhenAlreadyExists(t *testing.T) {
	tearDown, mgr, pool := vp.TstCreatePool(t)
	defer tearDown()

	_, err := vp.Create(pool.TstNamespace(), mgr, pool.ID)

	vp.TstCheckError(t, "", err, vp.ErrPoolAlreadyExists)
}
예제 #4
0
func TestCreatePool(t *testing.T) {
	tearDown, mgr, pool := vp.TstCreatePool(t)
	defer tearDown()

	pool2, err := vp.Create(pool.TstNamespace(), mgr, []byte{0x02})
	if err != nil {
		t.Errorf("Error creating Pool: %v", err)
	}
	if !bytes.Equal(pool2.ID, []byte{0x02}) {
		t.Errorf("Pool ID mismatch: got %v, want %v", pool2.ID, []byte{0x02})
	}
}
예제 #5
0
func ExampleCreate() {
	// Create a new walletdb.DB. See the walletdb docs for instructions on how
	// to do that.
	db, dbTearDown, err := createWalletDB()
	if err != nil {
		fmt.Println(err)
		return
	}
	defer dbTearDown()

	// Create a new walletdb namespace for the address manager.
	mgrNamespace, err := db.Namespace([]byte("waddrmgr"))
	if err != nil {
		fmt.Println(err)
		return
	}

	// Create the address manager.
	seed := bytes.Repeat([]byte{0x2a, 0x64, 0xdf, 0x08}, 8)
	var fastScrypt = &waddrmgr.ScryptOptions{N: 16, R: 8, P: 1}
	mgr, err := waddrmgr.Create(
		mgrNamespace, seed, pubPassphrase, privPassphrase, &chaincfg.MainNetParams, fastScrypt)
	if err != nil {
		fmt.Println(err)
		return
	}

	// Create a walletdb namespace for votingpools.
	vpNamespace, err := db.Namespace([]byte("votingpool"))
	if err != nil {
		fmt.Println(err)
		return
	}

	// Create a voting pool.
	_, err = votingpool.Create(vpNamespace, mgr, []byte{0x00})
	if err != nil {
		fmt.Println(err)
		return
	}

	// Output:
	//
}
예제 #6
0
// This example demonstrates how to create a voting pool with one
// series and get a deposit address for that series.
func Example_depositAddress() {
	// Create the address manager and votingpool DB namespace. See the example
	// for the Create() function for more info on how this is done.
	mgr, vpNamespace, tearDownFunc, err := exampleCreateMgrAndDBNamespace()
	if err != nil {
		fmt.Println(err)
		return
	}
	defer tearDownFunc()

	// Create the voting pool.
	pool, err := votingpool.Create(vpNamespace, mgr, []byte{0x00})
	if err != nil {
		fmt.Println(err)
		return
	}

	// Create a 2-of-3 series.
	seriesID := uint32(1)
	requiredSignatures := uint32(2)
	pubKeys := []string{
		"xpub661MyMwAqRbcFDDrR5jY7LqsRioFDwg3cLjc7tML3RRcfYyhXqqgCH5SqMSQdpQ1Xh8EtVwcfm8psD8zXKPcRaCVSY4GCqbb3aMEs27GitE",
		"xpub661MyMwAqRbcGsxyD8hTmJFtpmwoZhy4NBBVxzvFU8tDXD2ME49A6JjQCYgbpSUpHGP1q4S2S1Pxv2EqTjwfERS5pc9Q2yeLkPFzSgRpjs9",
		"xpub661MyMwAqRbcEbc4uYVXvQQpH9L3YuZLZ1gxCmj59yAhNy33vXxbXadmRpx5YZEupNSqWRrR7PqU6duS2FiVCGEiugBEa5zuEAjsyLJjKCh",
	}
	err = pool.CreateSeries(votingpool.CurrentVersion, seriesID, requiredSignatures, pubKeys)
	if err != nil {
		fmt.Println(err)
		return
	}

	// Create a deposit address.
	addr, err := pool.DepositScriptAddress(seriesID, votingpool.Branch(0), votingpool.Index(1))
	if err != nil {
		fmt.Println(err)
		return
	}
	fmt.Println("Generated deposit address:", addr.EncodeAddress())

	// Output:
	// Generated deposit address: 3QTzpc9d3tTbNLJLB7xwt87nWM38boAhAw
}