예제 #1
0
        private JObject SendMany(JArray _params)
        {
            CheckWallet();
            int     to_start = 0;
            UInt160 from     = null;

            if (_params[0] is JString)
            {
                from     = _params[0].AsString().ToScriptHash();
                to_start = 1;
            }
            JArray to = (JArray)_params[to_start];

            if (to.Count == 0)
            {
                throw new RpcException(-32602, "Invalid params");
            }
            TransferOutput[] outputs = new TransferOutput[to.Count];
            for (int i = 0; i < to.Count; i++)
            {
                UInt160         asset_id   = UInt160.Parse(to[i]["asset"].AsString());
                AssetDescriptor descriptor = new AssetDescriptor(asset_id);
                outputs[i] = new TransferOutput
                {
                    AssetId    = asset_id,
                    Value      = BigDecimal.Parse(to[i]["value"].AsString(), descriptor.Decimals),
                    ScriptHash = to[i]["address"].AsString().ToScriptHash()
                };
                if (outputs[i].Value.Sign <= 0)
                {
                    throw new RpcException(-32602, "Invalid params");
                }
            }
            Transaction tx = wallet.MakeTransaction(outputs, from);

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

            ContractParametersContext transContext = new ContractParametersContext(tx);

            wallet.Sign(transContext);
            if (!transContext.Completed)
            {
                return(transContext.ToJson());
            }
            tx.Witnesses = transContext.GetWitnesses();
            if (tx.Size > 1024)
            {
                long calFee = tx.Size * 1000 + 100000;
                if (tx.NetworkFee < calFee)
                {
                    tx.NetworkFee = calFee;
                }
            }
            if (tx.NetworkFee > settings.MaxFee)
            {
                throw new RpcException(-301, "The necessary fee is more than the Max_fee, this transaction is failed. Please increase your Max_fee value.");
            }
            return(SignAndRelay(tx));
        }