/// <summary> /// /// </summary> /// <param name="transfer"></param> /// <returns></returns> public static TransferModel ToTransferModel(this TransferNotifyItem transfer) { return(new TransferModel() { From = transfer.From, To = transfer.To, Amount = new BigDecimal(transfer.Amount, transfer.Decimals).ToString(), Symbol = transfer.Symbol, }); }
/// <summary> /// try to convert "Transfer" event, missing "Decimals"、"Symbol" /// </summary> /// <param name="notification"></param> /// <returns></returns> public static TransferNotifyItem ConvertToTransfer(this NotifyEventArgs notification) { if (!"transfer".Equals(notification.EventName, StringComparison.OrdinalIgnoreCase) || notification.State.Count < 3) { return null; } var notify = notification.State; var fromItem = notify[0]; var toItem = notify[1]; var amountItem = notify[2]; if (!fromItem.IsVmNullOrByteArray() || !toItem.IsVmNullOrByteArray()) { return null; } var from = fromItem.GetByteSafely(); if (from != null && from.Length != UInt160.Length) { return null; } var to = toItem.GetByteSafely(); if (to != null && to.Length != UInt160.Length) { return null; } if (from == null && to == null) { return null; } if (amountItem.NotVmByteArray() && amountItem.NotVmInt()) { return null; } var amount = amountItem.ToBigInteger(); if (amount == null) { return null; } var record = new TransferNotifyItem { From = from == null ? null : new UInt160(from), To = to == null ? null : new UInt160(to), Amount = amount.Value, Asset = notification.ScriptHash, }; return record; }
public static TransferNotifyItem GetTransferNotify(this VmArray notifyArray, UInt160 asset) { if (notifyArray.Count < 4) return null; // Event name should be encoded as a byte array. if (notifyArray[0].NotVmByteArray()) return null; var eventName = notifyArray[0].GetString(); if (!"Transfer".Equals(eventName, StringComparison.OrdinalIgnoreCase)) return null; var fromItem = notifyArray[1]; if (fromItem.NotVmByteArray() && fromItem.NotVmNull()) return null; var fromBytes = fromItem.GetByteSafely(); if (fromBytes?.Length != 20) { fromBytes = null; } var toItem = notifyArray[2]; if (toItem != null && toItem.NotVmByteArray()) return null; byte[] toBytes = toItem.GetByteSafely(); if (toBytes?.Length != 20) { toBytes = null; } if (fromBytes == null && toBytes == null) return null; var amountItem = notifyArray[3]; if (amountItem.NotVmByteArray() && amountItem.NotVmInt()) return null; var transfer = new TransferNotifyItem() { Asset = asset, From = fromBytes == null ? null : new UInt160(fromBytes), To = new UInt160(toBytes), Amount = amountItem.GetInteger(), }; return transfer; }
public static TransferNotifyItem GetTransferNotify(this VmArray notifyArray, UInt160 asset) { if (notifyArray.Count < 4) { return(null); } // Event name should be encoded as a byte array. if (notifyArray[0].NotVmByteArray()) { return(null); } var eventName = notifyArray[0].GetString(); if (eventName != "Transfer") { return(null); } var fromItem = notifyArray[1]; if (fromItem.NotVmByteArray() && fromItem.NotVmNull()) { return(null); } var fromBytes = fromItem.GetByteSafely(); if (fromBytes?.Length != 20) { fromBytes = null; } var toItem = notifyArray[2]; if (toItem != null && toItem.NotVmByteArray()) { return(null); } byte[] toBytes = toItem.GetByteSafely(); if (toBytes?.Length != 20) { toBytes = null; } if (fromBytes == null && toBytes == null) { return(null); } var amountItem = notifyArray[3]; if (amountItem.NotVmByteArray() && amountItem.NotVmInt()) { return(null); } var transfer = new TransferNotifyItem() { Asset = asset, From = fromBytes == null ? null : new UInt160(fromBytes), To = new UInt160(toBytes), Amount = amountItem.GetBigInteger(), }; return(transfer); }