當前位置: 首頁>>代碼示例>>Golang>>正文


Golang util.UnixNow函數代碼示例

本文整理匯總了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;未經允許,請勿轉載。