本文整理匯總了Golang中github.com/FactomProject/factoid.ITransaction.CalculateFee方法的典型用法代碼示例。如果您正苦於以下問題:Golang ITransaction.CalculateFee方法的具體用法?Golang ITransaction.CalculateFee怎麽用?Golang ITransaction.CalculateFee使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/FactomProject/factoid.ITransaction
的用法示例。
在下文中一共展示了ITransaction.CalculateFee方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: HandleGetFee
func HandleGetFee(ctx *web.Context, k string) {
var trans fct.ITransaction
var err error
key := ctx.Params["key"]
fmt.Println("getfee", key)
if len(key) > 0 {
trans, err = getTransaction(ctx, key)
if err != nil {
reportResults(ctx, "Failure to locate the transaction", false)
return
}
}
fee, err := Wallet.GetFee()
if err != nil {
reportResults(ctx, err.Error(), false)
return
}
if trans != nil {
ufee, _ := trans.CalculateFee(uint64(fee))
fee = int64(ufee)
}
reportResults(ctx, fmt.Sprintf("%s", strings.TrimSpace(fct.ConvertDecimal(uint64(fee)))), true)
}
示例2: FactoidAddFee
func FactoidAddFee(trans fct.ITransaction, key string, address fct.IAddress, name string) (uint64, error) {
{
ins, err := trans.TotalInputs()
if err != nil {
return 0, err
}
outs, err := trans.TotalOutputs()
if err != nil {
return 0, err
}
ecs, err := trans.TotalECs()
if err != nil {
return 0, err
}
if ins != outs+ecs {
return 0, fmt.Errorf("Inputs and outputs don't add up")
}
}
ok := Utility.IsValidKey(key)
if !ok {
return 0, fmt.Errorf("Invalid name for transaction")
}
fee, err := GetFee()
if err != nil {
return 0, err
}
transfee, err := trans.CalculateFee(uint64(fee))
if err != nil {
return 0, err
}
adr, err := factoidState.GetWallet().GetAddressHash(address)
if err != nil {
return 0, err
}
for _, input := range trans.GetInputs() {
if input.GetAddress().IsSameAs(adr) {
amt, err := fct.ValidateAmounts(input.GetAmount(), transfee)
if err != nil {
return 0, err
}
input.SetAmount(amt)
return transfee, nil
}
}
return 0, fmt.Errorf("%s is not an input to the transaction.", key)
}
示例3: ValidateTransaction
func (b FBlock) ValidateTransaction(index int, trans fct.ITransaction) error {
// Calculate the fee due.
{
err := trans.Validate(index)
if err != nil {
return err
}
}
//Ignore coinbase transaction's signatures
if len(b.Transactions) > 0 {
err := trans.ValidateSignatures()
if err != nil {
return err
}
}
fee, err := trans.CalculateFee(b.ExchRate)
if err != nil {
return err
}
tin, err := trans.TotalInputs()
if err != nil {
return err
}
tout, err := trans.TotalOutputs()
if err != nil {
return err
}
tec, err := trans.TotalECs()
if err != nil {
return err
}
sum, err := fct.ValidateAmounts(tout, tec, fee)
if err != nil {
return err
}
if tin < sum {
return fmt.Errorf("The inputs %s do not cover the outputs %s,\n"+
"the Entry Credit outputs %s, and the required fee %s",
strings.TrimSpace(fct.ConvertDecimal(tin)),
strings.TrimSpace(fct.ConvertDecimal(tout)),
strings.TrimSpace(fct.ConvertDecimal(tec)),
strings.TrimSpace(fct.ConvertDecimal(fee)))
}
return nil
}
示例4: isReasonableFee
func isReasonableFee(trans fct.ITransaction) error {
feeRate, getErr := GetFee()
if getErr != nil {
return getErr
}
reqFee, err := trans.CalculateFee(uint64(feeRate))
if err != nil {
return err
}
sreqFee := int64(reqFee)
tin, err := trans.TotalInputs()
if err != nil {
return err
}
tout, err := trans.TotalOutputs()
if err != nil {
return err
}
tec, err := trans.TotalECs()
if err != nil {
return err
}
cfee := int64(tin) - int64(tout) - int64(tec)
if cfee >= (sreqFee * 10) {
return fmt.Errorf("Unbalanced transaction (fee too high). Fee should be less than 10x the required fee.")
}
if cfee < sreqFee {
return fmt.Errorf("Insufficient fee")
}
return nil
}