本文整理汇总了Golang中github.com/skycoin/skycoin/src/coin.Block.Time方法的典型用法代码示例。如果您正苦于以下问题:Golang Block.Time方法的具体用法?Golang Block.Time怎么用?Golang Block.Time使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/skycoin/skycoin/src/coin.Block
的用法示例。
在下文中一共展示了Block.Time方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: GetAddressTransactions
// GetAddressTransactions returns the Transactions whose unspents give coins to a cipher.Address.
// This includes unconfirmed txns' predicted unspents.
func (vs *Visor) GetAddressTransactions(a cipher.Address) []Transaction {
var txns []Transaction
// Look in the blockchain
uxs := vs.Blockchain.GetUnspent().AllForAddress(a)
mxSeq := vs.HeadBkSeq()
var bk *coin.Block
for _, ux := range uxs {
if bk = vs.GetBlockBySeq(ux.Head.BkSeq); bk == nil {
return txns
}
tx, ok := bk.GetTransaction(ux.Body.SrcTransaction)
if ok {
h := mxSeq - bk.Head.BkSeq + 1
txns = append(txns, Transaction{
Txn: tx,
Status: NewConfirmedTransactionStatus(h),
Time: bk.Time(),
})
}
}
// Look in the unconfirmed pool
uxs = vs.Unconfirmed.Unspent.AllForAddress(a)
for _, ux := range uxs {
tx, ok := vs.Unconfirmed.Txns[ux.Body.SrcTransaction]
if !ok {
logger.Critical("Unconfirmed unspent missing unconfirmed txn")
continue
}
txns = append(txns, Transaction{
Txn: tx.Txn,
Status: NewUnconfirmedTransactionStatus(),
Time: uint64(tx.Received.Unix()),
})
}
return txns
}
示例2: GetLastTxs
// GetLastTxs returns last confirmed transactions, return nil if empty
func (vs *Visor) GetLastTxs() ([]*Transaction, error) {
ltxs, err := vs.history.GetLastTxs()
if err != nil {
return nil, err
}
txs := make([]*Transaction, len(ltxs))
var confirms uint64
bh := vs.GetHeadBlock().Seq()
var b *coin.Block
for i, tx := range ltxs {
confirms = bh - tx.BlockSeq + 1
if b = vs.GetBlockBySeq(tx.BlockSeq); b == nil {
return nil, fmt.Errorf("found no block in seq %v", tx.BlockSeq)
}
txs[i] = &Transaction{
Txn: tx.Tx,
Status: NewConfirmedTransactionStatus(confirms),
Time: b.Time(),
}
}
return txs, nil
}