Ejemplo n.º 1
0
 public void ExecuteUnit(ITransactionUnit unit)
 {
     try
     {
         if (!this.isBad)
         {
             unit.Commit();
             this.executedUnits.Add(unit);
             this.journalManager.Save(this.executedUnits);
         }
     }
     catch (Exception)
     {
         unit.Dispose();
         this.isBad = true;
         this.Rollback();
     }
 }
Ejemplo n.º 2
0
        public virtual string SignTransaction(string aTxData, ICurrencyTransaction aValidationInfo)
        {
            if (!CustomTransaction.GetCustomTransaction(Id, out Transaction tx, aTxData, Network))
            {
                tx = new Transaction(aTxData, Network);
            }
            // check how much is being spent and insure all is spent.
            BigInteger lTotalSent = 0;

            foreach (ITransactionUnit linput in aValidationInfo.Inputs)
            {
                lTotalSent += linput.Amount;
            }

            BigInteger lTotalSpending = aValidationInfo.TxFee;

            foreach (ITransactionUnit lOutput in aValidationInfo.Outputs)
            {
                lTotalSpending += lOutput.Amount;
            }

            if (lTotalSent != lTotalSpending)
            {
                throw new Exception("The total of the inputs does not equal the total outputs.");
            }
            // Check output amounts in the transaction to sign.
            int lValidCount = 0;

            foreach (TxOut lOutput in tx.Outputs)
            {
                string lAddress = lOutput.GetAddress(Network);
                foreach (ITransactionUnit lValOut in aValidationInfo.Outputs)
                {
                    if (lAddress == lValOut.Address)
                    {
                        if (lOutput.Value.Satoshi == lValOut.Amount)
                        {
                            lValidCount++;
                        }
                    }
                }
            }
            if (lValidCount != aValidationInfo.Outputs.Length)
            {
                throw new Exception("Transaction to sign is not correct.");
            }

            List <CCKey> lKeys  = new List <CCKey>();
            List <ICoin> lCoins = new List <ICoin>();

            for (int i = 0; i < tx.Inputs.Count; i++)
            {
                if (!FAddressLookup.TryGetValue(aValidationInfo.Inputs[i].Address, out long lIndex))
                {
                    throw new Exception(string.Format("Address {0} does not exist.", aValidationInfo.Inputs[i].Address));
                }

                lKeys.Add(GetCCKey(lIndex));
                ITransactionUnit lPrevOut = aValidationInfo.Inputs
                                            .Where(lInput => lInput.TxID == tx.Inputs[i].PrevOut.Hash.ToString() && lInput.Index == tx.Inputs[i].PrevOut.N)
                                            .FirstOrDefault();
                if (lPrevOut == null)
                {
                    throw new Exception("Failed to found previous tx out information");
                }
                lCoins.Add(new Coin(tx.Inputs[i].PrevOut, new TxOut()
                {
                    ScriptPubKey = tx.Inputs[i].ScriptSig,
                    Value        = new Money((long)lPrevOut.Amount)
                }));
                tx.Inputs[i].ScriptSig = Script.Empty;
            }

            var lHexTest = tx.ToHex();

            tx.Sign(lKeys.ToArray(), lCoins.ToArray());
            return(tx.ToHex());
        }
Ejemplo n.º 3
0
 public ITransatcionBuilder Then(ITransactionUnit transactionUnit)
 {
     throw new NotImplementedException();
 }