public override Elysium.Transaction Deserialize( BitcoinAddress?sender, BitcoinAddress?receiver, ref SequenceReader <byte> reader, int version) { if (ReferenceEquals(sender, null)) { throw new ArgumentNullException(nameof(sender)); } // Deserialize payload. var property = DeserializePropertyId(ref reader); var amount = DeserializeTokenAmount(ref reader); if (property == null) { throw new TransactionSerializationException("Invalid property identifier."); } // Construct domain object. try { return(version switch { 0 => new SimpleSendV0(sender, receiver, property, amount), _ => throw new ArgumentOutOfRangeException(nameof(version)), }); }
public CreateManagedPropertyV0( BitcoinAddress sender, BitcoinAddress?receiver, string name, string category, string subcategory, string website, string description, PropertyType type, TokenType tokenType, PropertyId?previousId) : base(sender, receiver) { if (name.Length == 0) { throw new ArgumentException("The value is not a valid name.", nameof(name)); } this.Name = name; this.Category = category; this.Subcategory = subcategory; this.Website = website; this.Description = description; this.Type = type; this.TokenType = tokenType; this.PreviousId = previousId; }
/// <inheritdoc /> public override BitcoinAddress?ReadJson(JsonReader reader, Type objectType, BitcoinAddress?existingValue, bool hasExistingValue, JsonSerializer serializer) { var bitcoinAddressString = reader.Value as string; if (string.IsNullOrWhiteSpace(bitcoinAddressString)) { return(default);
public async Task <string> GrantTokensAsync( Property property, BitcoinAddress from, BitcoinAddress?to, TokenAmount amount, string?note, CancellationToken cancellationToken = default) { if (amount <= TokenAmount.Zero) { throw new ArgumentOutOfRangeException(nameof(amount), amount, "The value is not valid."); } // Setup arguments. var args = new Collection <object>() { from.ToString(), ReferenceEquals(to, null) ? string.Empty : to.ToString(), property.Id.Value, amount.ToString(property.TokenType), }; if (note != null) { args.Add(note); } // Invoke RPC. var resp = await this.Client.SendCommandAsync("elysium_sendgrant", args.ToArray()); return(resp.Result.Value <string>()); }
public override Elysium.Transaction Deserialize( BitcoinAddress?sender, BitcoinAddress?receiver, ref SequenceReader <byte> reader, int version) { if (ReferenceEquals(sender, null)) { throw new ArgumentNullException(nameof(sender)); } // Deserialize payload. var type = DeserializePropertyType(ref reader); var tokenType = DeserializeTokenType(ref reader); var previousId = DeserializePropertyId(ref reader); var category = DeserializeString(ref reader); var subcategory = DeserializeString(ref reader); var name = DeserializeString(ref reader); var website = DeserializeString(ref reader); var description = DeserializeString(ref reader); PrivateTransactionStatus?privateTransactionStatus = null; if (version == 1) { privateTransactionStatus = DeserializePrivateTransactionStatus(ref reader); } // Construct domain object. try { return(version switch { 0 => new CreateManagedPropertyV0( sender, receiver, name, category, subcategory, website, description, type, tokenType, previousId), 1 => new CreateManagedPropertyV1( sender, receiver, name, category, subcategory, website, description, type, tokenType, privateTransactionStatus !.Value, previousId), _ => throw new ArgumentOutOfRangeException(nameof(version)), }); }
public GrantTokensV0(BitcoinAddress sender, BitcoinAddress?receiver, PropertyId property, TokenAmount amount) : base(sender, receiver) { if (amount <= TokenAmount.Zero) { throw new ArgumentOutOfRangeException(nameof(amount)); } this.Property = property; this.Amount = amount; }
public SimpleSendV0(BitcoinAddress sender, BitcoinAddress?receiver, PropertyId property, TokenAmount amount) : base(sender, receiver) { if (amount <= TokenAmount.Zero) { throw new ArgumentOutOfRangeException(nameof(amount), amount, "The value is less than one."); } this.Property = property; this.Amount = amount; }
protected async Task <string> GrantTokensAsync( Property property, BitcoinAddress from, BitcoinAddress?to, TokenAmount amount) { await using (var client = await this.Factory.CreatePropertyManagementClientAsync()) { return(await client.GrantTokensAsync(property, from, to, amount, null)); } }
public CreateManagedPropertyV1( BitcoinAddress sender, BitcoinAddress?receiver, string name, string category, string subcategory, string website, string description, PropertyType type, TokenType tokenType, PrivateTransactionStatus privateTransactionStatus, PropertyId?previousId) : base(sender, receiver, name, category, subcategory, website, description, type, tokenType, previousId) { this.PrivateTransactionStatus = privateTransactionStatus; }
public virtual void FillFromTemplateFunding(PSBTFundingTemplate fundingTemplate, PubKey fundingKey) { FundingInputs = fundingTemplate.FundingCoins .Select(input => new FundingInput() { Outpoint = input.Outpoint, Output = input.TxOut }).ToArray(); ChangeAddress = fundingTemplate.Change?.GetDestinationAddress(fundingTemplate.Network) ?? throw new InvalidOperationException("No change address output found"); PubKeys = new PubKeyObject() { PayoutAddress = fundingTemplate.PayoutAddress.GetDestinationAddress(fundingTemplate.Network) ?? throw new InvalidOperationException("No payout address output found"), FundingKey = fundingKey }; TotalCollateral = fundingTemplate.Collateral; } }
public override Elysium.Transaction Deserialize( BitcoinAddress?sender, BitcoinAddress?receiver, ref SequenceReader <byte> reader, int version) { var length = Convert.ToInt32(reader.Remaining); using (var memory = MemoryPool <byte> .Shared.Rent(length)) { var buffer = memory.Memory.Span.Slice(0, length); reader.TryCopyTo(buffer); reader.Advance(length); return(this.StubbedDeserialize.Object(sender, receiver, buffer.ToArray(), version)); } }
public Transaction Deserialize( BitcoinAddress?sender, BitcoinAddress?receiver, ref SequenceReader <byte> reader) { ushort version, type; using (var memory = MemoryPool <byte> .Shared.Rent(4)) { var buffer = memory.Memory.Span.Slice(0, 4); if (!reader.TryCopyTo(buffer)) { throw new TransactionSerializationException("Incomplete data."); } reader.Advance(4); version = BinaryPrimitives.ReadUInt16BigEndian(buffer.Slice(0)); type = BinaryPrimitives.ReadUInt16BigEndian(buffer.Slice(2)); } if (!this.serializers.TryGetValue(type, out var serializer)) { throw new TransactionSerializationException("Unknow transaction."); } try { return(serializer.Deserialize(sender, receiver, ref reader, version)); } catch (ArgumentException ex) when(ex.ParamName == "version") { throw new TransactionSerializationException("Unknow version.", ex); } }
protected Transaction(BitcoinAddress?sender, BitcoinAddress?receiver) { this.Sender = sender; this.Receiver = receiver; }
public FakeTransaction(BitcoinAddress?sender, BitcoinAddress?receiver, int id, int version) : base(sender, receiver) { Id = id; Version = version; }
public abstract Transaction Deserialize( BitcoinAddress?sender, BitcoinAddress?receiver, ref SequenceReader <byte> reader, int version);
public FakeTransaction(BitcoinAddress?sender, BitcoinAddress?receiver) : base(sender, receiver) { Id = 1; Version = 1; }
Elysium.Transaction DeserializeElysiumTransaction( BitcoinAddress?sender, BitcoinAddress?receiver, in ReadOnlySequence <byte> data)