本文整理汇总了Golang中github.com/skycoin/skycoin/src/util.UnixNow函数的典型用法代码示例。如果您正苦于以下问题:Golang UnixNow函数的具体用法?Golang UnixNow怎么用?Golang UnixNow使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了UnixNow函数的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestVisorVerifySignedBlock
func TestVisorVerifySignedBlock(t *testing.T) {
defer cleanupVisor()
vc := newMasterVisorConfig(t)
v := NewVisor(vc)
w := v.Wallets[0]
we := w.CreateEntry()
// Master should verify its own blocks correctly
txn, err := v.Spend(w.GetFilename(), wallet.Balance{1e6, 0}, 0, we.Address)
assert.Nil(t, err)
err, known := v.InjectTxn(txn)
assert.Nil(t, err)
assert.False(t, known)
b, err := v.CreateBlock(uint64(util.UnixNow()))
assert.Nil(t, err)
assert.Nil(t, v.verifySignedBlock(&b))
badb := b
badb.Sig = cipher.Sig{}
assert.NotNil(t, v.verifySignedBlock(&badb))
// Non master should verify signed blocks generated by master
mv := v
v = setupVisorFromMaster(mv)
assert.Nil(t, v.verifySignedBlock(&b))
assert.NotNil(t, v.verifySignedBlock(&badb))
}
示例2: CreateAndExecuteBlock
// Creates a SignedBlock from pending transactions and executes it
func (self *Visor) CreateAndExecuteBlock() (SignedBlock, error) {
sb, err := self.CreateBlock(uint64(util.UnixNow()))
if err == nil {
return sb, self.ExecuteSignedBlock(sb)
} else {
return sb, err
}
}
示例3: CreateAndExecuteBlock
// CreateAndExecuteBlock creates a SignedBlock from pending transactions and executes it
func (vs *Visor) CreateAndExecuteBlock() (coin.SignedBlock, error) {
sb, err := vs.CreateBlock(uint64(util.UnixNow()))
if err == nil {
return sb, vs.ExecuteSignedBlock(sb)
}
return sb, err
}
示例4: addSignedBlocks
func addSignedBlocks(t *testing.T, v *Visor, n int) []SignedBlock {
sbs := make([]SignedBlock, n)
now := uint64(util.UnixNow())
for i := 0; i < n; i++ {
sbs[i] = addSignedBlockAt(t, v, now+1+uint64(i))
}
return sbs
}
示例5: CreateFreshGenesisBlock
func (self *Visor) CreateFreshGenesisBlock() (SignedBlock, error) {
if len(self.blockchain.Blocks) != 0 || len(self.blockSigs.Sigs) != 0 {
log.Panic("Blockchain already has genesis")
}
gb := self.blockchain.CreateGenesisBlock(self.Config.MasterKeys.Address,
uint64(util.UnixNow()), self.Config.GenesisCoinVolume)
sb := self.SignBlock(gb)
if err := self.verifySignedBlock(&sb); err != nil {
log.Panic("Signed a fresh genesis block, but its invalid: %v", err)
}
self.blockSigs.record(&sb)
return sb, nil
}
示例6: transferCoinsAdvanced
func transferCoinsAdvanced(mv *Visor, v *Visor, b Balance, fee uint64,
addr coin.Address) error {
tx, err := mv.Spend(b, fee, addr)
if err != nil {
return err
}
mv.RecordTxn(tx)
now := uint64(util.UnixNow())
if len(mv.blockchain.Blocks) > 0 {
now = mv.blockchain.Time() + 1
}
sb, err := mv.CreateBlock(now)
if err != nil {
return err
}
err = mv.ExecuteSignedBlock(sb)
if err != nil {
return err
}
return v.ExecuteSignedBlock(sb)
}
示例7: transferCoinsAdvanced
func transferCoinsAdvanced(mv *Visor, v *Visor, b wallet.Balance, fee uint64,
addr cipher.Address) error {
tx, err := mv.Spend(mv.Wallets[0].GetFilename(), b, fee, addr)
if err != nil {
return err
}
mv.InjectTxn(tx)
now := uint64(util.UnixNow())
if len(mv.blockchain.Blocks) > 0 {
now = mv.blockchain.Time() + 1
}
sb, err := mv.CreateBlock(now)
if err != nil {
return err
}
err = mv.ExecuteSignedBlock(sb)
if err != nil {
return err
}
return v.ExecuteSignedBlock(sb)
}
示例8: makeBlocks
func makeBlocks(mv *visor.Visor, n int) ([]visor.SignedBlock, error) {
return makeMoreBlocks(mv, n, uint64(util.UnixNow()))
}
示例9: makeBlocks
func makeBlocks(t *testing.T, mv *Visor, n int) []SignedBlock {
return makeMoreBlocks(t, mv, n, uint64(util.UnixNow()))
}
示例10: TestExecuteSignedBlock
func TestExecuteSignedBlock(t *testing.T) {
defer cleanupVisor()
cleanupVisor()
we := wallet.NewWalletEntry()
vc := newMasterVisorConfig(t)
v := NewVisor(vc)
wid := v.Wallets[0].GetFilename()
assert.Equal(t, len(v.Unconfirmed.Txns), 0)
tx, err := v.Spend(wid, wallet.Balance{1e6, 0}, 0, we.Address)
assert.Nil(t, err)
err, known := v.InjectTxn(tx)
assert.Nil(t, err)
assert.False(t, known)
assert.Equal(t, len(v.Unconfirmed.Txns), 1)
assert.Equal(t, len(v.blockSigs.Sigs), 1)
now := uint64(util.UnixNow())
// Invalid signed block
sb, err := v.CreateBlock(now)
assert.Equal(t, len(v.blockSigs.Sigs), 1)
assert.Nil(t, err)
sb.Sig = cipher.Sig{}
err = v.ExecuteSignedBlock(sb)
assert.NotNil(t, err)
assert.Equal(t, len(v.Unconfirmed.Txns), 1)
assert.Equal(t, len(v.blockSigs.Sigs), 1)
// Invalid block
sb, err = v.CreateBlock(now)
assert.Nil(t, err)
// TODO -- empty BodyHash is being accepted, fix blockchain verification
sb.Block.Head.BodyHash = cipher.SHA256{}
sb.Block.Body.Transactions = make(coin.Transactions, 0)
sb = v.SignBlock(sb.Block)
err = v.ExecuteSignedBlock(sb)
assert.NotNil(t, err)
assert.Equal(t, len(v.Unconfirmed.Txns), 1)
assert.Equal(t, len(v.blockSigs.Sigs), 1)
// Valid block
sb, err = v.CreateBlock(now)
assert.Nil(t, err)
err = v.ExecuteSignedBlock(sb)
assert.Nil(t, err)
assert.Equal(t, len(v.blockSigs.Sigs), 2)
assert.Equal(t, v.blockSigs.Sigs[uint64(1)], sb.Sig)
assert.Equal(t, v.blockchain.Blocks[1], sb.Block)
assert.Equal(t, len(v.Unconfirmed.Txns), 0)
// Test a valid block created by a master but executing in non master
vc2, mv := setupVisorConfig()
v2 := NewVisor(vc2)
w := v2.Wallets[0]
addr := w.GetAddresses()[0]
tx, err = mv.Spend(mv.Wallets[0].GetFilename(), wallet.Balance{1e6, 0}, 0, addr)
assert.Nil(t, err)
err, known = mv.InjectTxn(tx)
assert.Nil(t, err)
assert.False(t, known)
sb, err = mv.CreateAndExecuteBlock()
assert.Nil(t, err)
err = v2.ExecuteSignedBlock(sb)
assert.Nil(t, err)
assert.Equal(t, len(v2.blockSigs.Sigs), 2)
assert.Equal(t, v2.blockSigs.Sigs[uint64(1)], sb.Sig)
assert.Equal(t, v2.blockchain.Blocks[1], sb.Block)
assert.Equal(t, len(v2.Unconfirmed.Txns), 0)
}
示例11: addSignedBlock
func addSignedBlock(t *testing.T, v *Visor) SignedBlock {
return addSignedBlockAt(t, v, uint64(util.UnixNow()))
}