public IActionResult GetRawTransaction(string txid, bool verbose = false)
        {
            UInt256     hash = UInt256.Parse(txid);
            Transaction tx   = Blockchain.Singleton.GetTransaction(hash);

            if (tx == null)
            {
                throw new RestException(-100, "Unknown transaction");
            }
            if (verbose)
            {
                JObject          json    = tx.ToJson();
                TransactionState txState = Blockchain.Singleton.View.Transactions.TryGet(hash);
                if (txState != null)
                {
                    Header header = Blockchain.Singleton.GetHeader(txState.BlockIndex);
                    json["blockhash"]     = header.Hash.ToString();
                    json["confirmations"] = Blockchain.Singleton.Height - header.Index + 1;
                    json["blocktime"]     = header.Timestamp;
                    json["vmState"]       = txState.VMState;
                }
                return(FormatJson(json));
            }
            return(FormatJson(tx.ToArray().ToHexString()));
        }
示例#2
0
        protected virtual JObject GetRawTransaction(JArray _params)
        {
            UInt256     hash    = UInt256.Parse(_params[0].AsString());
            bool        verbose = _params.Count >= 2 && _params[1].AsBoolean();
            Transaction tx      = Blockchain.Singleton.GetTransaction(hash);

            if (tx == null)
            {
                throw new RpcException(-100, "Unknown transaction");
            }
            if (verbose)
            {
                JObject          json    = tx.ToJson();
                TransactionState txState = Blockchain.Singleton.View.Transactions.TryGet(hash);
                if (txState != null)
                {
                    Header header = Blockchain.Singleton.GetHeader(txState.BlockIndex);
                    json["blockhash"]     = header.Hash.ToString();
                    json["confirmations"] = Blockchain.Singleton.Height - header.Index + 1;
                    json["blocktime"]     = header.Timestamp;
                    json["vmstate"]       = txState.VMState;
                }
                return(json);
            }
            return(Convert.ToBase64String(tx.ToArray()));
        }
示例#3
0
        public static JObject TransactionToJson(Transaction tx, ProtocolSettings settings)
        {
            JObject json = tx.ToJson(settings);

            json["sysfee"] = tx.SystemFee.ToString();
            json["netfee"] = tx.NetworkFee.ToString();
            return(json);
        }
示例#4
0
        public static JObject TransactionToJson(Transaction tx)
        {
            JObject json = tx.ToJson();

            json["sysfee"] = new BigDecimal(tx.SystemFee, NativeContract.GAS.Decimals).ToString();
            json["netfee"] = new BigDecimal(tx.NetworkFee, NativeContract.GAS.Decimals).ToString();
            return(json);
        }
        public JObject ToJson()
        {
            JObject json = new JObject();

            json["transaction"] = Transaction.ToJson();
            if (Metadata != null && Metadata.ToJson() != null)
            {
                json["metadata"] = Metadata.ToJson();
            }
            return(json);
        }
 private void AddTransaction(Transaction tx, ulong ts, ulong height)
 {
     if (tx != null)
     {
         Console.WriteLine($"Adding transaction {tx.Hash} to DynamoDB table");
         JObject j = tx.ToJson();
         j["time"]  = ts;
         j["block"] = height;
         Document d = Document.FromJson(j.ToString());
         TransactionsTable.UpdateItemAsync(d);
     }
 }
示例#7
0
        private JObject SignAndRelay(Transaction tx)
        {
            ContractParametersContext context = new ContractParametersContext(tx);

            wallet.Sign(context);
            if (context.Completed)
            {
                tx.Witnesses = context.GetWitnesses();
                system.Blockchain.Tell(tx);
                return(tx.ToJson());
            }
            else
            {
                return(context.ToJson());
            }
        }
示例#8
0
        private JObject SignAndRelay(Transaction tx)
        {
            ContractParametersContext context = new ContractParametersContext(tx);

            Wallet.Sign(context);
            if (context.Completed)
            {
                tx.Witnesses = context.GetWitnesses();
                System.LocalNode.Tell(new LocalNode.Relay {
                    Inventory = tx
                });
                return(tx.ToJson());
            }
            else
            {
                return(context.ToJson());
            }
        }
示例#9
0
        public JObject OnProcess(HttpContext context, string method, JArray _params)
        {
            if (_deniedMethods.Contains(method))
            {
                throw new RpcException(-400, "Access denied");
            }

            if (method == "faucet")
            {
                system = Plugin.System;
                RpcServer  rpcserver   = system.RpcServer;
                Wallet     Wallet      = rpcserver.Wallet;
                UInt160    script_hash = UInt160.Parse(_params[0].AsString());
                UInt160    asset_id    = UInt160.Parse(Settings.Default.TokenHash);
                UInt160    from_addr   = UInt160.Parse(Settings.Default.FromAddr);
                BigDecimal value       = BigDecimal.Parse(Settings.Default.AmountPerDay, (byte)0);

                DateTime now   = DateTime.Now;
                string   today = now.ToString("yyyyMMdd");

                List <TransactionAttribute> attrs = new List <TransactionAttribute>               {
                    new TransactionAttribute
                    {
                        Usage = TransactionAttributeUsage.Remark,
                        Data  = Encoding.UTF8.GetBytes(today)
                    }
                };

                Transaction tx = Wallet.MakeTransaction(attrs, new[]
                {
                    new TransferOutput
                    {
                        AssetId    = asset_id,
                        Value      = value,
                        ScriptHash = script_hash
                    }
                }, from_addr, null, Fixed8.Zero);

                if (tx == null)
                {
                    throw new RpcException(-300, "MakeTransaction failed");
                }

                ContractParametersContext ctx = new ContractParametersContext(tx);
                Wallet.Sign(ctx);
                if (ctx.Completed)
                {
                    tx.Witnesses = ctx.GetWitnesses();
                    Wallet.ApplyTransaction(tx);
                    system.LocalNode.Tell(new LocalNode.Relay {
                        Inventory = tx
                    }, null);
                    return(tx.ToJson());
                }
                else
                {
                    return(ctx.ToJson());
                }
            }
            return(null);
        }