// TODO, move these some where more specific // leave these here as static methods // delegate from more specific places public static TransactionEngineResult TransactionResult(StObject obj) { var uInt8 = obj[UInt8.TransactionResult]; if (uInt8 == null) { return(null); } return(TransactionEngineResult.FromNumber(uInt8.IntValue())); }
public int AsInteger(string s) { return TransactionEngineResult.FromString(s).AsInteger; }
public TransactionResult(JObject json, Source resultMessageSource) { Message = json; try { if (resultMessageSource == Source.transaction_subscription_notification) { EngineResult = TransactionEngineResult.FromString(json.GetValue("engine_result").ToObject <string>()); Validated = json.GetValue("validated").ToObject <bool>(); LedgerHash = Hash256.OutTranslate.FromString(json.GetValue("ledger_hash").ToObject <string>()); LedgerIndex = new UInt32(json.GetValue("ledger_index").ToObject <long>()); JToken transaction; if (json.TryGetValue("transaction", out transaction)) { Txn = (Transaction)StObject.FromJObject(transaction.ToObject <JObject>()); Hash = Txn[Hash256.hash]; } JToken meta; if (json.TryGetValue("meta", out meta)) { Meta = (TransactionMeta)StObject.FromJObject(meta.ToObject <JObject>()); } } else if (resultMessageSource == Source.request_tx_result) { JToken validated; Validated = json.TryGetValue("validated", out validated) && validated.ToObject <bool>(); JToken meta; if (Validated && !json.TryGetValue("meta", out meta)) { throw new InvalidOperationException("It's validated, why doesn't it have meta??"); } if (Validated) { Meta = (TransactionMeta)StObject.FromJObject(json.GetValue("meta").ToObject <JObject>()); EngineResult = TransactionEngineResult.FromNumber(Meta[UInt8.TransactionResult]); Txn = (Transaction)StObject.FromJObject(json); Hash = Txn[Hash256.hash]; LedgerHash = null; // XXXXXX } } else if (resultMessageSource == Source.request_account_tx) { JToken validated; Validated = json.TryGetValue("validated", out validated) && validated.ToObject <bool>(); JToken meta; if (Validated && !json.TryGetValue("meta", out meta)) { throw new InvalidOperationException("It's validated, why doesn't it have meta??"); } if (Validated) { var tx = json.GetValue("tx").ToObject <JObject>(); Meta = (TransactionMeta)StObject.FromJObject(json.GetValue("meta").ToObject <JObject>()); EngineResult = TransactionEngineResult.FromNumber(Meta[UInt8.TransactionResult]); Txn = (Transaction)StObject.FromJObject(tx); Hash = Txn[Hash256.hash]; LedgerIndex = new UInt32(tx.GetValue("ledger_index").ToObject <long>()); LedgerHash = null; } } else if (resultMessageSource == Source.request_account_tx_binary) { JToken validated; Validated = json.TryGetValue("validated", out validated) && validated.ToObject <bool>(); JToken meta; if (Validated && !json.TryGetValue("meta", out meta)) { throw new InvalidOperationException("It's validated, why doesn't it have meta??"); } if (Validated) { /* * { * "ledger_index": 3378767, * "meta": "201 ...", * "tx_blob": "120 ...", * "validated": true * }, */ var tx = json.GetValue("tx_blob").ToObject <string>(); byte[] decodedTx = B16.Decode(tx); Meta = (TransactionMeta)StObject.OutTranslate.FromHex(json.GetValue("meta").ToObject <string>()); Txn = (Transaction)StObject.OutTranslate.FromBytes(decodedTx); Hash = Hash256.TransactionId(decodedTx); Txn.Add(Field.hash, Hash); EngineResult = Meta.TransactionResult(); LedgerIndex = new UInt32(json.GetValue("ledger_index").ToObject <long>()); LedgerHash = null; } } } catch (JsonException e) { throw new ApplicationException("Json deserialization failed.", e); } }
public string AsString(int i) { return TransactionEngineResult.FromNumber(i).GetName(); }