コード例 #1
0
ファイル: transaction.go プロジェクト: johncap46/fctwallet
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)
}
コード例 #2
0
ファイル: scblock.go プロジェクト: conseweb/factoid
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
}
コード例 #3
0
ファイル: transaction.go プロジェクト: johncap46/fctwallet
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
}