Exemplo n.º 1
0
func SignFactoidTransaction(n uint64, tx interfaces.ITransaction) {
	tx.AddAuthorization(NewFactoidRCDAddress(n))
	data, err := tx.MarshalBinarySig()
	if err != nil {
		panic(err)
	}

	sig := factoid.NewSingleSignatureBlock(NewPrivKey(n), data)

	//str, err := sig.JSONString()

	//fmt.Printf("sig, err - %v, %v\n", str, err)

	tx.SetSignatureBlock(0, sig)

	err = tx.Validate(1)
	if err != nil {
		panic(err)
	}

	err = tx.ValidateSignatures()
	if err != nil {
		panic(err)
	}
}
Exemplo n.º 2
0
func (b FBlock) ValidateTransaction(index int, trans interfaces.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 := 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",
			primitives.ConvertDecimalToString(tin),
			primitives.ConvertDecimalToString(tout),
			primitives.ConvertDecimalToString(tec),
			primitives.ConvertDecimalToString(fee))
	}
	return nil
}
Exemplo n.º 3
0
func (w *SCWallet) Validate(index int, trans interfaces.ITransaction) error {
	err := trans.Validate(index)
	return err
}