예제 #1
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
}
예제 #2
0
// Returns an error message about what is wrong with the transaction if it is
// invalid, otherwise you are good to go.
func (fs *AssetState) Validate(trans fct.ITransaction) error {

	if err := trans.ValidateSignatures(); err != nil {
		return err
	}

	var sums = make(map[fct.IAddress]uint64, 10)
	for _, input := range trans.GetInputs() {
		bal, err := fct.ValidateAmounts(
			sums[input.GetAddress()], // Will be zero the first time around
			input.GetAmount())        // Get this amount, check against bounds
		if err != nil {
			return err
		}
		if bal > fs.GetBalance(input.GetAddress()) {
			return fmt.Errorf("Not enough funds in input addresses for the transaction")
		}
		sums[input.GetAddress()] = bal
	}
	return nil
}
예제 #3
0
func (w *SCWallet) ValidateSignatures(trans fct.ITransaction) error {
	if trans == nil {
		return fmt.Errorf("Missing Transaction")
	}
	return trans.ValidateSignatures()
}