void ISerializable.Deserialize(BinaryReader reader)
 {
     this.AssetId = reader.ReadSerializable<UInt256>();
     this.Value = reader.ReadSerializable<Fixed8>();
     if (Value <= Fixed8.Zero) throw new FormatException();
     this.ScriptHash = reader.ReadSerializable<UInt160>();
 }
 public static TransactionOutput Create(Fixed8 value, string address)
 {
     if (address == null) throw new ArgumentNullException(nameof(address));
     bool p2sh;
     UInt160 hash = Wallet.ToScriptHash(address, out p2sh);
     using (ScriptBuilder sb = new ScriptBuilder())
     {
         if (p2sh)
         {
             sb.Add(ScriptOp.OP_HASH160);
             sb.Push(hash.ToArray());
             sb.Add(ScriptOp.OP_EQUAL);
         }
         else
         {
             sb.Add(ScriptOp.OP_DUP);
             sb.Add(ScriptOp.OP_HASH160);
             sb.Push(hash.ToArray());
             sb.Add(ScriptOp.OP_EQUALVERIFY);
             sb.Add(ScriptOp.OP_CHECKSIG);
         }
         return new TransactionOutput
         {
             Value = value,
             Script = sb.ToArray()
         };
     }
 }
Beispiel #3
0
 void ISerializable.Deserialize(BinaryReader reader)
 {
     this.Amount = reader.ReadSerializable<Fixed8>();
     if (Amount == Fixed8.Zero) throw new FormatException();
     if (Amount.GetData() % 10000 != 0) throw new FormatException();
     this.Price = reader.ReadSerializable<Fixed8>();
     if (Price <= Fixed8.Zero) throw new FormatException();
     if (Price.GetData() % 10000 != 0) throw new FormatException();
     this.Client = reader.ReadSerializable<UInt160>();
 }
Beispiel #4
0
 void ISignable.FromUnsignedArray(byte[] value)
 {
     using (MemoryStream ms = new MemoryStream(value, false))
     using (BinaryReader reader = new BinaryReader(ms))
     {
         this.AssetId = reader.ReadSerializable<UInt256>();
         this.ValueAssetId = reader.ReadSerializable<UInt256>();
         this.Agent = reader.ReadSerializable<UInt160>();
         this.Amount = reader.ReadSerializable<Fixed8>();
         this.Price = reader.ReadSerializable<Fixed8>();
         this.Client = reader.ReadSerializable<UInt160>();
         this.Inputs = reader.ReadSerializableArray<TransactionInput>();
     }
 }
 protected override void DeserializeExclusiveData(BinaryReader reader)
 {
     this.AssetType = (AssetType)reader.ReadByte();
     if (!Enum.IsDefined(typeof(AssetType), AssetType))
         throw new FormatException();
     this.Name = reader.ReadVarString();
     this.Amount = reader.ReadSerializable<Fixed8>();
     if (Amount == Fixed8.Zero || Amount < -Fixed8.Satoshi) throw new FormatException();
     if (AssetType == AssetType.Share && Amount <= Fixed8.Zero)
         throw new FormatException();
     if (AssetType == AssetType.Currency && Amount != -Fixed8.Satoshi)
         throw new FormatException();
     this.Issuer = ECPoint.DeserializeFrom(reader, ECCurve.Secp256r1);
     this.Admin = reader.ReadSerializable<UInt160>();
 }
Beispiel #6
0
 private void DeserializeUnsignedInternal(BinaryReader reader, UInt256 asset_id, UInt256 value_asset_id, UInt160 agent)
 {
     AssetId = asset_id;
     ValueAssetId = value_asset_id;
     Agent = agent;
     Amount = reader.ReadSerializable<Fixed8>();
     if (Amount == Fixed8.Zero) throw new FormatException();
     if (Amount.GetData() % 10000 != 0) throw new FormatException();
     Price = reader.ReadSerializable<Fixed8>();
     if (Price <= Fixed8.Zero) throw new FormatException();
     if (Price.GetData() % 10000 != 0) throw new FormatException();
     Client = reader.ReadSerializable<UInt160>();
     Inputs = reader.ReadSerializableArray<TransactionInput>();
     if (Inputs.Distinct().Count() != Inputs.Length)
         throw new FormatException();
 }
Beispiel #7
0
 public override WalletUnspentCoin[] FindUnspentCoins(UInt256 asset_id, Fixed8 amount)
 {
     return FindUnspentCoins(FindUnspentCoins().Where(p => GetContract(p.ScriptHash) is SignatureContract), asset_id, amount) ?? base.FindUnspentCoins(asset_id, amount);
 }
 void ISerializable.Deserialize(BinaryReader reader)
 {
     this.AssetId = reader.ReadSerializable<UInt256>();
     this.Value = reader.ReadSerializable<Fixed8>();
     this.ScriptHash = reader.ReadSerializable<UInt160>();
 }
 void ISerializable.Deserialize(BinaryReader reader)
 {
     this.Value = reader.ReadSerializable<Fixed8>();
     this.Script = reader.ReadBytes((int)reader.ReadVarInt());
 }
Beispiel #10
0
 private static UnspentCoin[] FindUnspentCoins(IEnumerable<UnspentCoin> coins, Fixed8 total)
 {
     UnspentCoin[] coins_array = coins.ToArray();
     UnspentCoin coin = coins_array.FirstOrDefault(p => p.Value == total);
     if (coin != null) return new UnspentCoin[] { coin };
     coin = coins_array.OrderBy(p => p.Value).FirstOrDefault(p => p.Value > total);
     if (coin != null) return new UnspentCoin[] { coin };
     Fixed8 sum = coins_array.Sum(p => p.Value);
     if (sum < total) return null;
     if (sum == total) return coins_array;
     return coins_array.OrderByDescending(p => p.Value).TakeWhile(p =>
     {
         if (total <= Fixed8.Zero) return false;
         total -= p.Value;
         return true;
     }).ToArray();
 }