Exemplo n.º 1
0
        /// <summary>
        /// Creates the <see cref="Transaction{T}"/> object and builds normal payment transaction.
        /// </summary>
        /// <param name="options">The options for this transaction.</param>
        /// <returns>A <see cref="Transaction{T}"/> object.</returns>
        public Transaction <PaymentTxResponse> BuildPaymentTx(PaymentTxOptions options)
        {
            var tx = new InnerTransaction <PaymentTxData, PaymentTxResponse>(this);

            if (!Utils.IsValidAddress(options.Account))
            {
                tx.TxJson.Exception = new Exception("Invalid source address.");
                return(tx);
            }

            if (!Utils.IsValidAddress(options.To))
            {
                tx.TxJson.Exception = new Exception("Invalid destination address.");
                return(tx);
            }

            if (!Utils.IsValidAmount(options.Amount))
            {
                tx.TxJson.Exception = new Exception("Invalid amount.");
                return(tx);
            }

            tx.TransactionType    = TransactionType.Payment;
            tx.TxJson.Account     = options.Account;
            tx.TxJson.Amount      = Utils.ToAmount(options.Amount);
            tx.TxJson.Destination = options.To;

            return(tx);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates the <see cref="Transaction{T}"/> object and builds the deploy contract transaction.
        /// </summary>
        /// <param name="options">The options for this transaction.</param>
        /// <returns>A <see cref="Transaction{T}"/> object.</returns>
        public Transaction <DeployContractTxResponse> DeployContractTx(DeployContractTxOptions options)
        {
            var tx = new InnerTransaction <ContractTxData, DeployContractTxResponse>(this);

            if (!Utils.IsValidAddress(options.Account))
            {
                tx.TxJson.Exception = new Exception("Invalid address.");
                return(tx);
            }

            tx.TransactionType = TransactionType.ConfigContract;
            tx.TxJson.Account  = options.Account;
            tx.TxJson.Amount   = (options.Amount * 1000000).ToString("0");
            tx.TxJson.Method   = 0;
            tx.TxJson.Payload  = Utils.StringToHex(options.Payload);
            tx.TxJson.Args     = options.Params == null ? new ArgInfo[0] : options.Params.Select(p =>
            {
                var parameter = new ParameterInfo {
                    Parameter = Utils.StringToHex(p)
                };
                var arg = new ArgInfo {
                    Arg = parameter
                };
                return(arg);
            });

            return(tx);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Creates the <see cref="Transaction{T}"/> object and builds the sign transaction.
        /// </summary>
        /// <param name="options">The options for this transaction.</param>
        /// <returns>A <see cref="Transaction{T}"/> object.</returns>
        public Transaction <SignTxResponse> BuildSignTx(SignTxOptions options)
        {
            var tx = new InnerTransaction <TxData, SignTxResponse>(this);

            tx.TransactionType = TransactionType.Signer;
            tx.TxJson.Blob     = options.Blob;
            return(tx);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Creates the <see cref="Transaction{T}"/> object and builds the offer cancel transaction.
        /// </summary>
        /// <param name="options">The options for this transaction.</param>
        /// <remarks>
        /// The order can be cancel by order sequence.
        /// The sequence can be get when order is submitted or from offer query operation.
        /// </remarks>
        /// <returns>A <see cref="Transaction{T}"/> object.</returns>
        public Transaction <OfferCancelTxResponse> BuildOfferCancelTx(OfferCancelTxOptions options)
        {
            var tx = new InnerTransaction <OfferCancelTxData, OfferCancelTxResponse>(this);

            if (!Utils.IsValidAddress(options.Account))
            {
                tx.TxJson.Exception = new Exception("Invalid source address.");
                return(tx);
            }

            tx.TransactionType      = TransactionType.OfferCancel;
            tx.TxJson.Account       = options.Account;
            tx.TxJson.OfferSequence = options.Sequence;
            return(tx);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Creates the <see cref="Transaction{T}"/> object and builds the relation transaction.
        /// </summary>
        /// <param name="options">The options for this transaction.</param>
        /// <returns>A <see cref="Transaction{T}"/> object.</returns>
        public Transaction <RelationTxResponse> BuildRelationTx(RelationTxOptions options)
        {
            var tx = new InnerTransaction <RelationTxData, RelationTxResponse>(this);

            switch (options.Type)
            {
            case RelationType.Trust:
                return(BuildTrustSet(options, tx));

            case RelationType.Authorize:
            case RelationType.Freeze:
            case RelationType.Unfreeze:
                return(BuildRelationSet(options, tx));
            }

            tx.TxJson.Exception = new Exception("Build relation set should not go here.");
            return(tx);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Creates the <see cref="Transaction{T}"/> object and builds the set account attribute transaction.
        /// </summary>
        /// <param name="options">The options for this transaction.</param>
        /// <returns>A <see cref="Transaction{T}"/> object.</returns>
        public Transaction <AccountSetTxResponse> BuildAccountSetTx(AccountSetTxOptions options)
        {
            var tx = new InnerTransaction <AccountSetTxData, AccountSetTxResponse>(this);

            switch (options.Type)
            {
            case AccountSetType.Property:
                return(BuildAccountSet(options, tx));

            case AccountSetType.Delegate:
                return(BuildDelegateKeySet(options, tx));

            case AccountSetType.Signer:
                return(BuildSignerSet(options, tx));
            }

            tx.TxJson.Exception = new Exception("Build account set should not go here.");
            return(tx);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Creates the <see cref="Transaction{T}"/> object and builds the call contract transaction.
        /// </summary>
        /// <param name="options">The options for this transaction.</param>
        /// <returns>A <see cref="Transaction{T}"/> object.</returns>
        public Transaction <CallContractTxResponse> CallContractTx(CallContractTxOptions options)
        {
            var tx = new InnerTransaction <ContractTxData, CallContractTxResponse>(this);

            if (!Utils.IsValidAddress(options.Account))
            {
                tx.TxJson.Exception = new Exception("Invalid address.");
                return(tx);
            }

            if (!Utils.IsValidAddress(options.Destination))
            {
                tx.TxJson.Exception = new Exception("Invalid destination.");
                return(tx);
            }

            if (string.IsNullOrEmpty(options.Foo))
            {
                tx.TxJson.Exception = new Exception("Foo must be set.");
                return(tx);
            }

            tx.TransactionType       = TransactionType.ConfigContract;
            tx.TxJson.Account        = options.Account;
            tx.TxJson.Method         = 1;
            tx.TxJson.ContractMethod = Utils.StringToHex(options.Foo);
            tx.TxJson.Destination    = options.Destination;
            tx.TxJson.Args           = options.Params == null ? new ArgInfo[0] : options.Params.Select(p =>
            {
                var parameter = new ParameterInfo {
                    Parameter = Utils.StringToHex(p)
                };
                var arg = new ArgInfo {
                    Arg = parameter
                };
                return(arg);
            });

            return(tx);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Creates the <see cref="Transaction{T}"/> object and builds the offer create transaction.
        /// </summary>
        /// <param name="options">The options for this transaction.</param>
        /// <returns>A <see cref="Transaction{T}"/> object.</returns>
        public Transaction <OfferCreateTxResponse> BuildOfferCreateTx(OfferCreateTxOptions options)
        {
            var tx = new InnerTransaction <OfferCreateTxData, OfferCreateTxResponse>(this);

            if (!Utils.IsValidAddress(options.Account))
            {
                tx.TxJson.Exception = new Exception("Invalid source address.");
                return(tx);
            }

            var takerGets = options.TakerGets;
            var takerPays = options.TakerPays;

            if (!Utils.IsValidAmount(takerGets))
            {
                tx.TxJson.Exception = new Exception("Invalid to pays amount.");
                return(tx);
            }

            if (!Utils.IsValidAmount(takerPays))
            {
                tx.TxJson.Exception = new Exception("Invalid to gets amount.");
                return(tx);
            }

            tx.TransactionType = TransactionType.OfferCreate;
            if (options.Type == OfferType.Sell)
            {
                tx.SetFlags((UInt32)OfferCreateFlags.Sell);
            }
            tx.TxJson.Account   = options.Account;
            tx.TxJson.TakerPays = Utils.ToAmount(takerPays);
            tx.TxJson.TakerGets = Utils.ToAmount(takerGets);

            return(tx);
        }
Exemplo n.º 9
0
 private InnerTransaction <AccountSetTxData, V> BuildSignerSet <V>(AccountSetTxOptions options, InnerTransaction <AccountSetTxData, V> tx)
     where V : GeneralTxResponse
 {
     tx.TxJson.Exception = new Exception("Not implemented.");
     return(tx);
 }
Exemplo n.º 10
0
        private InnerTransaction <AccountSetTxData, V> BuildDelegateKeySet <V>(AccountSetTxOptions options, InnerTransaction <AccountSetTxData, V> tx)
            where V : GeneralTxResponse
        {
            if (!Utils.IsValidAddress(options.Account))
            {
                tx.TxJson.Exception = new Exception("Invalid source address.");
                return(tx);
            }

            if (!Utils.IsValidAddress(options.DelegateKey))
            {
                tx.TxJson.Exception = new Exception("Invalid regular key address.");
                return(tx);
            }

            tx.TransactionType   = TransactionType.SetRegularKey;
            tx.TxJson.Account    = options.Account;
            tx.TxJson.RegularKey = options.DelegateKey;

            return(tx);
        }
Exemplo n.º 11
0
        private InnerTransaction <AccountSetTxData, V> BuildAccountSet <V>(AccountSetTxOptions options, InnerTransaction <AccountSetTxData, V> tx)
            where V : GeneralTxResponse
        {
            if (!Utils.IsValidAddress(options.Account))
            {
                tx.TxJson.Exception = new Exception("Invalid source address.");
                return(tx);
            }

            tx.TransactionType = TransactionType.AccountSet;
            tx.TxJson.Account  = options.Account;

            if (options.SetFlag != null)
            {
                tx.TxJson.SetFlag = (UInt32)options.SetFlag.Value;
            }

            if (options.ClearFlag != null)
            {
                tx.TxJson.ClearFlag = (UInt32)options.ClearFlag.Value;
            }

            return(tx);
        }
Exemplo n.º 12
0
        private InnerTransaction <RelationTxData, V> BuildRelationSet <V>(RelationTxOptions options, InnerTransaction <RelationTxData, V> tx)
            where V : GeneralTxResponse
        {
            if (!Utils.IsValidAddress(options.Account))
            {
                tx.TxJson.Exception = new Exception("Invalid source address.");
                return(tx);
            }

            if (!Utils.IsValidAddress(options.Target))
            {
                tx.TxJson.Exception = new Exception("Invalid target address.");
                return(tx);
            }

            if (!Utils.IsValidAmount(options.Limit))
            {
                tx.TxJson.Exception = new Exception("Invalid amount.");
                return(tx);
            }

            tx.TransactionType     = options.Type == RelationType.Unfreeze ? TransactionType.RelationDel : TransactionType.RelationSet;
            tx.TxJson.Account      = options.Account;
            tx.TxJson.Target       = options.Target;
            tx.TxJson.RelationType = (uint)(options.Type == RelationType.Authorize ? 1 : 3);
            if (options.Limit != null)
            {
                tx.TxJson.LimitAmount = options.Limit;
            }

            return(tx);
        }
Exemplo n.º 13
0
        private InnerTransaction <RelationTxData, V> BuildTrustSet <V>(RelationTxOptions options, InnerTransaction <RelationTxData, V> tx)
            where V : GeneralTxResponse
        {
            if (!Utils.IsValidAddress(options.Account))
            {
                tx.TxJson.Exception = new Exception("Invalid source address.");
                return(tx);
            }

            if (!Utils.IsValidAmount(options.Limit))
            {
                tx.TxJson.Exception = new Exception("Invalid amount.");
                return(tx);
            }

            tx.TransactionType = TransactionType.TrustSet;
            tx.TxJson.Account  = options.Account;
            if (options.Limit != null)
            {
                tx.TxJson.LimitAmount = options.Limit;
            }
            if (options.QualityIn != null)
            {
                tx.TxJson.QualityIn = options.QualityIn.Value;
            }
            if (options.QualityOut != null)
            {
                tx.TxJson.QualityOut = options.QualityOut.Value;
            }

            return(tx);
        }