本文整理匯總了Golang中github.com/NebulousLabs/Sia/modules.ProcessedTransaction.Inputs方法的典型用法代碼示例。如果您正苦於以下問題:Golang ProcessedTransaction.Inputs方法的具體用法?Golang ProcessedTransaction.Inputs怎麽用?Golang ProcessedTransaction.Inputs使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/NebulousLabs/Sia/modules.ProcessedTransaction
的用法示例。
在下文中一共展示了ProcessedTransaction.Inputs方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: ReceiveUpdatedUnconfirmedTransactions
// ReceiveUpdatedUnconfirmedTransactions updates the wallet's unconfirmed
// transaction set.
func (w *Wallet) ReceiveUpdatedUnconfirmedTransactions(txns []types.Transaction, _ modules.ConsensusChange) {
// There are two different situations under which a subscribee calls
// ProcessConsensusChange. The first is when w.subscribed is set to false
// AND the mutex is already locked. The other situation is that subscribed
// is set to true and is not going to be changed. Therefore there is no
// race condition here. If w.subscribed is set to false, trying to grab the
// lock would cause a deadlock.
if w.subscribed {
lockID := w.mu.Lock()
defer w.mu.Unlock(lockID)
}
w.unconfirmedProcessedTransactions = nil
for _, txn := range txns {
// To save on code complexity, relveancy is determined while building
// up the wallet transaction.
relevant := false
pt := modules.ProcessedTransaction{
Transaction: txn,
TransactionID: txn.ID(),
ConfirmationHeight: types.BlockHeight(math.MaxUint64),
ConfirmationTimestamp: types.Timestamp(math.MaxUint64),
}
for _, sci := range txn.SiacoinInputs {
_, exists := w.keys[sci.UnlockConditions.UnlockHash()]
if exists {
relevant = true
}
pt.Inputs = append(pt.Inputs, modules.ProcessedInput{
FundType: types.SpecifierSiacoinInput,
WalletAddress: exists,
RelatedAddress: sci.UnlockConditions.UnlockHash(),
Value: w.historicOutputs[types.OutputID(sci.ParentID)],
})
}
for i, sco := range txn.SiacoinOutputs {
_, exists := w.keys[sco.UnlockHash]
if exists {
relevant = true
}
pt.Outputs = append(pt.Outputs, modules.ProcessedOutput{
FundType: types.SpecifierSiacoinOutput,
MaturityHeight: types.BlockHeight(math.MaxUint64),
WalletAddress: exists,
RelatedAddress: sco.UnlockHash,
Value: sco.Value,
})
w.historicOutputs[types.OutputID(txn.SiacoinOutputID(i))] = sco.Value
}
for _, fee := range txn.MinerFees {
pt.Outputs = append(pt.Outputs, modules.ProcessedOutput{
FundType: types.SpecifierMinerFee,
Value: fee,
})
}
if relevant {
w.unconfirmedProcessedTransactions = append(w.unconfirmedProcessedTransactions, pt)
}
}
}
示例2: ReceiveUpdatedUnconfirmedTransactions
// ReceiveUpdatedUnconfirmedTransactions updates the wallet's unconfirmed
// transaction set.
func (w *Wallet) ReceiveUpdatedUnconfirmedTransactions(txns []types.Transaction, _ modules.ConsensusChange) {
if err := w.tg.Add(); err != nil {
// Gracefully reject transactions if the wallet's Close method has
// closed the wallet's ThreadGroup already.
return
}
defer w.tg.Done()
w.mu.Lock()
defer w.mu.Unlock()
w.unconfirmedProcessedTransactions = nil
for _, txn := range txns {
// To save on code complexity, relevancy is determined while building
// up the wallet transaction.
relevant := false
pt := modules.ProcessedTransaction{
Transaction: txn,
TransactionID: txn.ID(),
ConfirmationHeight: types.BlockHeight(math.MaxUint64),
ConfirmationTimestamp: types.Timestamp(math.MaxUint64),
}
for _, sci := range txn.SiacoinInputs {
_, exists := w.keys[sci.UnlockConditions.UnlockHash()]
if exists {
relevant = true
}
pt.Inputs = append(pt.Inputs, modules.ProcessedInput{
FundType: types.SpecifierSiacoinInput,
WalletAddress: exists,
RelatedAddress: sci.UnlockConditions.UnlockHash(),
Value: w.historicOutputs[types.OutputID(sci.ParentID)],
})
}
for i, sco := range txn.SiacoinOutputs {
_, exists := w.keys[sco.UnlockHash]
if exists {
relevant = true
}
pt.Outputs = append(pt.Outputs, modules.ProcessedOutput{
FundType: types.SpecifierSiacoinOutput,
MaturityHeight: types.BlockHeight(math.MaxUint64),
WalletAddress: exists,
RelatedAddress: sco.UnlockHash,
Value: sco.Value,
})
w.historicOutputs[types.OutputID(txn.SiacoinOutputID(uint64(i)))] = sco.Value
}
for _, fee := range txn.MinerFees {
pt.Outputs = append(pt.Outputs, modules.ProcessedOutput{
FundType: types.SpecifierMinerFee,
Value: fee,
})
}
if relevant {
w.unconfirmedProcessedTransactions = append(w.unconfirmedProcessedTransactions, pt)
}
}
}
示例3: ProcessConsensusChange
//.........這裏部分代碼省略.........
minerPT := modules.ProcessedTransaction{
Transaction: types.Transaction{},
TransactionID: types.TransactionID(block.ID()),
ConfirmationHeight: w.consensusSetHeight,
ConfirmationTimestamp: block.Timestamp,
}
relevant := false
for i, mp := range block.MinerPayouts {
_, exists := w.keys[mp.UnlockHash]
if exists {
relevant = true
}
minerPT.Outputs = append(minerPT.Outputs, modules.ProcessedOutput{
FundType: types.SpecifierMinerPayout,
MaturityHeight: w.consensusSetHeight + types.MaturityDelay,
WalletAddress: exists,
RelatedAddress: mp.UnlockHash,
Value: mp.Value,
})
w.historicOutputs[types.OutputID(block.MinerPayoutID(uint64(i)))] = mp.Value
}
if relevant {
w.processedTransactions = append(w.processedTransactions, minerPT)
w.processedTransactionMap[minerPT.TransactionID] = &w.processedTransactions[len(w.processedTransactions)-1]
}
for _, txn := range block.Transactions {
relevant := false
pt := modules.ProcessedTransaction{
Transaction: txn,
TransactionID: txn.ID(),
ConfirmationHeight: w.consensusSetHeight,
ConfirmationTimestamp: block.Timestamp,
}
for _, sci := range txn.SiacoinInputs {
_, exists := w.keys[sci.UnlockConditions.UnlockHash()]
if exists {
relevant = true
}
pt.Inputs = append(pt.Inputs, modules.ProcessedInput{
FundType: types.SpecifierSiacoinInput,
WalletAddress: exists,
RelatedAddress: sci.UnlockConditions.UnlockHash(),
Value: w.historicOutputs[types.OutputID(sci.ParentID)],
})
}
for i, sco := range txn.SiacoinOutputs {
_, exists := w.keys[sco.UnlockHash]
if exists {
relevant = true
}
pt.Outputs = append(pt.Outputs, modules.ProcessedOutput{
FundType: types.SpecifierSiacoinOutput,
MaturityHeight: w.consensusSetHeight,
WalletAddress: exists,
RelatedAddress: sco.UnlockHash,
Value: sco.Value,
})
w.historicOutputs[types.OutputID(txn.SiacoinOutputID(i))] = sco.Value
}
for _, sfi := range txn.SiafundInputs {
_, exists := w.keys[sfi.UnlockConditions.UnlockHash()]
if exists {
relevant = true
}
sfiValue := w.historicOutputs[types.OutputID(sfi.ParentID)]
pt.Inputs = append(pt.Inputs, modules.ProcessedInput{
示例4: applyHistory
// applyHistory applies any transaction history that was introduced by the
// applied blocks.
func (w *Wallet) applyHistory(cc modules.ConsensusChange) {
for _, block := range cc.AppliedBlocks {
w.consensusSetHeight++
// Apply the miner payout transaction if applicable.
minerPT := modules.ProcessedTransaction{
Transaction: types.Transaction{},
TransactionID: types.TransactionID(block.ID()),
ConfirmationHeight: w.consensusSetHeight,
ConfirmationTimestamp: block.Timestamp,
}
relevant := false
for i, mp := range block.MinerPayouts {
_, exists := w.keys[mp.UnlockHash]
if exists {
relevant = true
}
minerPT.Outputs = append(minerPT.Outputs, modules.ProcessedOutput{
FundType: types.SpecifierMinerPayout,
MaturityHeight: w.consensusSetHeight + types.MaturityDelay,
WalletAddress: exists,
RelatedAddress: mp.UnlockHash,
Value: mp.Value,
})
w.historicOutputs[types.OutputID(block.MinerPayoutID(uint64(i)))] = mp.Value
}
if relevant {
w.processedTransactions = append(w.processedTransactions, minerPT)
w.processedTransactionMap[minerPT.TransactionID] = &w.processedTransactions[len(w.processedTransactions)-1]
}
for _, txn := range block.Transactions {
relevant := false
pt := modules.ProcessedTransaction{
Transaction: txn,
TransactionID: txn.ID(),
ConfirmationHeight: w.consensusSetHeight,
ConfirmationTimestamp: block.Timestamp,
}
for _, sci := range txn.SiacoinInputs {
_, exists := w.keys[sci.UnlockConditions.UnlockHash()]
if exists {
relevant = true
}
pt.Inputs = append(pt.Inputs, modules.ProcessedInput{
FundType: types.SpecifierSiacoinInput,
WalletAddress: exists,
RelatedAddress: sci.UnlockConditions.UnlockHash(),
Value: w.historicOutputs[types.OutputID(sci.ParentID)],
})
}
for i, sco := range txn.SiacoinOutputs {
_, exists := w.keys[sco.UnlockHash]
if exists {
relevant = true
}
pt.Outputs = append(pt.Outputs, modules.ProcessedOutput{
FundType: types.SpecifierSiacoinOutput,
MaturityHeight: w.consensusSetHeight,
WalletAddress: exists,
RelatedAddress: sco.UnlockHash,
Value: sco.Value,
})
w.historicOutputs[types.OutputID(txn.SiacoinOutputID(i))] = sco.Value
}
for _, sfi := range txn.SiafundInputs {
_, exists := w.keys[sfi.UnlockConditions.UnlockHash()]
if exists {
relevant = true
}
sfiValue := w.historicOutputs[types.OutputID(sfi.ParentID)]
pt.Inputs = append(pt.Inputs, modules.ProcessedInput{
FundType: types.SpecifierSiafundInput,
WalletAddress: exists,
RelatedAddress: sfi.UnlockConditions.UnlockHash(),
Value: sfiValue,
})
claimValue := w.siafundPool.Sub(w.historicClaimStarts[sfi.ParentID]).Mul(sfiValue)
pt.Outputs = append(pt.Outputs, modules.ProcessedOutput{
FundType: types.SpecifierClaimOutput,
MaturityHeight: w.consensusSetHeight + types.MaturityDelay,
WalletAddress: exists,
RelatedAddress: sfi.ClaimUnlockHash,
Value: claimValue,
})
}
for i, sfo := range txn.SiafundOutputs {
_, exists := w.keys[sfo.UnlockHash]
if exists {
relevant = true
}
pt.Outputs = append(pt.Outputs, modules.ProcessedOutput{
FundType: types.SpecifierSiafundOutput,
MaturityHeight: w.consensusSetHeight,
WalletAddress: exists,
RelatedAddress: sfo.UnlockHash,
Value: sfo.Value,
})
w.historicOutputs[types.OutputID(txn.SiafundOutputID(i))] = sfo.Value
w.historicClaimStarts[txn.SiafundOutputID(i)] = sfo.ClaimStart
//.........這裏部分代碼省略.........