示例#1
0
        public string GetCode(string contractAddr, string blockId)
        {
            var hash = contractAddr.HexToUInt160();

            if (hash is null)
            {
                return("");
            }

            if (!blockId.Equals("pending"))
            {
                var snapshot = GetSnapshotByTag(blockId);
                if (snapshot is null)
                {
                    return("");
                }
                var contractByHash = snapshot.Contracts.GetContractByHash(hash);
                return(contractByHash != null?Web3DataFormatUtils.Web3Data(contractByHash !.ByteCode) : "");
            }

            // getting Code for "pending"
            // look for the code in latest snapshot first
            var contractFromLatest = _stateManager.LastApprovedSnapshot.Contracts.GetContractByHash(hash);

            if (contractFromLatest != null)
            {
                return(Web3DataFormatUtils.Web3Data(contractFromLatest !.ByteCode));
            }

            // look for the code in pool
            var txHashPool = _transactionPool.Transactions.Keys;

            foreach (var txHash in txHashPool)
            {
                var receipt = _transactionPool.GetByHash(txHash);
                if (receipt is null)
                {
                    continue;
                }
                if (receipt.Transaction.To.Buffer.IsEmpty || receipt.Transaction.To.IsZero()) // this is deploy transaction
                {
                    // find the contract address where this contract will be deployed
                    var address = UInt160Utils.Zero.ToBytes().Ripemd();
                    if (receipt.Transaction?.From != null)
                    {
                        address = receipt.Transaction.From.ToBytes()
                                  .Concat(receipt.Transaction.Nonce.ToBytes())
                                  .Ripemd();
                    }
                    if (address.Equals(hash) && receipt !.Transaction != null)
                    {
                        return(Web3DataFormatUtils.Web3Data(receipt !.Transaction !.Invocation.ToArray()));
                    }
                }
            }

            // contract was not found anywhere
            return("");
        }
示例#2
0
        private JObject?GetTransactionPoolByHash(string txHash)
        {
            var transaction = _transactionPool.GetByHash(HexUtils.HexToUInt256(txHash));

            return(transaction?.ToJson());
        }
示例#3
0
        public JObject?GetTransactionPoolByHash(string txHash)
        {
            var transaction = _transactionPool.GetByHash(txHash.HexToUInt256());

            return(transaction?.ToJson());
        }