internal override byte[] GenerateBytes() { var builder = new FlatBufferBuilder(1); // create transaction bytes var transactionsBytes = new byte[0]; transactionsBytes = InnerTransactions.Aggregate(transactionsBytes, (current, innerTransaction) => current.Concat(innerTransaction.ToAggregate()).ToArray()); // Create Vectors var signatureVector = AggregateTransactionBuffer.CreateSignatureVector(builder, new byte[64]); var signerVector = AggregateTransactionBuffer.CreateSignerVector(builder, GetSigner()); var deadlineVector = AggregateTransactionBuffer.CreateDeadlineVector(builder, Deadline.Ticks.ToUInt8Array()); var feeVector = AggregateTransactionBuffer.CreateMaxFeeVector(builder, MaxFee?.ToUInt8Array()); var transactionsVector = AggregateTransactionBuffer.CreateTransactionsVector(builder, transactionsBytes); // total size of transaction /*var totalSize = HEADER_SIZE + 4 + transactionsBytes.Length;*/ var totalSize = GetSerializedSize(); // create version var version = GetTxVersionSerialization(); // add vectors AggregateTransactionBuffer.StartAggregateTransactionBuffer(builder); AggregateTransactionBuffer.AddSize(builder, (uint)totalSize); AggregateTransactionBuffer.AddSignature(builder, signatureVector); AggregateTransactionBuffer.AddSigner(builder, signerVector); AggregateTransactionBuffer.AddVersion(builder, (uint)version); AggregateTransactionBuffer.AddType(builder, TransactionType.GetValue()); AggregateTransactionBuffer.AddMaxFee(builder, feeVector); AggregateTransactionBuffer.AddDeadline(builder, deadlineVector); AggregateTransactionBuffer.AddTransactionsSize(builder, (uint)transactionsBytes.Length); AggregateTransactionBuffer.AddTransactions(builder, transactionsVector); // end build var codedTransaction = AggregateTransactionBuffer.EndAggregateTransactionBuffer(builder).Value; builder.Finish(codedTransaction); var output = new AggregateTransactionSchema().Serialize(builder.SizedByteArray()); if (output.Length != totalSize) { throw new SerializationException("Serialized form has incorrect length"); } return(output); }
internal override byte[] GenerateBytes() { var builder = new FlatBufferBuilder(1); var transactionsBytes = new byte[0]; transactionsBytes = InnerTransactions.Aggregate(transactionsBytes, (current, innerTransaction) => current.Concat(innerTransaction.ToAggregate()).ToArray()); // Create Vectors var signatureVector = AggregateTransactionBuffer.CreateSignatureVector(builder, new byte[64]); var signerVector = AggregateTransactionBuffer.CreateSignerVector(builder, GetSigner()); var deadlineVector = AggregateTransactionBuffer.CreateDeadlineVector(builder, Deadline.Ticks.ToUInt8Array()); var feeVector = AggregateTransactionBuffer.CreateFeeVector(builder, Fee.ToUInt8Array()); var transactionsVector = AggregateTransactionBuffer.CreateTransactionsVector(builder, transactionsBytes); ushort version = ushort.Parse(NetworkType.GetNetworkByte().ToString("X") + "0" + Version.ToString("X"), System.Globalization.NumberStyles.HexNumber); // add vectors AggregateTransactionBuffer.StartAggregateTransactionBuffer(builder); AggregateTransactionBuffer.AddSize(builder, (uint)(120 + 4 + transactionsBytes.Length)); AggregateTransactionBuffer.AddSignature(builder, signatureVector); AggregateTransactionBuffer.AddSigner(builder, signerVector); AggregateTransactionBuffer.AddVersion(builder, version); AggregateTransactionBuffer.AddType(builder, TransactionType.GetValue()); AggregateTransactionBuffer.AddFee(builder, feeVector); AggregateTransactionBuffer.AddDeadline(builder, deadlineVector); AggregateTransactionBuffer.AddTransactionsSize(builder, (uint)transactionsBytes.Length); AggregateTransactionBuffer.AddTransactions(builder, transactionsVector); // end build var codedTransaction = AggregateTransactionBuffer.EndAggregateTransactionBuffer(builder).Value; builder.Finish(codedTransaction); return(new AggregateTransactionSchema().Serialize(builder.SizedByteArray())); }