本文整理匯總了Golang中github.com/NebulousLabs/Sia/crypto.GenerateTwofishKey函數的典型用法代碼示例。如果您正苦於以下問題:Golang GenerateTwofishKey函數的具體用法?Golang GenerateTwofishKey怎麽用?Golang GenerateTwofishKey使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了GenerateTwofishKey函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: createServerTester
// createServerTester creates a server tester object that is ready for testing,
// including money in the wallet and all modules initialized.
func createServerTester(name string) (*serverTester, error) {
// createServerTester is expensive, and therefore should not be called
// during short tests.
if testing.Short() {
panic("createServerTester called during short tests")
}
// Create the testing directory.
testdir := build.TempDir("api", name)
key, err := crypto.GenerateTwofishKey()
if err != nil {
return nil, err
}
st, err := assembleServerTester(key, testdir)
if err != nil {
return nil, err
}
// Mine blocks until the wallet has confirmed money.
for i := types.BlockHeight(0); i <= types.MaturityDelay; i++ {
_, err := st.miner.AddBlock()
if err != nil {
return nil, err
}
}
return st, nil
}
示例2: createAuthenticatedServerTester
// createAuthenticatedServerTester creates an authenticated server tester
// object that is ready for testing, including money in the wallet and all
// modules initalized.
func createAuthenticatedServerTester(name string, password string) (*serverTester, error) {
// createAuthenticatedServerTester should not get called during short
// tests, as it takes a long time to run.
if testing.Short() {
panic("assembleServerTester called during short tests")
}
// Create the testing directory.
testdir := build.TempDir("authenticated-api", name)
key, err := crypto.GenerateTwofishKey()
if err != nil {
return nil, err
}
st, err := assembleAuthenticatedServerTester(password, key, testdir)
if err != nil {
return nil, err
}
// Mine blocks until the wallet has confirmed money.
for i := types.BlockHeight(0); i <= types.MaturityDelay; i++ {
_, err := st.miner.AddBlock()
if err != nil {
return nil, err
}
}
return st, nil
}
示例3: newRenterTester
// newRenterTester creates a ready-to-use renter tester with money in the
// wallet.
func newRenterTester(name string) (*renterTester, error) {
// Create the modules.
testdir := build.TempDir("renter", name)
g, err := gateway.New("localhost:0", false, filepath.Join(testdir, modules.GatewayDir))
if err != nil {
return nil, err
}
cs, err := consensus.New(g, false, filepath.Join(testdir, modules.ConsensusDir))
if err != nil {
return nil, err
}
tp, err := transactionpool.New(cs, g, filepath.Join(testdir, modules.TransactionPoolDir))
if err != nil {
return nil, err
}
w, err := wallet.New(cs, tp, filepath.Join(testdir, modules.WalletDir))
if err != nil {
return nil, err
}
key, err := crypto.GenerateTwofishKey()
if err != nil {
return nil, err
}
_, err = w.Encrypt(key)
if err != nil {
return nil, err
}
err = w.Unlock(key)
if err != nil {
return nil, err
}
r, err := New(cs, w, tp, filepath.Join(testdir, modules.RenterDir))
if err != nil {
return nil, err
}
m, err := miner.New(cs, tp, w, filepath.Join(testdir, modules.MinerDir))
if err != nil {
return nil, err
}
// Assemble all pieces into a renter tester.
rt := &renterTester{
cs: cs,
gateway: g,
miner: m,
tpool: tp,
wallet: w,
renter: r,
}
// Mine blocks until there is money in the wallet.
for i := types.BlockHeight(0); i <= types.MaturityDelay; i++ {
_, err := rt.miner.AddBlock()
if err != nil {
return nil, err
}
}
return rt, nil
}
示例4: createExplorerTester
// createExplorerTester creates a tester object for the explorer module.
func createExplorerTester(name string) (*explorerTester, error) {
// Create and assemble the dependencies.
testdir := build.TempDir(modules.HostDir, name)
g, err := gateway.New(":0", filepath.Join(testdir, modules.GatewayDir))
if err != nil {
return nil, err
}
cs, err := consensus.New(g, filepath.Join(testdir, modules.ConsensusDir))
if err != nil {
return nil, err
}
tp, err := transactionpool.New(cs, g)
if err != nil {
return nil, err
}
w, err := wallet.New(cs, tp, filepath.Join(testdir, modules.WalletDir))
if err != nil {
return nil, err
}
key, err := crypto.GenerateTwofishKey()
if err != nil {
return nil, err
}
_, err = w.Encrypt(key)
if err != nil {
return nil, err
}
err = w.Unlock(key)
if err != nil {
return nil, err
}
m, err := miner.New(cs, tp, w, filepath.Join(testdir, modules.RenterDir))
if err != nil {
return nil, err
}
e, err := New(cs, filepath.Join(testdir, modules.ExplorerDir))
if err != nil {
return nil, err
}
et := &explorerTester{
cs: cs,
gateway: g,
miner: m,
tpool: tp,
wallet: w,
walletKey: key,
explorer: e,
}
// Mine until the wallet has money.
for i := types.BlockHeight(0); i <= types.MaturityDelay; i++ {
b, _ := et.miner.FindBlock()
err = et.cs.AcceptBlock(b)
if err != nil {
return nil, err
}
}
return et, nil
}
示例5: createConsensusSetTester
// createConsensusSetTester creates a consensusSetTester that's ready for use.
func createConsensusSetTester(name string) (*consensusSetTester, error) {
testdir := build.TempDir(modules.ConsensusDir, name)
// Create modules.
g, err := gateway.New(":0", filepath.Join(testdir, modules.GatewayDir))
if err != nil {
return nil, err
}
cs, err := New(g, filepath.Join(testdir, modules.ConsensusDir))
if err != nil {
return nil, err
}
tp, err := transactionpool.New(cs, g)
if err != nil {
return nil, err
}
w, err := wallet.New(cs, tp, filepath.Join(testdir, modules.WalletDir))
if err != nil {
return nil, err
}
key, err := crypto.GenerateTwofishKey()
if err != nil {
return nil, err
}
_, err = w.Encrypt(key)
if err != nil {
return nil, err
}
err = w.Unlock(key)
if err != nil {
return nil, err
}
m, err := miner.New(cs, tp, w, filepath.Join(testdir, modules.MinerDir))
if err != nil {
return nil, err
}
// Assemble all objects into a consensusSetTester.
cst := &consensusSetTester{
gateway: g,
miner: m,
tpool: tp,
wallet: w,
walletKey: key,
cs: cs,
persistDir: testdir,
}
// Mine until the wallet has money.
for i := types.BlockHeight(0); i <= types.MaturityDelay; i++ {
b, _ := cst.miner.FindBlock()
err = cst.cs.AcceptBlock(b)
if err != nil {
return nil, err
}
}
return cst, nil
}
示例6: newHostDBTester
// newHostDBTester creates a ready-to-use hostdb tester with money in the
// wallet.
func newHostDBTester(name string) (*hostdbTester, error) {
// Create the modules.
testdir := build.TempDir("hostdb", name)
g, err := gateway.New(":0", filepath.Join(testdir, modules.GatewayDir))
if err != nil {
return nil, err
}
cs, err := consensus.New(g, filepath.Join(testdir, modules.ConsensusDir))
if err != nil {
return nil, err
}
tp, err := transactionpool.New(cs, g)
if err != nil {
return nil, err
}
w, err := modWallet.New(cs, tp, filepath.Join(testdir, modules.WalletDir))
if err != nil {
return nil, err
}
key, err := crypto.GenerateTwofishKey()
if err != nil {
return nil, err
}
_, err = w.Encrypt(key)
if err != nil {
return nil, err
}
err = w.Unlock(key)
if err != nil {
return nil, err
}
hdb, err := New(cs, w, tp, filepath.Join(testdir, modules.RenterDir))
if err != nil {
return nil, err
}
m, err := miner.New(cs, tp, w, filepath.Join(testdir, modules.MinerDir))
if err != nil {
return nil, err
}
// Assemble all pieces into a hostdb tester.
ht := &hostdbTester{
cs: cs,
gateway: g,
miner: m,
tpool: tp,
wallet: w,
hostdb: hdb,
}
// Mine blocks until there is money in the wallet.
for i := types.BlockHeight(0); i <= types.MaturityDelay; i++ {
_, err := ht.miner.AddBlock()
if err != nil {
return nil, err
}
}
return ht, nil
}
示例7: newTestingWallet
// newTestingWallet is a helper function that creates a ready-to-use wallet
// and mines some coins into it.
func newTestingWallet(testdir string, cs modules.ConsensusSet, tp modules.TransactionPool) (modules.Wallet, error) {
w, err := modWallet.New(cs, tp, filepath.Join(testdir, modules.WalletDir))
if err != nil {
return nil, err
}
key, err := crypto.GenerateTwofishKey()
if err != nil {
return nil, err
}
if !w.Encrypted() {
_, err = w.Encrypt(key)
if err != nil {
return nil, err
}
}
err = w.Unlock(key)
if err != nil {
return nil, err
}
// give it some money
m, err := miner.New(cs, tp, w, filepath.Join(testdir, modules.MinerDir))
if err != nil {
return nil, err
}
for i := types.BlockHeight(0); i <= types.MaturityDelay; i++ {
_, err := m.AddBlock()
if err != nil {
return nil, err
}
}
return w, nil
}
示例8: newFile
// newFile creates a new file object.
func newFile(name string, code modules.ErasureCoder, pieceSize, fileSize uint64) *file {
key, _ := crypto.GenerateTwofishKey()
return &file{
name: name,
size: fileSize,
contracts: make(map[modules.NetAddress]fileContract),
masterKey: key,
erasureCode: code,
pieceSize: pieceSize,
}
}
示例9: createConsensusSetTester
// createConsensusSetTester creates a consensusSetTester that's ready for use.
func createConsensusSetTester(name string) (*consensusSetTester, error) {
testdir := build.TempDir(modules.ConsensusDir, name)
// Create modules.
g, err := gateway.New(":0", filepath.Join(testdir, modules.GatewayDir))
if err != nil {
return nil, err
}
cs, err := New(g, filepath.Join(testdir, modules.ConsensusDir))
if err != nil {
return nil, err
}
tp, err := transactionpool.New(cs, g)
if err != nil {
return nil, err
}
w, err := wallet.New(cs, tp, filepath.Join(testdir, modules.WalletDir))
if err != nil {
return nil, err
}
key, err := crypto.GenerateTwofishKey()
if err != nil {
return nil, err
}
_, err = w.Encrypt(key)
if err != nil {
return nil, err
}
err = w.Unlock(key)
if err != nil {
return nil, err
}
m, err := miner.New(cs, tp, w, filepath.Join(testdir, modules.MinerDir))
if err != nil {
return nil, err
}
// Assemble all objects into a consensusSetTester.
cst := &consensusSetTester{
gateway: g,
miner: m,
tpool: tp,
wallet: w,
walletKey: key,
cs: cs,
persistDir: testdir,
}
cst.addSiafunds()
cst.mineSiacoins()
return cst, nil
}
示例10: reorgToBlank
// reorgToBlank creates a bunch of empty blocks on top of the genesis block
// that reorgs the explorer to a state of all blank blocks.
func (et *explorerTester) reorgToBlank() error {
// Get a unique directory name to house the persistence of the miner
// dependencies.
dir := et.testdir + " - " + persist.RandomSuffix()
// Create a miner and all dependencies to create an alternate chain.
g, err := gateway.New("localhost:0", false, filepath.Join(dir, modules.GatewayDir))
if err != nil {
return err
}
cs, err := consensus.New(g, false, filepath.Join(dir, modules.ConsensusDir))
if err != nil {
return err
}
tp, err := transactionpool.New(cs, g, filepath.Join(dir, modules.TransactionPoolDir))
if err != nil {
return err
}
w, err := wallet.New(cs, tp, filepath.Join(dir, modules.WalletDir))
if err != nil {
return err
}
key, err := crypto.GenerateTwofishKey()
if err != nil {
return err
}
_, err = w.Encrypt(key)
if err != nil {
return err
}
err = w.Unlock(key)
if err != nil {
return err
}
m, err := miner.New(cs, tp, w, filepath.Join(dir, modules.RenterDir))
if err != nil {
return err
}
// Mine blocks until the height is higher than the existing consensus,
// submitting each block to the explorerTester.
currentHeight := cs.Height()
for i := types.BlockHeight(0); i <= currentHeight+1; i++ {
block, err := m.AddBlock()
if err != nil {
return err
}
et.cs.AcceptBlock(block) // error is not checked, will not always be nil
}
return nil
}
示例11: newTestingFile
// newTestingFile initializes a file object with random parameters.
func newTestingFile() *file {
key, _ := crypto.GenerateTwofishKey()
data, _ := crypto.RandBytes(8)
nData, _ := crypto.RandIntn(10)
nParity, _ := crypto.RandIntn(10)
rsc, _ := NewRSCode(nData+1, nParity+1)
return &file{
name: "testfile-" + strconv.Itoa(int(data[0])),
size: encoding.DecUint64(data[1:5]),
masterKey: key,
erasureCode: rsc,
pieceSize: encoding.DecUint64(data[6:8]),
}
}
示例12: initWallet
// initWallet creates a wallet key, initializes the host wallet, unlocks it,
// and then stores the key in the host tester.
func (ht *hostTester) initWallet() error {
// Create the keys for the wallet and unlock it.
key, err := crypto.GenerateTwofishKey()
if err != nil {
return err
}
ht.walletKey = key
_, err = ht.wallet.Encrypt(key)
if err != nil {
return err
}
err = ht.wallet.Unlock(key)
if err != nil {
return err
}
return nil
}
示例13: blankServerTester
// blankServerTester creates a server tester object that is ready for testing,
// without any money in the wallet.
func blankServerTester(name string) (*serverTester, error) {
// createServerTester is expensive, and therefore should not be called
// during short tests.
if testing.Short() {
panic("blankServerTester called during short tests")
}
// Create the server tester with key.
testdir := build.TempDir("api", name)
key, err := crypto.GenerateTwofishKey()
if err != nil {
return nil, err
}
st, err := assembleServerTester(key, testdir)
if err != nil {
return nil, err
}
return st, nil
}
示例14: createServerTester
// createServerTester creates a server tester object that is ready for testing,
// including money in the wallet and all modules initalized.
func createServerTester(name string) (*serverTester, error) {
// Create the testing directory.
testdir := build.TempDir("api", name)
key, err := crypto.GenerateTwofishKey()
if err != nil {
return nil, err
}
st, err := assembleServerTester(key, testdir)
if err != nil {
return nil, err
}
// Mine blocks until the wallet has confirmed money.
for i := types.BlockHeight(0); i <= types.MaturityDelay; i++ {
_, err := st.miner.AddBlock()
if err != nil {
return nil, err
}
}
return st, nil
}
示例15: TestIntegrationMinimumValidChildTimestamp
// TestIntegrationMinimumValidChildTimestamp probes the
// MinimumValidChildTimestamp method of the consensus type.
func TestIntegrationMinimumValidChildTimestamp(t *testing.T) {
if testing.Short() {
t.SkipNow()
}
t.Parallel()
// Create a custom consensus set to control the blocks.
testdir := build.TempDir(modules.ConsensusDir, "TestIntegrationMinimumValidChildTimestamp")
g, err := gateway.New("localhost:0", false, filepath.Join(testdir, modules.GatewayDir))
if err != nil {
t.Fatal(err)
}
cs, err := New(g, false, filepath.Join(testdir, modules.ConsensusDir))
if err != nil {
t.Fatal(err)
}
tp, err := transactionpool.New(cs, g, filepath.Join(testdir, modules.TransactionPoolDir))
if err != nil {
t.Fatal(err)
}
w, err := wallet.New(cs, tp, filepath.Join(testdir, modules.WalletDir))
if err != nil {
t.Fatal(err)
}
key, err := crypto.GenerateTwofishKey()
if err != nil {
t.Fatal(err)
}
_, err = w.Encrypt(key)
if err != nil {
t.Fatal(err)
}
err = w.Unlock(key)
if err != nil {
t.Fatal(err)
}
m, err := miner.New(cs, tp, w, filepath.Join(testdir, modules.MinerDir))
if err != nil {
t.Fatal(err)
}
defer g.Close()
// The earliest child timestamp of the genesis block should be the
// timestamp of the genesis block.
genesisTime := cs.blockRoot.Block.Timestamp
earliest, ok := cs.MinimumValidChildTimestamp(cs.blockRoot.Block.ID())
if !ok || genesisTime != earliest {
t.Error("genesis block earliest timestamp producing unexpected results")
}
timestampOffsets := []types.Timestamp{1, 3, 2, 5, 4, 6, 7, 8, 9, 10}
blockIDs := []types.BlockID{cs.blockRoot.Block.ID()}
for _, offset := range timestampOffsets {
bfw, target, err := m.BlockForWork()
if err != nil {
t.Fatal(err)
}
bfw.Timestamp = genesisTime + offset
solvedBlock, _ := m.SolveBlock(bfw, target)
err = cs.AcceptBlock(solvedBlock)
if err != nil {
t.Fatal(err)
}
blockIDs = append(blockIDs, solvedBlock.ID())
}
// Median should be genesisTime for 6th block.
earliest, ok = cs.MinimumValidChildTimestamp(blockIDs[5])
if !ok || earliest != genesisTime {
t.Error("incorrect child timestamp")
}
// Median should be genesisTime+1 for 7th block.
earliest, ok = cs.MinimumValidChildTimestamp(blockIDs[6])
if !ok || earliest != genesisTime+1 {
t.Error("incorrect child timestamp")
}
// Median should be genesisTime + 5 for pb11.
earliest, ok = cs.MinimumValidChildTimestamp(blockIDs[10])
if !ok || earliest != genesisTime+5 {
t.Error("incorrect child timestamp")
}
}