/// <summary> /// Attaches the specified transactions (trytes) to the Tangle by doing Proof of Work. /// You need to supply branchTransaction as well as trunkTransaction /// (basically the tips which you're going to validate and reference with this transaction) /// - both of which you'll get through the getTransactionsToApprove API call. /// </summary> /// <param name="trunkTransaction">Trunk transaction to approve.</param> /// <param name="branchTransaction">Branch transaction to approve.</param> /// <param name="trytes">List of trytes (raw transaction data) to attach to the tangle.</param> /// <param name="minWeightMagnitude">Proof of Work intensity. Minimum value is 18</param> /// <returns>The returned value contains a different set of tryte values which you can input into broadcastTransactions and storeTransactions. /// The returned tryte value, the last 243 trytes basically consist of the: trunkTransaction + branchTransaction + nonce. /// These are valid trytes which are then accepted by the network.</returns> public AttachToTangleResponse AttachToTangle(string trunkTransaction, string branchTransaction, string[] trytes, int minWeightMagnitude = 18) { if (!InputValidator.IsHash(trunkTransaction)) { throw new ArgumentException("Invalid hashes provided."); } if (!InputValidator.IsHash(branchTransaction)) { throw new ArgumentException("Invalid hashes provided."); } if (!InputValidator.IsArrayOfTrytes(trytes, 2673)) { throw new ArgumentException("Invalid trytes provided."); } if (LocalPow != null) { var response = new AttachToTangleResponse { Trytes = new List <string>() }; string previousTransaction = null; foreach (var t in trytes) { var txn = new Transaction(t) { TrunkTransaction = previousTransaction ?? trunkTransaction, BranchTransaction = previousTransaction == null ? branchTransaction : trunkTransaction }; if (string.IsNullOrEmpty(txn.Tag) || txn.Tag.Matches("9*")) { txn.Tag = txn.ObsoleteTag; } txn.AttachmentTimestamp = IotaApiUtils.CreateTimeStampNow(); txn.AttachmentTimestampLowerBound = 0; txn.AttachmentTimestampUpperBound = 3_812_798_742_493L; var resultTrytes = LocalPow.PerformPoW(txn.ToTransactionTrytes(), minWeightMagnitude); previousTransaction = new Transaction(resultTrytes).Hash; response.Trytes.Add(resultTrytes); } return(response); } AttachToTangleRequest attachToTangleRequest = new AttachToTangleRequest(trunkTransaction, branchTransaction, trytes, minWeightMagnitude); return(_genericIotaCoreApi.Request <AttachToTangleRequest, AttachToTangleResponse>(attachToTangleRequest)); }
/// <summary> /// Attaches the specified transactions (trytes) to the Tangle by doing Proof of Work. /// You need to supply branchTransaction as well as trunkTransaction /// (basically the tips which you're going to validate and reference with this transaction) /// - both of which you'll get through the getTransactionsToApprove API call. /// </summary> /// <param name="trunkTransaction">Trunk transaction to approve.</param> /// <param name="branchTransaction">Branch transaction to approve.</param> /// <param name="trytes">List of trytes (raw transaction data) to attach to the tangle.</param> /// <param name="minWeightMagnitude">Proof of Work intensity. Minimum value is 18</param> /// <returns>The returned value contains a different set of tryte values which you can input into broadcastTransactions and storeTransactions. /// The returned tryte value, the last 243 trytes basically consist of the: trunkTransaction + branchTransaction + nonce. /// These are valid trytes which are then accepted by the network.</returns> public AttachToTangleResponse AttachToTangle(string trunkTransaction, string branchTransaction, string[] trytes, int minWeightMagnitude = 18) { InputValidator.CheckIfArrayOfTrytes(trytes); AttachToTangleRequest attachToTangleRequest = new AttachToTangleRequest(trunkTransaction, branchTransaction, trytes, minWeightMagnitude); return(_genericIotaCoreApi.Request <AttachToTangleRequest, AttachToTangleResponse>(attachToTangleRequest)); }