public static Transaction FromJson(JObject json)
 {
     return(new(
                TransactionIdentifier.FromJson(json["transaction_identifier"]),
                json["operations"]?.GetArray().Select(p => Operation.FromJson(p)).ToArray(),
                Metadata.FromJson(json["metadata"])
                ));
 }
Beispiel #2
0
        public JObject ToJson()
        {
            JObject json = new JObject();

            json["transaction_identifier"] = TransactionIdentifier.ToJson();
            if (Metadata != null && Metadata.ToJson() != null)
            {
                json["metadata"] = Metadata.ToJson();
            }
            return(json);
        }
        public JObject ToJson()
        {
            JObject json = new JObject();

            json["transaction_identifier"] = TransactionIdentifier.ToJson();
            json["operations"]             = Operations.Select(p => p.ToJson()).ToArray();
            if (Metadata != null && Metadata.ToJson() != null)
            {
                json["metadata"] = Metadata.ToJson();
            }
            return(json);
        }
Beispiel #4
0
        /// <summary>
        /// Submit a pre-signed transaction to the node. This call should not block on the transaction being included in a block.
        /// Rather, it should return immediately with an indication of whether or not the transaction was included in the mempool.
        /// The transaction submission response should only return a 200 status if the submitted transaction could be included in the mempool.
        /// Otherwise, it should return an error.
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public JObject ConstructionSubmit(ConstructionSubmitRequest request)
        {
            NeoTransaction neoTx;

            try
            {
                neoTx = NeoTransaction.DeserializeFrom(request.SignedTransaction.HexToBytes());
            }
            catch (Exception)
            {
                return(Error.TX_DESERIALIZE_ERROR.ToJson());
            }

            RelayResultReason reason = system.Blockchain.Ask <RelayResultReason>(neoTx).Result;

            switch (reason)
            {
            case RelayResultReason.Succeed:
                TransactionIdentifier      transactionIdentifier = new TransactionIdentifier(neoTx.Hash.ToString());
                ConstructionSubmitResponse response = new ConstructionSubmitResponse(transactionIdentifier);
                return(response.ToJson());

            case RelayResultReason.AlreadyExists:
                return(Error.ALREADY_EXISTS.ToJson());

            case RelayResultReason.OutOfMemory:
                return(Error.OUT_OF_MEMORY.ToJson());

            case RelayResultReason.UnableToVerify:
                return(Error.UNABLE_TO_VERIFY.ToJson());

            case RelayResultReason.Invalid:
                return(Error.TX_INVALID.ToJson());

            case RelayResultReason.PolicyFail:
                return(Error.POLICY_FAIL.ToJson());

            default:
                return(Error.UNKNOWN_ERROR.ToJson());
            }
        }
 public Transaction(TransactionIdentifier transactionIdentifier, Operation[] operations, Metadata metadata = null)
 {
     TransactionIdentifier = transactionIdentifier;
     Operations            = operations;
     Metadata = metadata;
 }
Beispiel #6
0
 public ConstructionHashResponse(TransactionIdentifier transactionIdentifier, Metadata metadata = null)
 {
     TransactionIdentifier = transactionIdentifier;
     Metadata = metadata;
 }
Beispiel #7
0
        /// <summary>
        /// Get a block by its Block Identifier.
        /// If transactions are returned in the same call to the node as fetching the block,
        /// the response should include these transactions in the Block object.
        /// If not, an array of Transaction Identifiers should be returned.
        /// So /block/transaction fetches can be done to get all transaction information.
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public JObject Block(BlockRequest request)
        {
            var index = request.BlockIdentifier.Index;
            var hash  = request.BlockIdentifier.Hash;

            if (index == null && hash == null)
            {
                return(Error.BLOCK_IDENTIFIER_INVALID.ToJson());
            }
            if (index != null && index < 0)
            {
                return(Error.BLOCK_INDEX_INVALID.ToJson());
            }

            NeoBlock neoBlock;
            UInt256  blockHash;

            if (hash != null)
            {
                if (!UInt256.TryParse(hash, out blockHash))
                {
                    return(Error.BLOCK_HASH_INVALID.ToJson());
                }
            }
            else
            {
                blockHash = Blockchain.Singleton.GetBlockHash((uint)index);
                if (blockHash == null)
                {
                    return(Error.BLOCK_INDEX_INVALID.ToJson());
                }
            }
            neoBlock = Blockchain.Singleton.GetBlock(blockHash);
            if (neoBlock == null)
            {
                return(Error.BLOCK_NOT_FOUND.ToJson());
            }
            BlockIdentifier blockIdentifier = new BlockIdentifier(neoBlock.Index, neoBlock.Hash.ToString());

            // get parent block
            BlockIdentifier parentBlockIdentifier;

            if (neoBlock.Index == 0)
            {
                parentBlockIdentifier = blockIdentifier;
            }
            else
            {
                var parentBlockHash = Blockchain.Singleton.GetBlockHash(neoBlock.Index - 1);
                if (parentBlockHash == null)
                {
                    return(Error.BLOCK_INDEX_INVALID.ToJson());
                }

                var parentBlock = Blockchain.Singleton.GetBlock(parentBlockHash);
                if (parentBlock == null)
                {
                    return(Error.BLOCK_NOT_FOUND.ToJson());
                }

                parentBlockIdentifier = new BlockIdentifier(parentBlock.Index, parentBlock.Hash.ToString());
            }

            // handle transactions
            Transaction[]           transactions      = new Transaction[] { };
            TransactionIdentifier[] otherTransactions = new TransactionIdentifier[] { };
            foreach (var neoTx in neoBlock.Transactions)
            {
                var tx = ConvertTx(neoTx);
                if (tx == null)
                {
                    continue;
                }
                if (tx.Operations.Length > 0)
                {
                    transactions = transactions.Append(tx).ToArray();
                }
                else
                {
                    otherTransactions = otherTransactions.Append(new TransactionIdentifier(neoTx.Hash.ToString())).ToArray();
                }
            }

            Block         block    = new Block(blockIdentifier, parentBlockIdentifier, neoBlock.Timestamp * 1000, transactions);
            BlockResponse response = new BlockResponse(block, otherTransactions.Length > 0 ? otherTransactions : null);

            return(response.ToJson());
        }
Beispiel #8
0
 public BlockTransactionRequest(NetworkIdentifier networkIdentifier, BlockIdentifier blockIdentifier, TransactionIdentifier transactionIdentifier)
 {
     NetworkIdentifier     = networkIdentifier;
     BlockIdentifier       = blockIdentifier;
     TransactionIdentifier = transactionIdentifier;
 }
Beispiel #9
0
 public MempoolTransactionRequest(NetworkIdentifier networkIdentifier, TransactionIdentifier transactionIdentifier)
 {
     NetworkIdentifier     = networkIdentifier;
     TransactionIdentifier = transactionIdentifier;
 }