本文整理汇总了Golang中github.com/skycoin/skycoin/src/wallet.NewWalletEntry函数的典型用法代码示例。如果您正苦于以下问题:Golang NewWalletEntry函数的具体用法?Golang NewWalletEntry怎么用?Golang NewWalletEntry使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewWalletEntry函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: makeMoreBlocks
func makeMoreBlocks(t *testing.T, mv *Visor, n int, when uint64) []SignedBlock {
dest := wallet.NewWalletEntry()
blocks := make([]SignedBlock, 0, n)
for i := 0; i < n; i++ {
tx, err := mv.Spend(mv.Wallets[0].GetID(), wallet.Balance{10 * 1e6, 0},
0, dest.Address)
assert.Nil(t, err)
if err != nil {
return nil
}
mv.RecordTxn(tx)
assert.Equal(t, len(mv.Unconfirmed.Txns), 1)
sb, err := mv.CreateBlock(when + 1 + uint64(i))
assert.Nil(t, err)
if err != nil {
return nil
}
err = mv.ExecuteSignedBlock(sb)
assert.Nil(t, err)
if err != nil {
return nil
}
assert.Equal(t, len(mv.Unconfirmed.Txns), 0)
blocks = append(blocks, sb)
}
return blocks
}
示例2: makeValidTxnNoError
func makeValidTxnNoError(t *testing.T, mv *visor.Visor) coin.Transaction {
we := wallet.NewWalletEntry()
tx, err := mv.Spend(mv.Wallets[0].GetID(), visor.Balance{10 * 1e6, 0}, 0,
we.Address)
assert.Nil(t, err)
return tx
}
示例3: makeValidTxnWithFeeFactorAndExtraChange
func makeValidTxnWithFeeFactorAndExtraChange(mv *Visor,
factor, extra, change uint64) (coin.Transaction, error) {
we := wallet.NewWalletEntry()
tmp := mv.Config.CoinHourBurnFactor
mv.Config.CoinHourBurnFactor = factor
tx, err := mv.Spend(mv.Wallets[0].GetID(), wallet.Balance{10 * 1e6, 1002},
extra, we.Address)
mv.Config.CoinHourBurnFactor = tmp
return tx, err
}
示例4: newDefaultDaemon
func newDefaultDaemon() *Daemon {
cleanupPeers()
c := NewConfig()
we := wallet.NewWalletEntry()
c.Visor.Config.MasterKeys = we
c.Visor.Config.GenesisSignature = createGenesisSignature(we)
c.Visor.Disabled = true
c.DHT.Disabled = true
return NewDaemon(c)
}
示例5: makeInvalidTxn
func makeInvalidTxn(mv *Visor) (coin.Transaction, error) {
we := wallet.NewWalletEntry()
txn, err := mv.Spend(mv.Wallets[0].GetID(), wallet.Balance{10 * 1e6, 0}, 0,
we.Address)
if err != nil {
return txn, err
}
txn.Out[0].Address = cipher.Address{}
return txn, nil
}
示例6: setupMasterVisor
func setupMasterVisor() VisorConfig {
cleanupVisor()
coin.SetAddressVersion("test")
c := NewVisorConfig()
c.Config.IsMaster = true
mw := wallet.NewWalletEntry()
c.Config.MasterKeys = mw
c.Config.GenesisSignature = createGenesisSignature(mw)
return c
}
示例7: setupMasterVisorConfig
func setupMasterVisorConfig() VisorConfig {
// Create testmaster.keys file
c := NewVisorConfig()
c.CoinHourBurnFactor = 0
c.IsMaster = true
mw := wallet.NewWalletEntry()
c.MasterKeys = mw
c.GenesisSignature = createGenesisSignature(mw)
return c
}
示例8: TestVisorSpend
func TestVisorSpend(t *testing.T) {
defer cleanupVisor()
we := wallet.NewWalletEntry()
addr := we.Address
vc := newMasterVisorConfig(t)
assert.Equal(t, vc.CoinHourBurnFactor, uint64(0))
v := NewVisor(vc)
wid := v.Wallets[0].GetFilename()
ogb := v.WalletBalance(wid).Confirmed
// Test spend 0 amount
v = NewVisor(vc)
b = wallet.Balance{0, 0}
_, err = v.Spend(v.Wallets[0].GetFilename(), b, 0, addr)
assert.NotNil(t, err)
assert.Equal(t, err.Error(), "Zero spend amount")
// Test lacking funds
v = NewVisor(vc)
b = wallet.Balance{10e16, 10e16}
_, err = v.Spend(v.Wallets[0].GetFilename(), b, 10e16, addr)
assert.NotNil(t, err)
assert.Equal(t, err.Error(), "Not enough coins")
// Test created txn too large
v = NewVisor(vc)
v.Config.MaxBlockSize = 0
b = wallet.Balance{10e6, 10}
assert.Panics(t, func() { v.Spend(v.Wallets[0].GetFilename(), b, 0, addr) })
// Test simple spend (we have only 1 address to spend from, no fee)
v = NewVisor(vc)
assert.Equal(t, v.Config.CoinHourBurnFactor, uint64(0))
b = wallet.Balance{10e6, 10}
tx, err := v.Spend(v.Wallets[0].GetFilename(), b, 0, addr)
assert.Nil(t, err)
assert.Equal(t, len(tx.In), 1)
assert.Equal(t, len(tx.Out), 2)
// Hash should be updated
assert.NotEqual(t, tx.Head.Hash, cipher.SHA256{})
// Should be 1 signature for the single input
assert.Equal(t, len(tx.Head.Sigs), 1)
// Spent amount should be correct
assert.Equal(t, tx.Out[1].Address, addr)
assert.Equal(t, tx.Out[1].Coins, b.Coins)
assert.Equal(t, tx.Out[1].Hours, b.Hours)
// Change amount should be correct
ourAddr := v.Wallets[0].GetAddresses()[0]
assert.Equal(t, tx.Out[0].Address, ourAddr)
assert.Equal(t, tx.Out[0].Coins, ogb.Coins-b.Coins)
assert.Equal(t, tx.Out[0].Hours, ogb.Hours-b.Hours)
assert.Nil(t, tx.Verify())
}
示例9: TestLoadBlockchainPrivate
func TestLoadBlockchainPrivate(t *testing.T) {
defer cleanupVisor()
cleanupVisor()
we := wallet.NewWalletEntry()
// No filename should return fresh blockchain
bc := loadBlockchain("", we.Address)
assert.Equal(t, len(bc.Blocks), 0)
// Filename with no file should return fresh blockchain
assertFileNotExists(t, testBlockchainFile)
bc = loadBlockchain(testBlockchainFile, we.Address)
assert.Equal(t, len(bc.Blocks), 0)
// Loading an empty blockchain should panic
assert.Nil(t, SaveBlockchain(bc, testBlockchainFile))
assertFileExists(t, testBlockchainFile)
assert.Panics(t, func() {
loadBlockchain(testBlockchainFile, we.Address)
})
// Loading a blockchain with a different genesis address should panic
vc := newMasterVisorConfig(t)
bc.CreateGenesisBlock(vc.MasterKeys.Address, 0, 100e6)
assert.Equal(t, len(bc.Blocks), 1)
assert.Nil(t, SaveBlockchain(bc, testBlockchainFile))
assertFileExists(t, testBlockchainFile)
assert.Panics(t, func() {
loadBlockchain(testBlockchainFile, coin.Address{})
})
// Loading a corrupt blockchain should panic
corruptFile(t, testBlockchainFile)
assert.Panics(t, func() {
loadBlockchain(testBlockchainFile, we.Address)
})
cleanupVisor()
// Loading a valid blockchain should be safe
vc = newMasterVisorConfig(t)
vc.BlockchainFile = testBlockchainFile
v := NewVisor(vc)
assert.Nil(t, transferCoinsToSelf(v, v.Config.MasterKeys.Address))
assert.Equal(t, len(v.blockchain.Blocks), 2)
assert.Nil(t, v.SaveBlockchain())
assertFileExists(t, testBlockchainFile)
bc = loadBlockchain(testBlockchainFile, v.Config.MasterKeys.Address)
assert.Equal(t, v.blockchain, bc)
}
示例10: TestCreateMasterWallet
func TestCreateMasterWallet(t *testing.T) {
defer cleanupVisor()
cleanupVisor()
we := wallet.NewWalletEntry()
w := CreateMasterWallet(we)
assert.Equal(t, w.NumEntries(), 1)
assert.Equal(t, w.GetAddresses()[0], we.Address)
// Having a wallet file present should not affect loading master wallet
w.Save(testWalletFile)
we = wallet.NewWalletEntry()
w = CreateMasterWallet(we)
assert.Equal(t, w.NumEntries(), 1)
assert.Equal(t, w.GetAddresses()[0], we.Address)
// Creating with an invalid wallet entry should panic
we = wallet.NewWalletEntry()
we.Secret = cipher.SecKey{}
assert.Panics(t, func() { CreateMasterWallet(we) })
we = wallet.NewWalletEntry()
we.Public = cipher.PubKey{}
assert.Panics(t, func() { CreateMasterWallet(we) })
}
示例11: addSignedBlockAt
func addSignedBlockAt(t *testing.T, v *Visor, when uint64) SignedBlock {
we := wallet.NewWalletEntry()
tx, err := v.Spend(v.Wallets[0].GetFilename(), wallet.Balance{1e6, 0}, 0, we.Address)
assert.Nil(t, err)
err, known := v.InjectTxn(tx)
assert.Nil(t, err)
assert.False(t, known)
sb, err := v.CreateBlock(when)
assert.Nil(t, err)
if err != nil {
return sb
}
err = v.ExecuteSignedBlock(sb)
assert.Nil(t, err)
return sb
}
示例12: setupVisorConfig
// Returns an appropriate VisorConfig and a master visor
func setupVisorConfig() (VisorConfig, *Visor) {
// Make a new master visor + blockchain
// Get the signed genesis block,
mw := wallet.NewWalletEntry()
mvc := NewVisorConfig()
mvc.CoinHourBurnFactor = 0
mvc.IsMaster = true
mvc.MasterKeys = mw
mvc.GenesisSignature = createGenesisSignature(mw)
mv := NewVisor(mvc)
// Use the master values for a client configuration
c := NewVisorConfig()
c.IsMaster = false
c.GenesisSignature = mvc.GenesisSignature
c.GenesisTimestamp = mvc.GenesisTimestamp
c.MasterKeys = mw
c.MasterKeys.Secret = cipher.SecKey{}
c.WalletDirectory = testWalletDir
return c, mv
}
示例13: makeMoreBlocks
func makeMoreBlocks(mv *visor.Visor, n int,
now uint64) ([]visor.SignedBlock, error) {
dest := wallet.NewWalletEntry()
blocks := make([]visor.SignedBlock, n)
for i := 0; i < n; i++ {
tx, err := mv.Spend(mv.Wallets[0].GetID(), visor.Balance{10 * 1e6, 0},
0, dest.Address)
if err != nil {
return nil, err
}
mv.RecordTxn(tx)
sb, err := mv.CreateBlock(now + uint64(i) + 1)
if err != nil {
return nil, err
}
err = mv.ExecuteSignedBlock(sb)
if err != nil {
return nil, err
}
blocks[i] = sb
}
return blocks, nil
}
示例14: TestCreateAndPublishBlock
func TestCreateAndPublishBlock(t *testing.T) {
defer cleanupVisor()
defer gnet.EraseMessages()
p, gc := setupPool()
vc, mv := setupVisor()
dest := wallet.NewWalletEntry()
go p.Pool.ConnectionWriteLoop(gc)
// Disabled
vc.Disabled = true
vc.Config = mv.Config
v := NewVisor(vc)
v.Visor = mv
err := v.CreateAndPublishBlock(p)
assert.NotNil(t, err)
wait()
assert.Equal(t, err.Error(), "Visor disabled")
assert.Equal(t, len(p.Pool.SendResults), 0)
assert.Equal(t, v.Visor.MostRecentBkSeq(), uint64(0))
// Created and sent
vc.Disabled = false
vc.Config.IsMaster = true
vc.Config = mv.Config
v = NewVisor(vc)
gc.Conn = NewDummyConn(addr)
_, err = v.Spend(v.Visor.Wallets[0].GetID(), visor.Balance{10 * 1e6, 0}, 0,
dest.Address, p)
assert.Nil(t, err)
wait()
assert.Equal(t, len(p.Pool.SendResults), 1)
if len(p.Pool.SendResults) == 0 {
t.Fatal("SendResults empty, would block")
}
<-p.Pool.SendResults
err = v.CreateAndPublishBlock(p)
wait()
assert.Nil(t, err)
wait()
assert.Equal(t, len(p.Pool.SendResults), 1)
if len(p.Pool.SendResults) == 0 {
t.Fatal("SendResults empty, would block")
}
sr := <-p.Pool.SendResults
assert.Nil(t, sr.Error)
assert.Equal(t, sr.Connection, gc)
_, ok := sr.Message.(*GiveBlocksMessage)
assert.True(t, ok)
assert.Equal(t, v.Visor.MostRecentBkSeq(), uint64(1))
// Can't create, don't have coins
// First, spend all of our coins
// vc2, _ := setupVisor()
// vc2.Config.GenesisSignature = vc.Config.GenesisSignature
// vc2.Config.MasterKeys = vc.Config.MasterKeys
// vc2.Config.IsMaster = true
// vc2.Disabled = false
vc.Config.IsMaster = true
vc.Disabled = false
v = NewVisor(vc)
tx, err := v.Spend(v.Visor.Wallets[0].GetID(),
visor.Balance{vc.Config.GenesisCoinVolume, 0},
vc.Config.GenesisCoinVolume, dest.Address, p)
mv.RecordTxn(tx)
wait()
assert.Nil(t, err)
assert.Equal(t, len(p.Pool.SendResults), 1)
for len(p.Pool.SendResults) > 0 {
<-p.Pool.SendResults
}
err = v.CreateAndPublishBlock(p)
assert.Nil(t, err)
wait()
assert.Equal(t, len(p.Pool.SendResults), 1)
for len(p.Pool.SendResults) > 0 {
<-p.Pool.SendResults
}
// No coins to spend, fail
assert.Equal(t, v.Visor.MostRecentBkSeq(), uint64(1))
_, err = v.Spend(v.Visor.Wallets[0].GetID(), visor.Balance{10 * 1e6, 0}, 0,
dest.Address, p)
assert.NotNil(t, err)
wait()
assert.Equal(t, len(p.Pool.SendResults), 0)
err = v.CreateAndPublishBlock(p)
assert.NotNil(t, err)
wait()
assert.Equal(t, len(p.Pool.SendResults), 0)
assert.Equal(t, v.Visor.MostRecentBkSeq(), uint64(1))
}
示例15: newWalletEntry
func newWalletEntry(t *testing.T) wallet.WalletEntry {
we := wallet.NewWalletEntry()
assert.Nil(t, we.Verify())
return we
}