public void TestBuilderMemoText() { // GBPMKIRA2OQW2XZZQUCQILI5TMVZ6JNRKM423BSAISDM7ZFWQ6KWEBC4 var source = KeyPair.FromSecretSeed("SCH27VUZZ6UAKB67BDNF6FA42YMBMQCBKXWGMFD5TZ6S5ZZCZFLRXKHS"); var destination = KeyPair.FromAccountId("GDW6AUTBXTOC7FIKUO5BOO3OGLK4SF7ZPOBLMQHMZDI45J2Z6VXRB5NR"); var account = new Account(source.AccountId, 2908908335136768); var transaction = new TransactionBuilder(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(TransactionBase.TransactionXdrVersion.V0)); Assert.AreEqual( "AAAAAgAAAABexSIg06FtXzmFBQQtHZsrnyWxUzmthkBEhs/ktoeVYgAAAGQAClWjAAAAAQAAAAAAAAABAAAADEhlbGxvIHdvcmxkIQAAAAEAAAAAAAAAAAAAAADt4FJhvNwvlQqjuhc7bjLVyRf5e4K2QOzI0c6nWfVvEAAAAASoF8gAAAAAAAAAAAG2h5ViAAAAQMc6HwYaGsrlJ8/LdE9VDVq04JifpQofSmnjhrtqaTTs/VBsNGmxi4b/vaFkLLLWh8emI8FsS/vBgb8AVFVkZQU=", transaction.ToEnvelopeXdrBase64()); var transaction2 = Transaction.FromEnvelopeXdr(transaction.ToEnvelopeXdr()); Assert.AreEqual(transaction.SourceAccount.AccountId, transaction2.SourceAccount.AccountId); Assert.AreEqual(transaction.SequenceNumber, transaction2.SequenceNumber); Assert.AreEqual(transaction.Memo, transaction2.Memo); Assert.AreEqual(transaction.Fee, transaction2.Fee); Assert.AreEqual( ((CreateAccountOperation)transaction.Operations[0]).StartingBalance, ((CreateAccountOperation)transaction2.Operations[0]).StartingBalance ); }
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()); var transaction2 = Transaction.FromEnvelopeXdr(transaction.ToEnvelopeXdr()); Assert.AreEqual(transaction.SourceAccount.AccountId, transaction2.SourceAccount.AccountId); Assert.AreEqual(transaction.SequenceNumber, transaction2.SequenceNumber); Assert.AreEqual(transaction.Memo, transaction2.Memo); Assert.AreEqual(transaction.Fee, transaction2.Fee); Assert.AreEqual( ((CreateAccountOperation)transaction.Operations[0]).StartingBalance, ((CreateAccountOperation)transaction2.Operations[0]).StartingBalance ); }
public void TestBuilderTimeBounds() { // GBPMKIRA2OQW2XZZQUCQILI5TMVZ6JNRKM423BSAISDM7ZFWQ6KWEBC4 var source = KeyPair.FromSecretSeed("SCH27VUZZ6UAKB67BDNF6FA42YMBMQCBKXWGMFD5TZ6S5ZZCZFLRXKHS"); var destination = KeyPair.FromAccountId("GDW6AUTBXTOC7FIKUO5BOO3OGLK4SF7ZPOBLMQHMZDI45J2Z6VXRB5NR"); var account = new Account(source.AccountId, 2908908335136768L); var transaction = new TransactionBuilder(account) .AddOperation(new CreateAccountOperation.Builder(destination, "2000").Build()) .AddTimeBounds(new TimeBounds(42, 1337)) .AddMemo(Memo.Hash("abcdef")) .Build(); transaction.Sign(source); // Convert transaction to binary XDR and back again to make sure timebounds are correctly de/serialized. var decodedTransaction = transaction.ToEnvelopeXdr().V1.Tx; Assert.AreEqual(decodedTransaction.TimeBounds.MinTime.InnerValue.InnerValue, 42U); Assert.AreEqual(decodedTransaction.TimeBounds.MaxTime.InnerValue.InnerValue, 1337U); var transaction2 = Transaction.FromEnvelopeXdr(transaction.ToEnvelopeXdr()); Assert.AreEqual(transaction.SourceAccount.AccountId, transaction2.SourceAccount.AccountId); Assert.AreEqual(transaction.SequenceNumber, transaction2.SequenceNumber); Assert.AreEqual(transaction.Memo, transaction2.Memo); Assert.AreEqual(transaction.TimeBounds, transaction2.TimeBounds); Assert.AreEqual(transaction.Fee, transaction2.Fee); Assert.AreEqual( ((CreateAccountOperation)transaction.Operations[0]).StartingBalance, ((CreateAccountOperation)transaction2.Operations[0]).StartingBalance ); }
public void TestMemoTextUtf8() { var memo = Memo.Text("三"); Assert.AreEqual(sdkxdr.MemoType.MemoTypeEnum.MEMO_TEXT, memo.ToXdr().Discriminant.InnerValue); Assert.AreEqual("三", memo.MemoTextValue); }
public void TestMemoReturnHashSuccess() { var memo = Memo.ReturnHash("4142434445464748494a4b4c"); Assert.AreEqual(sdkxdr.MemoType.MemoTypeEnum.MEMO_RETURN, memo.ToXdr().Discriminant.InnerValue); Assert.AreEqual("4142434445464748494a4b4c", memo.GetTrimmedHexValue()); }
public void TestMemoId() { var memo = Memo.Id(9223372036854775807L); Assert.AreEqual(9223372036854775807L, memo.IdValue); Assert.AreEqual(sdkxdr.MemoType.MemoTypeEnum.MEMO_ID, memo.ToXdr().Discriminant.InnerValue); Assert.AreEqual(9223372036854775807L, memo.ToXdr().Id.InnerValue); }
public void TestMemoHashBytesSuccess() { var bytes = Enumerable.Repeat((byte)'A', 10).ToArray(); var memo = Memo.Hash(bytes); Assert.AreEqual(sdkxdr.MemoType.MemoTypeEnum.MEMO_HASH, memo.ToXdr().Discriminant.InnerValue); Assert.AreEqual("AAAAAAAAAA", Util.PaddedByteArrayToString(memo.MemoBytes)); Assert.AreEqual("4141414141414141414100000000000000000000000000000000000000000000", memo.GetHexValue()); Assert.AreEqual("41414141414141414141", memo.GetTrimmedHexValue()); }
public void TestMemoHashSuccess() { var memo = Memo.Hash("4142434445464748494a4b4c"); Assert.AreEqual(sdkxdr.MemoType.MemoTypeEnum.MEMO_HASH, memo.ToXdr().Discriminant.InnerValue); var test = "ABCDEFGHIJKL"; Assert.AreEqual(test, Util.PaddedByteArrayToString(memo.MemoBytes)); Assert.AreEqual("4142434445464748494a4b4c", memo.GetTrimmedHexValue()); }
public void TestMemoHashInvalidHex() { try { Memo.Hash("test"); Assert.Fail(); } catch (FormatException) { } }
public void TestMemoHashTooLong() { var longer = Enumerable.Repeat((byte)0, 33).ToArray(); try { Memo.Hash(longer); Assert.Fail(); } catch (MemoTooLongException exception) { Assert.IsTrue(exception.Message.Contains("MEMO_HASH can contain 32 bytes at max.")); } }
public Transaction(IAccountId sourceAccount, uint fee, long sequenceNumber, Operation[] operations, Memo memo, TimeBounds timeBounds) { SourceAccount = sourceAccount ?? throw new ArgumentNullException(nameof(sourceAccount), "sourceAccount cannot be null"); Fee = fee; 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"); } Memo = memo ?? Memo.None(); TimeBounds = timeBounds; }
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 TransactionV0 ToXdrV0() { if (!(SourceAccount is KeyPair)) { throw new Exception("TransactionEnvelope V0 expects a KeyPair source account"); } // fee var fee = new Uint32 { InnerValue = Fee }; // sequenceNumber var sequenceNumberUint = new xdr.Int64(SequenceNumber); var sequenceNumber = new SequenceNumber { InnerValue = sequenceNumberUint }; // sourceAccount var sourceAccount = new Uint256(SourceAccount.PublicKey); // 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 TransactionV0.TransactionV0Ext { Discriminant = 0 }; var transaction = new TransactionV0 { Fee = fee, SeqNum = sequenceNumber, SourceAccountEd25519 = sourceAccount, Operations = operations, Memo = Memo.ToXdr(), TimeBounds = TimeBounds?.ToXdr(), Ext = ext }; return(transaction); }
/// <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 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.")); } }
public static Transaction FromEnvelopeXdr(TransactionEnvelope envelope) { xdr.Transaction transactionXdr = envelope.Tx; var fee = transactionXdr.Fee.InnerValue; KeyPair sourceAccount = KeyPair.FromXdrPublicKey(transactionXdr.SourceAccount.InnerValue); long sequenceNumber = transactionXdr.SeqNum.InnerValue.InnerValue; Memo memo = Memo.FromXdr(transactionXdr.Memo); TimeBounds timeBounds = TimeBounds.FromXdr(transactionXdr.TimeBounds); Operation[] operations = new Operation[transactionXdr.Operations.Length]; for (int i = 0; i < transactionXdr.Operations.Length; i++) { operations[i] = Operation.FromXdr(transactionXdr.Operations[i]); } Transaction transaction = new Transaction(sourceAccount, fee, sequenceNumber, operations, memo, timeBounds); foreach (var signature in envelope.Signatures) { transaction.Signatures.Add(signature); } return(transaction); }
public void TestMemoNone() { var memo = Memo.None(); Assert.AreEqual(sdkxdr.MemoType.MemoTypeEnum.MEMO_NONE, memo.ToXdr().Discriminant.InnerValue); }