private Transaction(KeyPair sourceAccount, long sequenceNumber, Operation[] operations, Memo memo, TimeBounds timeBounds) { SourceAccount = sourceAccount ?? throw new ArgumentNullException(nameof(sourceAccount), "sourceAccount cannot be null"); SequenceNumber = sequenceNumber; Operations = operations ?? throw new ArgumentNullException(nameof(operations), "operations cannot be null"); if (operations.Length == 0) { throw new ArgumentNullException(nameof(operations), "At least one operation required"); } Fee = operations.Length * BaseFee; Signatures = new List <DecoratedSignature>(); Memo = memo ?? Memo.None(); TimeBounds = timeBounds; }
/// <summary> /// Generates Transaction XDR object. /// </summary> /// <returns></returns> public xdr.Transaction ToXdr() { // fee var fee = new Uint32 { InnerValue = Fee }; // sequenceNumber var sequenceNumberUint = new Uint64 { InnerValue = SequenceNumber }; var sequenceNumber = new SequenceNumber { InnerValue = sequenceNumberUint }; // sourceAccount var sourceAccount = new AccountID { InnerValue = SourceAccount.XdrPublicKey }; // operations var operations = new xdr.Operation[Operations.Length]; for (var i = 0; i < Operations.Length; i++) { operations[i] = Operations[i].ToXdr(); } // ext var ext = new xdr.Transaction.TransactionExt { Discriminant = 0 }; var transaction = new xdr.Transaction { Fee = fee, SeqNum = sequenceNumber, SourceAccount = sourceAccount, Operations = operations, Memo = Memo.ToXdr(), TimeBounds = TimeBounds?.ToXdr(), Ext = ext }; return(transaction); }
public void TestBuilderMemoText() { // GBPMKIRA2OQW2XZZQUCQILI5TMVZ6JNRKM423BSAISDM7ZFWQ6KWEBC4 var source = KeyPair.FromSecretSeed("SCH27VUZZ6UAKB67BDNF6FA42YMBMQCBKXWGMFD5TZ6S5ZZCZFLRXKHS"); var destination = KeyPair.FromAccountId("GDW6AUTBXTOC7FIKUO5BOO3OGLK4SF7ZPOBLMQHMZDI45J2Z6VXRB5NR"); var account = new Account(source, 2908908335136768); var transaction = new Transaction.Builder(account) .AddOperation(new CreateAccountOperation.Builder(destination, "2000").Build()) .AddMemo(Memo.Text("Hello world!")) .Build(); transaction.Sign(source); Assert.AreEqual( "AAAAAF7FIiDToW1fOYUFBC0dmyufJbFTOa2GQESGz+S2h5ViAAAAZAAKVaMAAAABAAAAAAAAAAEAAAAMSGVsbG8gd29ybGQhAAAAAQAAAAAAAAAAAAAAAO3gUmG83C+VCqO6FztuMtXJF/l7grZA7MjRzqdZ9W8QAAAABKgXyAAAAAAAAAAAAbaHlWIAAABAxzofBhoayuUnz8t0T1UNWrTgmJ+lCh9KaeOGu2ppNOz9UGw0abGLhv+9oWQsstaHx6YjwWxL+8GBvwBUVWRlBQ==", transaction.ToEnvelopeXdrBase64()); }
public void TestTryingToAddMemoTwice() { // GBPMKIRA2OQW2XZZQUCQILI5TMVZ6JNRKM423BSAISDM7ZFWQ6KWEBC4 var source = KeyPair.FromSecretSeed("SCH27VUZZ6UAKB67BDNF6FA42YMBMQCBKXWGMFD5TZ6S5ZZCZFLRXKHS"); var destination = KeyPair.FromAccountId("GDW6AUTBXTOC7FIKUO5BOO3OGLK4SF7ZPOBLMQHMZDI45J2Z6VXRB5NR"); try { var account = new Account(source, 2908908335136768L); new Transaction.Builder(account) .AddOperation(new CreateAccountOperation.Builder(destination, "2000").Build()) .AddMemo(Memo.None()) .AddMemo(Memo.None()); Assert.Fail(); } catch (Exception exception) { Assert.IsTrue(exception.Message.Contains("Memo has been already added.")); } }