Esempio n. 1
0
        public void testFormatted()
        {
            StObject offer = new StObject();

            offer.Add(UInt16.LedgerEntryType, LedgerEntryType.Offer.AsInteger);
            offer.Add(Amount.TakerGets, "1.0");
            offer.Add(Amount.TakerPays, "2.0");

            Offer casted = (Offer)StObject.Formatted(offer);

            Assert.AreEqual(casted.AskQuality.ToPlainString(), "2");
        }
Esempio n. 2
0
        public void testTypeInference()
        {
            StObject so = StObject.NewInstance();

            so.Add(Field.FromString("LowLimit"), "10.0/USD");
            so.Add(Amount.Balance, "125.0");

            Assert.AreEqual(so[Amount.Balance].ToDropsString(), "125000000");
            Assert.AreEqual(so[Amount.LowLimit].CurrencyString, "USD");

            Assert.NotNull(so[Amount.LowLimit]);
            Assert.Null(so[Amount.HighLimit]);
        }
Esempio n. 3
0
        public StObject RebuildFromMeta(bool layerPrevious)
        {
            var  mixed   = new StObject();
            bool created = IsCreatedNode;

            var wrapperField = created
                ? Field.CreatedNode
                : IsDeletedNode
                    ? Field.DeletedNode
                    : Field.ModifiedNode;

            var wrapped = (StObject) base[wrapperField];

            var finalFields = created
                ? Field.NewFields
                : Field.FinalFields;

            var finals = (StObject)wrapped[finalFields];

            foreach (var field in finals)
            {
                mixed.Add(field, finals[field]);
            }

            // DirectoryNode LedgerEntryType won't have `PreviousFields`
            if (layerPrevious && wrapped.Has(Field.PreviousFields))
            {
                var previous = wrapped[PreviousFields];
                var changed  = new StObject();
                mixed.Add(Field.FinalFields, changed);

                foreach (var field in previous)
                {
                    mixed.Add(field, previous[field]);
                    changed.Add(field, finals[field]);
                }
            }

            foreach (var field in wrapped)
            {
                if (field == Field.NewFields || field == Field.PreviousFields || field == Field.FinalFields)
                {
                    continue;
                }

                mixed.Add(field, wrapped[field]);
            }
            return(Formatted(mixed));
        }
Esempio n. 4
0
        public void testSerializedPaymentTransaction()
        {
            string expectedSerialization =
                "120000240000000561D4C44364C5BB00000000000000000000000000005553440000000000B5F762798A53D543A014CAF8B297CFF8F2F937E868400000000000000F73210330E7FC9D56BB25D6893BA3F317AE5BCF33B3291BD63DB32654A313222F7FD0208114B5F762798A53D543A014CAF8B297CFF8F2F937E88314FD94A75318DE40B1D513E6764ECBCB6F1E7056ED";

            AccountId ac     = AccountId.FromSeed(TestFixtures.MasterSeed);
            StObject  fromSO = StObject.NewInstance();

            fromSO.Add(Field.TransactionType, "Payment");
            fromSO.Add(AccountId.Account, ac.Address);
            fromSO.Add(UInt32.Sequence, 5);
            fromSO.Add(Amount.Fee, "15");
            fromSO.Add(VariableLength.SigningPubKey, ac.KeyPair.PubHex());
            fromSO.Add(AccountId.Destination, TestFixtures.BobAccount.Address);
            fromSO.Add(Amount.AmountFld, "12/USD/" + ac.Address);

            Assert.AreEqual(expectedSerialization, fromSO.ToHex());
        }
Esempio n. 5
0
        public StObject RebuildFromMeta(bool layerPrevious)
        {
            var mixed = new StObject();
            bool created = IsCreatedNode;

            var wrapperField = created
                ? Field.CreatedNode
                : IsDeletedNode
                    ? Field.DeletedNode
                    : Field.ModifiedNode;

            var wrapped = (StObject)base[wrapperField];

            var finalFields = created
                ? Field.NewFields
                : Field.FinalFields;

            var finals = (StObject) wrapped[finalFields];
            foreach (var field in finals)
            {
                mixed.Add(field, finals[field]);
            }

            // DirectoryNode LedgerEntryType won't have `PreviousFields`
            if (layerPrevious && wrapped.Has(Field.PreviousFields))
            {
                var previous = wrapped[PreviousFields];
                var changed = new StObject();
                mixed.Add(Field.FinalFields, changed);

                foreach (var field in previous)
                {
                    mixed.Add(field, previous[field]);
                    changed.Add(field, finals[field]);
                }
            }

            foreach (var field in wrapped)
            {
                if (field == Field.NewFields || field == Field.PreviousFields || field == Field.FinalFields)
                {
                    continue;
                }

                mixed.Add(field, wrapped[field]);
            }
            return Formatted(mixed);
        }