private static SignedTx GetSignedTx(StObject tx, TestAccount src)
 {
     if (tx.Has(Field.Signers) || tx.Has(Field.TxnSignature))
     {
         return(TxSigner.ValidateAndEncode(tx));
     }
     return(src.Signer.SignStObject(tx));
 }
 public void AutoPopulateFields(TestAccount src, StObject tx)
 {
     if (!tx.Has(Field.Sequence))
     {
         tx[Field.Sequence] = src.NextSequence++;
     }
     if (!tx.Has(Field.Fee))
     {
         tx[Field.Fee] = DefaultFee;
     }
     if (!tx.Has(Field.Account))
     {
         tx[Field.Account] = src.Id;
     }
 }
예제 #3
0
        internal static void Validate(StObject obj, Action \ \ onError)
        {
            if (!obj.Has(Field.TransactionType))
            {
                onError("Missing `TransactionType` field");
                return;
            }

            var tt = obj[Field.TransactionType];

            if (tt == null)
            {
                onError("`TransactionType` is set to null");
                return;
            }

            var format    = Formats[tt];
            var allFields = new SortedSet \ \ (obj.Fields.Keys);

            allFields.UnionWith(format.Keys);

            foreach (var field in allFields)
            {
                var             inFormat = format.ContainsKey(field);
                ISerializedType fieldValue;
                var             inObject = obj.Fields.TryGetValue(field, out fieldValue);
                if (!inFormat)
                {
                    onError($"`{tt}` has no `{field}` field");
                }
                else if (format[field] == Requirement.Required)
                {
                    if (!inObject)
                    {
                        onError($"`{tt}` has required field `{field}`");
                    }
                    else if (fieldValue == null)
                    {
                        onError($"Required field `{field}` is set to null");
                    }
                    // TODO: associated type for field is wrong
                    // It should be nearly impossible anyway because FromJson
                    // throws when the json is invalid for the field type and
                    // the StObject[] indexers all use typed fields externally
                }
            }
        }
예제 #4
0
        public void test_parsing_transaction_meta_with_STArray()
        {
            TransactionMeta meta  = (TransactionMeta)StObject.FromJObject(JObject.Parse(this.metastring));
            StArray         nodes = meta[StArray.AffectedNodes];

            // Some helper methods to get enum fields
            Assert.AreEqual(TransactionEngineResult.tesSUCCESS, meta.TransactionResult());

            StObject firstAffected = nodes[0];

            Assert.AreEqual(
                LedgerEntryType.AccountRoot,
                ((AccountRoot)firstAffected[StObject.ModifiedNode]).LedgerEntryType());

            Assert.True(firstAffected.Has(StObject.ModifiedNode));
            Assert.AreEqual(new UInt32((long)35), this.finalSequence(firstAffected));
            Assert.AreEqual(new UInt32((long)177), this.finalSequence(nodes[1]));
        }
예제 #5
0
 public static bool IsAffectedNode(StObject source)
 {
     return (source.Count == 1 && source.Has(DeletedNode) || source.Has(CreatedNode) || source.Has(ModifiedNode));
 }
예제 #6
0
 public static bool IsAffectedNode(StObject source)
 {
     return(source.Count == 1 && source.Has(DeletedNode) || source.Has(CreatedNode) || source.Has(ModifiedNode));
 }
예제 #7
0
 public static bool IsTransactionMeta(StObject source)
 {
     return(source.Has(UInt8.TransactionResult) && source.Has(Field.AffectedNodes));
 }