private Transaction CreateTransaction(double price) { var builder = new CallTransactionBuilder { NID = 1, PrivateKey = GetPrivateKey(), To = _appsetting.Daedric_Address, StepLimit = NumericsHelper.ICX2Loop("0.000000001"), Method = "post" }; //For a general purpose solution to remove scientific notation on a double to string value you need to preserve 339 places //https://stackoverflow.com/questions/1546113/double-to-string-conversion-without-scientific-notation builder.Params["value"] = price.ToString("0." + new string('#', 339)); var tax = builder.Build(); return(builder.Build()); }
public void TestCallTransactionBuilder() { var builder = new CallTransactionBuilder(); builder.NID = 2; builder.PrivateKey = PrivateKey.Random(); builder.To = "cx54f7853dc6481b670caf69c5a27c7c8fe5be8269"; builder.StepLimit = NumericsHelper.ICX2Loop("0.10000000000"); builder.Value = NumericsHelper.ICX2Loop("1.00000"); builder.Timestamp = 100000000000; builder.Method = "transfer"; builder.Params["to"] = new ExternalAddress("hx54f7853dc6481b670caf69c5a27c7c8fe5be8269"); builder.Params["value"] = new BigInteger(10); var tx = builder.Build(); Assert.True(Signer.Verify(tx.Signature, tx.Hash, tx.From)); var hashSource = new Dictionary <string, object>() { ["version"] = "0x3", ["nid"] = "0x2", ["from"] = Addresser.Create(builder.PrivateKey).ToString(), ["to"] = "cx54f7853dc6481b670caf69c5a27c7c8fe5be8269", ["stepLimit"] = "0x16345785d8a0000", ["value"] = "0xde0b6b3a7640000", ["timestamp"] = "0x174876e800", ["dataType"] = "call", ["data"] = new Dictionary <string, object>() { ["method"] = "transfer", ["params"] = new Dictionary <string, object>() { ["to"] = "hx54f7853dc6481b670caf69c5a27c7c8fe5be8269", ["value"] = "0xa" } } }; var hash = Hasher.Digest(hashSource); Assert.AreEqual(tx.Hash, hash); }