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


Golang Blockchain.VerifyTransaction方法代碼示例

本文整理匯總了Golang中github.com/skycoin/skycoin/src/coin.Blockchain.VerifyTransaction方法的典型用法代碼示例。如果您正苦於以下問題:Golang Blockchain.VerifyTransaction方法的具體用法?Golang Blockchain.VerifyTransaction怎麽用?Golang Blockchain.VerifyTransaction使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/skycoin/skycoin/src/coin.Blockchain的用法示例。


在下文中一共展示了Blockchain.VerifyTransaction方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: 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

示例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[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

示例3: 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 (self *UnconfirmedTxnPool) InjectTxn(bc *coin.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 := 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)
	// Add predicted unspents
	self.Unspent[h] = coin.CreateUnspents(bc.Head().Head, t)

	return nil, false
}
開發者ID:Chao-Jia,項目名稱:skycoin,代碼行數:35,代碼來源:unconfirmed.go

示例4: Refresh

// Checks all unconfirmed txns against the blockchain. maxAge is how long
// we'll hold a txn regardless of whether it has been invalidated.
// checkPeriod is how often we check the txn against the blockchain.
func (self *UnconfirmedTxnPool) Refresh(bc *coin.Blockchain, checkPeriod int) {
	now := time.Now().Unix()
	toRemove := make([]cipher.SHA256, 0)
	for k, t := range self.Txns {
		if now-t.Checked >= int64(checkPeriod) {
			if bc.VerifyTransaction(t.Txn) == nil {
				t.Checked = now
				self.Txns[k] = t
			} else {
				toRemove = append(toRemove, k)
			}
		}
	}
	self.removeTxns(toRemove)
}
開發者ID:skycoin,項目名稱:skycoin,代碼行數:18,代碼來源:unconfirmed.go

示例5: Refresh

// Checks all unconfirmed txns against the blockchain. maxAge is how long
// we'll hold a txn regardless of whether it has been invalidated.
// checkPeriod is how often we check the txn against the blockchain.
func (self *UnconfirmedTxnPool) Refresh(bc *coin.Blockchain,
	checkPeriod, maxAge time.Duration) {
	now := util.Now()
	toRemove := make([]coin.SHA256, 0)
	for k, t := range self.Txns {
		if now.Sub(t.Received) >= maxAge {
			toRemove = append(toRemove, k)
		} else if now.Sub(t.Checked) >= checkPeriod {
			if bc.VerifyTransaction(t.Txn) == nil {
				t.Checked = now
				self.Txns[k] = t
			} else {
				toRemove = append(toRemove, k)
			}
		}
	}
	self.removeTxns(bc, toRemove)
}
開發者ID:up4k,項目名稱:skycoin,代碼行數:21,代碼來源:unconfirmed.go


注:本文中的github.com/skycoin/skycoin/src/coin.Blockchain.VerifyTransaction方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。