本文整理匯總了Golang中github.com/NebulousLabs/Sia/types.Transaction.SiacoinOutputSum方法的典型用法代碼示例。如果您正苦於以下問題:Golang Transaction.SiacoinOutputSum方法的具體用法?Golang Transaction.SiacoinOutputSum怎麽用?Golang Transaction.SiacoinOutputSum使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/NebulousLabs/Sia/types.Transaction
的用法示例。
在下文中一共展示了Transaction.SiacoinOutputSum方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: validSiacoins
// validSiacoins checks that the siacoin inputs and outputs are valid in the
// context of the current consensus set.
func validSiacoins(tx *bolt.Tx, t types.Transaction) error {
scoBucket := tx.Bucket(SiacoinOutputs)
var inputSum types.Currency
for _, sci := range t.SiacoinInputs {
// Check that the input spends an existing output.
scoBytes := scoBucket.Get(sci.ParentID[:])
if scoBytes == nil {
return errMissingSiacoinOutput
}
// Check that the unlock conditions match the required unlock hash.
var sco types.SiacoinOutput
err := encoding.Unmarshal(scoBytes, &sco)
if build.DEBUG && err != nil {
panic(err)
}
if sci.UnlockConditions.UnlockHash() != sco.UnlockHash {
return errWrongUnlockConditions
}
inputSum = inputSum.Add(sco.Value)
}
if inputSum.Cmp(t.SiacoinOutputSum()) != 0 {
return errSiacoinInputOutputMismatch
}
return nil
}
示例2: validUnconfirmedSiacoins
// validUnconfirmedSiacoins checks that all siacoin inputs and outputs are
// valid in the context of the unconfirmed consensus set.
func (tp *TransactionPool) validUnconfirmedSiacoins(t types.Transaction) (err error) {
var inputSum types.Currency
for _, sci := range t.SiacoinInputs {
// All inputs must have corresponding outputs in the unconfirmed set.
sco, exists := tp.siacoinOutputs[sci.ParentID]
if !exists {
return ErrUnrecognizedSiacoinInput
}
// The unlock conditions provided must match the unlock hash of the
// corresponding output.
if sci.UnlockConditions.UnlockHash() != sco.UnlockHash {
return ErrBadUnlockConditions
}
inputSum = inputSum.Add(sco.Value)
}
// The sum of all inputs must equal the sum of all outputs.
if inputSum.Cmp(t.SiacoinOutputSum()) != 0 {
return ErrSiacoinOverspend
}
return
}