本文整理匯總了Golang中github.com/skycoin/skycoin/src/coin.Blockchain.Head方法的典型用法代碼示例。如果您正苦於以下問題:Golang Blockchain.Head方法的具體用法?Golang Blockchain.Head怎麽用?Golang Blockchain.Head使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/skycoin/skycoin/src/coin.Blockchain
的用法示例。
在下文中一共展示了Blockchain.Head方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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[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
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
}
示例2: 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
}
示例3: assertValidUnspent
func assertValidUnspent(t *testing.T, bc *coin.Blockchain,
unspent TxnUnspents, tx coin.Transaction) {
expect := coin.CreateUnspents(bc.Head().Head, tx)
assert.NotEqual(t, len(expect), 0)
sum := 0
for _, uxs := range unspent {
sum += len(uxs)
}
assert.Equal(t, len(expect), sum)
uxs := unspent[tx.Hash()]
for _, ux := range expect {
found := false
for _, u := range uxs {
if u.Hash() == ux.Hash() {
found = true
break
}
}
assert.True(t, found)
}
}