示例#1
0
        public void Run()
        {
            Random random = new Random();
            Party  partyA = new Party(random, "A - Party");

            partyA.SetRandom();
            Party        partyB = new Party(random, "B - Party");
            decimal      x      = 0.5m;
            ATransaction tx1    = partyA.CreateTransaction(x, CoinType.Bitcoin, partyB); //new ATransaction(x, partyA);

            tx1.Hasher();
            partyA.Send(tx1);


            ReceivedTxHandler(partyB);

            if (VerifyReceivedTx(partyA, ref tx1) == false)
            {
                return;
            }

            partyA.Transactions.Add(tx1); //do not yet broadcast.
            //party A creates transaction 2, sends to self
            decimal      w   = 0.2m;      //is this equal to x or less than x?
            ATransaction tx2 = partyA.CreateTransaction(w, CoinType.Bitcoin, partyA, 0);

            partyA.Send(tx2);

            ReceivedTxHandler(partyB);
            if (VerifyReceivedTx(partyA, ref tx2))
            {
                partyA.Broadcast(tx2);
            }
        }
示例#2
0
        public void ReceivedTxHandler(Party party)
        {
            ATransaction receivedTx1 = party.Receive();

            if (party.Accepted(receivedTx1))
            {
                receivedTx1.Sign(party);
                party.Send(receivedTx1);
            }
            else
            {
                receivedTx1.Reject();
            }
        }
示例#3
0
        public bool VerifyReceivedTx(Party party, ref ATransaction sentTransaction)
        {
            var newTx1 = party.Receive();

            if (sentTransaction.Verify(newTx1) == true)
            {
                sentTransaction       = newTx1;
                sentTransaction.Valid = true;
                return(true);
            }
            else
            {
                sentTransaction.Valid = false;
            }

            return(false);
        }
示例#4
0
        public ATransaction CreateTransaction(decimal amount, CoinType coinType, Party toParty, int?index = null)
        {
            ATransaction tx;

            if (index != null)
            {
                tx = new ATransaction(amount, toParty, Transactions[0]);
            }
            else
            {
                tx = new ATransaction(amount, toParty);
            }
            tx.Amount   = amount;
            tx.CoinType = coinType;
            Transactions.Add(tx);
            return(tx);
        }
示例#5
0
 internal bool Verify(ATransaction newTx1)
 {
     return(true);
     //throw new NotImplementedException();
 }
示例#6
0
 public ATransaction(decimal amount, Party fromParty, ATransaction inputTransaction) : this(amount, fromParty)
 {
     this.InputTransaction = inputTransaction;
 }
示例#7
0
 internal void Broadcast(ATransaction tx2)
 {
     throw new NotImplementedException();
 }
示例#8
0
 internal void Send(ATransaction tx1)
 {
     throw new NotImplementedException();
 }
示例#9
0
 internal bool Accepted(ATransaction receivedTx1)
 {
     throw new NotImplementedException();
 }