コード例 #1
0
        public string SignTransaction(string key, string to, BigInteger amount, BigInteger nonce, BigInteger gasPrice, BigInteger gasLimit)
        {
            var transaction = new Core.Transaction(to, amount, nonce, gasPrice, gasLimit);

            transaction.Sign(new ECKey(key.HexToByteArray(), true));
            return(transaction.GetRLPEncoded().ToHex());
        }
コード例 #2
0
        public bool ExecuteFinal(Core.Script script, Core.Transaction transaction, int transactionInputIndex)
        {
            Contract.Ensures(InFinalState);
            Contract.Ensures(ExecutionResult != null);

            Execute(script, transaction, transactionInputIndex);

            Finish();

            return(this.ExecutionResult == true);
        }
コード例 #3
0
        public bool Execute(Core.Script script, Core.Transaction transaction, int transactionInputIndex)
        {
            try
            {
                CurrentScript                = script;
                CurrentTransaction           = transaction;
                CurrentTransactionInputIndex = transactionInputIndex;

                foreach (var atom in script.Atoms)
                {
                    if (this.ExecutionResult.HasValue)
                    {
                        break;
                    }
                    if (!atom.CanExecute(this))
                    {
                        this.HardFailure = true;
                    }
                    atom.Execute(this);

                    if (atom is Atoms.IVerifyAtom && (atom as Atoms.IVerifyAtom).MustVerify)
                    {
                        ExecuteVerify();
                    }

                    if (atom is Atoms.OpAtom)
                    {
                        ++OpAtomsExecuted;
                    }
                    ++CurrentAtomIndex;
                }
            }
            finally
            {
                CurrentScript                = null;
                CurrentTransaction           = null;
                CurrentTransactionInputIndex = 0;
                CurrentAtomIndex             = 0;
                LastSeparatorAtomIndex       = 0;
            }

            return(this.ExecutionResult != false);
        }
コード例 #4
0
 public Transaction MapTransaction(int index, long blockNumber,
                                   Keccak blockHash, Core.Transaction transaction)
 => new Transaction
 {
     transactionIndex = index,
     blockNumber      = blockNumber,
     toAddr           = transaction.To?.ToString() ?? string.Empty,
     blockHash        = blockHash.ToString(),
     nonce            = (int)transaction.Nonce,
     fromAddr         = transaction.SenderAddress?.ToString() ?? string.Empty,
     hash             = transaction.Hash.ToString(),
     gasPrice         = (long)transaction.GasPrice,
     v        = transaction.Signature.V,
     r        = transaction.Signature.R.ToString(),
     s        = transaction.Signature.S.ToString(),
     input    = transaction.Data ?? Array.Empty <byte>(),
     gas      = (long)transaction.GasLimit,
     weiValue = transaction.Value.ToString()
 };
コード例 #5
0
 public Transaction MapTransaction(Core.Transaction transaction)
 => transaction == null
         ? null
         : new Transaction
 {
     Nonce              = transaction.Nonce.ToString(),
     GasPrice           = transaction.GasPrice.ToString(),
     GasLimit           = transaction.GasLimit.ToString(),
     To                 = transaction.To?.Bytes,
     Value              = transaction.Value.ToString(),
     Data               = transaction.Data,
     SenderAddress      = transaction.SenderAddress?.Bytes,
     Signature          = MapSignature(transaction.Signature),
     IsSigned           = transaction.IsSigned,
     IsContractCreation = transaction.IsContractCreation,
     IsMessageCall      = transaction.IsMessageCall,
     Hash               = transaction.Hash?.Bytes,
     DeliveredBy        = transaction.DeliveredBy?.Bytes
 };
コード例 #6
0
        public override bool IsDoubleSpend(Core.Transaction tx)
        {
            if (tx.Inputs.Length == 0)
            {
                return(false);
            }
            ReadOptions options = new ReadOptions();

            using (options.Snapshot = db.GetSnapshot())
            {
                foreach (var group in tx.Inputs.GroupBy(p => p.PrevHash))
                {
                    UnspentCoinState state = db.TryGet <UnspentCoinState>(options, DataEntryPrefix.ST_Coin, group.Key);

                    if (state == null)
                    {
                        bool is_DoubleSpent = true;
                        if (Wallets.EntityFramework.UserWallet.Default != null)
                        {
                            foreach (Quras.Wallets.Coin coin in Wallets.EntityFramework.UserWallet.Default.GetCoins())
                            {
                                if (group.Key == coin.Reference.PrevHash /* && !coin.State.HasFlag(CoinState.Spent)*/)
                                {
                                    is_DoubleSpent = false;
                                    break;
                                }
                            }
                        }
                        return(is_DoubleSpent);
                    }
                    if (group.Any(p => p.PrevIndex >= state.Items.Length || state.Items[p.PrevIndex].HasFlag(CoinState.Spent)))
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
コード例 #7
0
 public FullTransaction(int index, Core.Transaction transaction, TxReceipt receipt)
 {
     Index       = index;
     Transaction = transaction;
     Receipt     = receipt;
 }
コード例 #8
0
        public string GetSenderAddress(string rlp)
        {
            var transaction = new Core.Transaction(rlp.HexToByteArray());

            return(transaction.Key.GetPublicAddress());
        }
コード例 #9
0
        public byte[] GetPublicKey(string rlp)
        {
            var transaction = new Core.Transaction(rlp.HexToByteArray());

            return(transaction.Key.GetPubKey(false));
        }
コード例 #10
0
        public bool VerifyTransaction(string rlp)
        {
            var transaction = new Core.Transaction(rlp.HexToByteArray());

            return(transaction.Key.VerifyAllowingOnlyLowS(transaction.RawHash, transaction.Signature));
        }