当前位置: 首页>>代码示例>>Golang>>正文


Golang util.Now函数代码示例

本文整理汇总了Golang中github.com/skycoin/skycoin/src/util.Now函数的典型用法代码示例。如果您正苦于以下问题:Golang Now函数的具体用法?Golang Now怎么用?Golang Now使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了Now函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: TestSetAnnounced

func TestSetAnnounced(t *testing.T) {
	ut := NewUnconfirmedTxnPool()
	assert.Equal(t, len(ut.Txns), 0)
	// Unknown should be safe and a noop
	assert.NotPanics(t, func() {
		ut.SetAnnounced(cipher.SHA256{}, util.Now())
	})
	assert.Equal(t, len(ut.Txns), 0)
	utx := createUnconfirmedTxn()
	assert.True(t, utx.Announced.IsZero())
	ut.Txns[utx.Hash()] = utx
	now := util.Now()
	ut.SetAnnounced(utx.Hash(), now)
	assert.Equal(t, ut.Txns[utx.Hash()].Announced, now)
}
开发者ID:skycoin,项目名称:skycoin,代码行数:15,代码来源:unconfirmed_test.go

示例2: RecordTxn

// Adds a coin.Transaction to the pool, or updates an existing one's timestamps
// Returns an error if txn is invalid, and whether the transaction already
// existed in the pool.
func (self *UnconfirmedTxnPool) RecordTxn(bc *coin.Blockchain,
	t coin.Transaction, addrs map[cipher.Address]byte, maxSize int,
	burnFactor uint64) (error, bool) {
	if err := VerifyTransaction(bc, &t, maxSize, burnFactor); err != nil {
		return err, false
	}
	if err := bc.VerifyTransaction(t); err != nil {
		return err, false
	}

	// Update if we already have this txn
	h := t.Hash()
	ut, ok := self.Txns[h]
	if ok {
		now := util.Now()
		ut.Received = now
		ut.Checked = now
		self.Txns[h] = ut
		return nil, true
	}

	// Add txn to index
	self.Txns[h] = self.createUnconfirmedTxn(&bc.Unspent, t, addrs)
	// Add predicted unspents
	self.Unspent[h] = coin.CreateUnspents(bc.Head().Head, t)

	return nil, false
}
开发者ID:JmAbuDabi,项目名称:skycoin,代码行数:31,代码来源:unconfirmed.go

示例3: InjectTxn

// InjectTxn adds a coin.Transaction to the pool, or updates an existing one's timestamps
// Returns an error if txn is invalid, and whether the transaction already
// existed in the pool.
func (utp *UnconfirmedTxnPool) InjectTxn(bc *Blockchain,
	t coin.Transaction) (error, bool) {

	if err := t.Verify(); err != nil {
		return err, false
	}

	if err := VerifyTransactionFee(bc, &t); err != nil {
		return err, false
	}
	if err := bc.VerifyTransaction(t); err != nil {
		return err, false
	}

	// Update if we already have this txn
	h := t.Hash()
	ut, ok := utp.Txns[h]
	if ok {
		now := util.Now()
		ut.Received = now
		ut.Checked = now
		utp.Txns[h] = ut
		return nil, true
	}

	// Add txn to index
	unspent := bc.GetUnspent()
	utp.Txns[h] = utp.createUnconfirmedTxn(unspent, t)
	// Add predicted unspents
	utp.Unspent[h] = coin.CreateUnspents(bc.Head().Head, t)

	return nil, false
}
开发者ID:skycoin,项目名称:skycoin,代码行数:36,代码来源:unconfirmed.go

示例4: RecordTxn

// Adds a coin.Transaction to the pool, or updates an existing one's timestamps
// Returns an error if txn is invalid, and whether the transaction already
// existed in the pool.
func (self *UnconfirmedTxnPool) RecordTxn(bc *coin.Blockchain,
	t coin.Transaction, addrs map[coin.Address]byte, maxSize int,
	burnFactor uint64) (error, bool) {
	if err := VerifyTransaction(bc, &t, maxSize, burnFactor); err != nil {
		return err, false
	}
	if err := bc.VerifyTransaction(t); err != nil {
		return err, false
	}

	// Update if we already have this txn
	ut, ok := self.Txns[t.Hash()]
	if ok {
		now := util.Now()
		ut.Received = now
		ut.Checked = now
		self.Txns[ut.Txn.Hash()] = ut
		return nil, true
	}

	// Add txn to index
	self.Txns[t.Hash()] = self.createUnconfirmedTxn(&bc.Unspent, t, addrs)
	// Add predicted unspents
	uxs := coin.CreateExpectedUnspents(t)
	for i, _ := range uxs {
		self.Unspent.Add(uxs[i])
	}

	return nil, false
}
开发者ID:up4k,项目名称:skycoin,代码行数:33,代码来源:unconfirmed.go

示例5: createUnconfirmedTxn

// Creates an unconfirmed transaction
func (self *UnconfirmedTxnPool) createUnconfirmedTxn(bcUnsp *coin.UnspentPool,
	t coin.Transaction, addrs map[coin.Address]byte) UnconfirmedTxn {
	now := util.Now()
	ut := UnconfirmedTxn{
		Txn:          t,
		Received:     now,
		Checked:      now,
		Announced:    util.ZeroTime(),
		IsOurReceive: false,
		IsOurSpend:   false,
	}

	// Check if this unspent is related to us
	if addrs != nil {
		// Check if this is one of our receiving txns
		for i, _ := range t.Out {
			if _, ok := addrs[t.Out[i].Address]; ok {
				ut.IsOurReceive = true
				break
			}
		}
		// Check if this is one of our spending txns
		for i, _ := range t.In {
			if ux, ok := bcUnsp.Get(t.In[i]); ok {
				if _, ok := addrs[ux.Body.Address]; ok {
					ut.IsOurSpend = true
					break
				}
			}
		}
	}

	return ut
}
开发者ID:up4k,项目名称:skycoin,代码行数:35,代码来源:unconfirmed.go

示例6: main

func main() {
	flag.Parse()

	if len(*host) == 0 {
		log.Fatalf("Missing required -host parameter")
	}

	var err error
	var notBefore time.Time
	if len(*validFrom) == 0 {
		notBefore = util.Now()
	} else {
		notBefore, err = time.Parse("Jan 2 15:04:05 2006", *validFrom)
		if err != nil {
			fmt.Fprintf(os.Stderr, "Failed to parse creation date: %v\n", err)
			os.Exit(1)
		}
	}

	err = util.GenerateCert(*certFile, *keyFile, *host, *organization, *rsaBits,
		*isCA, notBefore, *validFor)
	if err == nil {
		fmt.Printf("Created %s and %s\n", *certFile, *keyFile)
	} else {
		fmt.Fprintln(os.Stderr, "Failed to create cert and key")
		fmt.Fprintln(os.Stderr, err)
		os.Exit(1)
	}
}
开发者ID:JmAbuDabi,项目名称:skycoin,代码行数:29,代码来源:cert.go

示例7: sendPings

// Send a ping if our last message sent was over pingRate ago
func (self *Pool) sendPings() {
	now := util.Now()
	for _, c := range self.Pool.Pool {
		if c.LastSent.Add(self.Config.PingRate).Before(now) {
			self.Pool.SendMessage(c, &PingMessage{})
		}
	}
}
开发者ID:RagnarDanneskjold,项目名称:skycoin,代码行数:9,代码来源:pool.go

示例8: clearStaleConnections

// Removes connections that have not sent a message in too long
func (self *Pool) clearStaleConnections() {
	now := util.Now()
	for _, c := range self.Pool.Pool {
		if c.LastReceived.Add(self.Config.IdleLimit).Before(now) {
			self.Pool.Disconnect(c, DisconnectIdle)
		}
	}
}
开发者ID:RagnarDanneskjold,项目名称:skycoin,代码行数:9,代码来源:pool.go

示例9: createUnconfirmedTxn

func createUnconfirmedTxn() UnconfirmedTxn {
	ut := UnconfirmedTxn{}
	ut.Txn = coin.Transaction{}
	ut.Txn.Head.Hash = randSHA256()
	ut.Received = util.Now()
	ut.Checked = ut.Received
	ut.Announced = util.ZeroTime()
	return ut
}
开发者ID:JmAbuDabi,项目名称:skycoin,代码行数:9,代码来源:readable_test.go

示例10: TestGenerateCert

func TestGenerateCert(t *testing.T) {
	defer os.Remove("certtest.pem")
	defer os.Remove("keytest.pem")
	err := GenerateCert("certtest.pem", "keytest.pem", "127.0.0.1", "org",
		2048, false, util.Now(), time.Hour*24)
	assert.Nil(t, err)
	_, err = tls.LoadX509KeyPair("certtest.pem", "keytest.pem")
	assert.Nil(t, err)
}
开发者ID:RagnarDanneskjold,项目名称:skycoin,代码行数:9,代码来源:cert_test.go

示例11: createUnconfirmedTxn

// Creates an unconfirmed transaction
func (utp *UnconfirmedTxnPool) createUnconfirmedTxn(bcUnsp *coin.UnspentPool,
	t coin.Transaction) UnconfirmedTxn {
	now := util.Now()
	return UnconfirmedTxn{
		Txn:       t,
		Received:  now,
		Checked:   now,
		Announced: util.ZeroTime(),
	}
}
开发者ID:skycoin,项目名称:skycoin,代码行数:11,代码来源:unconfirmed.go

示例12: createUnconfirmedTxn

// Creates an unconfirmed transaction
func (self *UnconfirmedTxnPool) createUnconfirmedTxn(bcUnsp *coin.UnspentPool,
	t coin.Transaction, addrs map[coin.Address]byte) UnconfirmedTxn {
	now := util.Now()
	return UnconfirmedTxn{
		Txn:       t,
		Received:  now,
		Checked:   now,
		Announced: util.ZeroTime(),
	}
}
开发者ID:kinghuabg,项目名称:skycoin,代码行数:11,代码来源:unconfirmed.go

示例13: GetOldOwnedTransactions

// Returns transactions in which we are a party and have not been announced
// in ago duration
func (self *UnconfirmedTxnPool) GetOldOwnedTransactions(ago time.Duration) []UnconfirmedTxn {
	txns := make([]UnconfirmedTxn, 0)
	now := util.Now()
	for _, tx := range self.Txns {
		// TODO -- don't record IsOurSpend/IsOurReceive and do lookup each time?
		// Slower but more correct
		if (tx.IsOurSpend || tx.IsOurReceive) && now.Sub(tx.Announced) > ago {
			txns = append(txns, tx)
		}
	}
	return txns
}
开发者ID:up4k,项目名称:skycoin,代码行数:14,代码来源:unconfirmed.go

示例14: TestVisorSetAnnounced

func TestVisorSetAnnounced(t *testing.T) {
	defer cleanupVisor()
	vc := newMasterVisorConfig(t)
	v := NewVisor(vc)

	now := util.Now()
	utx := addUnconfirmedTxn(v)
	assert.True(t, utx.Announced.IsZero())
	assert.True(t, v.Unconfirmed.Txns[utx.Hash()].Announced.IsZero())
	v.SetAnnounced(utx.Hash(), now)
	assert.False(t, v.Unconfirmed.Txns[utx.Hash()].Announced.IsZero())
	assert.Equal(t, v.Unconfirmed.Txns[utx.Hash()].Announced, now)
}
开发者ID:keepwalking1234,项目名称:skycoin,代码行数:13,代码来源:blockchain_test.go

示例15: createUnconfirmedTxn

func createUnconfirmedTxn() visor.UnconfirmedTxn {
	now := util.Now()
	return visor.UnconfirmedTxn{
		Txn: coin.Transaction{
			Head: coin.TransactionHeader{
				Hash: coin.SumSHA256([]byte("cascas")),
			},
		},
		Received:  now,
		Checked:   now,
		Announced: util.ZeroTime(),
	}
}
开发者ID:notsoshifty,项目名称:skycoin,代码行数:13,代码来源:visor_test.go


注:本文中的github.com/skycoin/skycoin/src/util.Now函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。