Example #1
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);
        }
Example #2
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);
        }
Example #3
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);
        }