本文整理汇总了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))
}
开发者ID:Chao-Jia,项目名称:skycoin,代码行数:26,代码来源:visor_test.go
示例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
}
}
开发者ID:keepwalking1234,项目名称:skycoin,代码行数:9,代码来源:visor.go
示例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
}
开发者ID:skycoin,项目名称:skycoin,代码行数:9,代码来源:visor.go
示例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
}
开发者ID:Chao-Jia,项目名称:skycoin,代码行数:8,代码来源:visor_test.go
示例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
}
开发者ID:JmAbuDabi,项目名称:skycoin,代码行数:13,代码来源:visor.go
示例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)
}
开发者ID:RagnarDanneskjold,项目名称:skycoin,代码行数:21,代码来源:readable_test.go
示例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)
}
开发者ID:keepwalking1234,项目名称:skycoin,代码行数:21,代码来源:readable_test.go
示例8: makeBlocks
func makeBlocks(mv *visor.Visor, n int) ([]visor.SignedBlock, error) {
return makeMoreBlocks(mv, n, uint64(util.UnixNow()))
}
开发者ID:notsoshifty,项目名称:skycoin,代码行数:3,代码来源:visor_test.go
示例9: makeBlocks
func makeBlocks(t *testing.T, mv *Visor, n int) []SignedBlock {
return makeMoreBlocks(t, mv, n, uint64(util.UnixNow()))
}
开发者ID:kinghuabg,项目名称:skycoin,代码行数:3,代码来源:blocksigs_test.go
示例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)
}
开发者ID:Chao-Jia,项目名称:skycoin,代码行数:68,代码来源:visor_test.go
示例11: addSignedBlock
func addSignedBlock(t *testing.T, v *Visor) SignedBlock {
return addSignedBlockAt(t, v, uint64(util.UnixNow()))
}
开发者ID:Chao-Jia,项目名称:skycoin,代码行数:3,代码来源:visor_test.go
注:本文中的github.com/skycoin/skycoin/src/util.UnixNow函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论