private bool IncTest(Int64 num) { var b0 = new BigInteger(num); var c0 = Mint.BigToCompact(b0); var b1 = new BigInteger(0); if (num < 0x800000) { b1 = new BigInteger(num + 1); } else { b1 = new BigInteger(num); var bytes = BigInteger.Abs(b1).ToByteArray().Length; var leftshift = 8 * (bytes - 3); var toadd = 1 << leftshift; b1 = BigInteger.Add(b1, new BigInteger(toadd)); } var c1 = Mint.BigToCompact(b1); if (c1 == c0) { return(false); } var c1_ = Mint.IncCompact(c0); if (c1_ != c1) { return(false); } return(true); }
public async Task then_the_request_should_be_in_the_completed_state() { // arrange var mint = new Mint( aggregateId: Any.Guid, billingAccountId: Any.NumericString, catalogId: Any.NumericString, quantity: 10L, idempotencyToken: Any.IdempotencyToken, correlationId: ScenarioCorrelationId); // act await Bus.Send(mint); await Bus.Flush(); // assert MintRequests.Single().Should().BeEquivalentTo( new { Id = mint.AggregateId, Version = 0, CatalogId = mint.CatalogId, Quantity = mint.Quantity, State = Completed }); }
public static void Main(string[] args) { long m = rl; long n = rl; Mint ans = nCk(m, 2) + nCk(n, 2); Console.WriteLine(ans); }
public void CheckStakeKernelHashTest() { var result = Mint.CheckStakeKernelHash(new PeercoinUtils.MintTemplate( "totest", "Pxxxx", 1394219584, 160, 1394219584, 1, 210090000, 471087779 ), 1411634680, 15161125480764745506); bool isValid = result.success; Assert.IsTrue(isValid); var tpl0Hash = new List <byte> { 0x00, 0x00, 0x00, 0xdb, 0x33, 0x30, 0x88, 0x15, 0x19, 0xa4, 0xf3, 0x2b, 0x90, 0x91, 0xb0, 0x93, 0x0f, 0x24, 0xec, 0x6f, 0xb0, 0x90, 0x0a, 0xcf, 0xbf, 0xb0, 0xc2, 0x26, 0xc7, 0xbc, 0x31, 0x92, }; //little endian tpl0Hash.Reverse(); for (int i = 0; i < result.hash.Length; i++) { isValid = result.hash[i] == tpl0Hash[i]; Assert.IsTrue(isValid); } // check if template satisfies min target var minbits = Mint.IncCompact(Mint.BigToCompact(result.minTarget)); var minresult = Mint.CheckStakeKernelHash(new PeercoinUtils.MintTemplate( "totest", "Pxxx", 1394219584, 160, 1394219584, 1, 210090000, minbits ), 1411634680, 15161125480764745506); isValid = minresult.success; Assert.IsTrue(isValid); }
void HandleArgumentClick(object sender, EventArgs args) { try { throw new ArgumentException("A Xamarin Android ArgumentException for testing purposes!"); } catch (Exception ex) { Mint.LogExceptionMessage("HandledKey1", "HandledValue1", ex.ToJavaException()); } }
public override string ToString() { var target = (Array.ConvertAll(this.hash.ToArray(), x => (x))).ToList(); target.Insert(0, version); var checksum = Mint.DoubleSha256(target); var bytes = target.Concat(checksum.Take(4)).ToArray(); return(Encoders.Base58.EncodeData(bytes)); }
public static void Main(string[] args) { int N = ri; Mint ans = 0; for (int i = 0; i < N; i++) { ans += GetDivisorCount(i); } Console.WriteLine((long)ans); }
/// <summary> /// nが大きくてkが小さいときに使える。 /// </summary> /// <param name="n"></param> /// <param name="k"></param> /// <returns></returns> static Mint nCk(long n, long k) { Mint x = 1; Mint y = 1; for (int i = 0; i < k; i++) { x *= n - i; y *= i + 1; } return(x / y); }
void HandleNullReferenceClick(object sender, EventArgs args) { try { string a = null; a.ToString(); } catch (Exception ex) { Java.Lang.Exception javaException = ex.ToJavaException(); Log.Debug(Tag, "Java Exception: " + javaException.ToString()); Mint.LogException(javaException); } }
void HandleApplicationExceptionClick(object sender, EventArgs args) { try { throw new ApplicationException("A Xamarin Android ArgumentException for testing purposes!"); } catch (Exception ex) { IDictionary <string, string> dictionaryMap = new Dictionary <string, string> (); dictionaryMap.Add("DictionaryKey1", "DictionaryValue1"); dictionaryMap.Add("DictionaryKey2", "DictionaryValue2"); Mint.LogExceptionMap(dictionaryMap, ex.ToJavaException()); } }
public async Task <string> CreateMintTransactionAsync(BigInteger nonce, string toAddress, BigInteger amount) { var call = new Mint { To = toAddress, Amount = amount, Nonce = nonce, Gas = 100000, GasPrice = 0 }; string transaction = await _mintHandler.SignTransactionAsync(_contractAddress, call); return(transaction); }
public void TestRoundtrip() { var set = new List <UInt32>() { 471105047 }; set.ForEach(compact => { var expected = Mint.BigToCompact(Mint.DiffToTarget(Mint.CompactToDiff(compact))); bool isValid = compact == expected; Assert.IsTrue(isValid); }); }
public List <byte> DecodeString(string address) { var bytes = Encoders.Base58.DecodeData(address); var firsthash = bytes.Take(21).ToArray(); var checksum = Mint.DoubleSha256(firsthash.ToList()).ToArray(); if (firsthash[0] != PeercoinConstants.NetworkVersion || checksum[0] != bytes[21] || checksum[1] != bytes[22] || checksum[2] != bytes[23] || checksum[3] != bytes[24]) { throw new ArgumentException($"{address} is not an address", nameof(address)); } return(firsthash.ToList().Skip(1).ToList()); }
public void IncTests() { var list = new List <long>() { 0x1, 0x2, 0x12, 0x123, 0x1234, 0x12345, 0x123456, 0x800000, 0x1234567, 0x7fffff, 0x7ffffffff, }; var big = new BigInteger(0x1234567); var g = long.Parse(Mint.CompactToBig(Mint.BigToCompact(big)).ToString()); list.Add(g); list.Add(g - 1); list.ForEach(num => { bool isValid = IncTest(num); Assert.IsTrue(isValid); }); }
public void BigToCompactTest() { var set = new[] { new uint[] { 8388608, 67141632 }, }; foreach (var i in set) { long data = (long)i[0]; var b0 = new BigInteger(data); var c0 = Mint.BigToCompact(b0); uint encoded = (uint)i[1]; bool isValid = c0 == encoded; Assert.IsTrue(isValid); } }
public CosmosApiClient(CosmosApiClientSettings settings) { _settings = settings; _flurlClient = new Lazy <IFlurlClient>(CreateClient, LazyThreadSafetyMode.ExecutionAndPublication); GaiaRest = new GaiaREST(GetClient); TendermintRpc = new TendermintRPC(GetClient); Transactions = new Transactions(GetClient); Auth = new Auth(GetClient); Bank = new Bank(GetClient); Staking = new Staking(GetClient); Governance = new Governance(GetClient); Slashing = new Slashing(GetClient); Distribution = new Distribution(GetClient); Mint = new Mint(GetClient); var jsonSerializerSettings = JsonSerializerSettings(); Serializer = new NewtownJsonSerializer(jsonSerializerSettings); }
public void ShouldCovertToCompact() { var dataset = new[] { new long[] { 7, 16842752 }, new long[] { 734, 16842754 }, new long[] { 42, 16842752 }, new long[] { 1984, 16842759 } }; foreach (var i in dataset) { var data = (uint)i[0]; var expected = i[1]; var bn = Mint.IncCompact(data); bool isValid = bn == expected; Assert.IsTrue(isValid); } }
public void Parse(uint height, List <string> txIds, uint blocktime) { var sizeVarintTx = Mint.GetSizeVarInt((long)(txIds.Count)); var offset = PeercoinConstants.BlockHeaderSize + sizeVarintTx; for (int index = 0; index < txIds.Count; index++) { var tx = client.GetRawTransaction(txIds[index]); var txraw = client.DecodeRawTransaction(tx.hex); var rawsize = tx.hex.Length / 2; // 2 char is 1 byte StoreTxState(blocktime, height, txraw, tx, (uint)index, offset, (uint)rawsize); DeleteSpentFromStore(txraw); ParseVouts(txraw); offset += rawsize; } }
public void ShouldCovertToTarget() { var set = new[] { new object[] { 21.345F, "1263037534708007065233903449077122707924414303996398674892185141248" }, new object[] { 6.15F, "4383664314154799371057726451385090274339071401122701325781576974336" }, new object[] { 56.08F, "480733493559447088382085585624766859301132742736115421675251564544" }, new object[] { 18.5007F, "1457217015401058230710519728509336428455980242272185129797989433344" }, new object[] { 7F, "3851362069648898194808762653391849309347085353924666742105907920896" } }; foreach (var i in set) { float data = (float)i[0]; string encoded = (string)i[1]; var bn = Mint.DiffToTarget(data); bool isValid = bn.ToString() == encoded; Assert.IsTrue(isValid); } }
public static void Main(string[] args) { int X = ri; int Y = ri; COMinit(); Mint ans = 0; for (int a = 0; a <= X; a++) { if ((X - a) % 2 == 0) { var b = (X - a) / 2; if (2 * a + b == Y) { ans += nCk(a + b, a); } } } Console.WriteLine((long)ans); }
public async Task then_the_vault_should_contain_the_expected_tokens() { // arrange var mint = new Mint( aggregateId: Any.Guid, billingAccountId: Any.NumericString, catalogId: Any.NumericString, quantity: 10L, idempotencyToken: Any.IdempotencyToken, correlationId: ScenarioCorrelationId); // act await Bus.Send(mint); await Bus.Flush(); await Task.Delay(2000); await Bus.Flush(); // assert Tokens.Should().HaveCount(10); }
private void btn_Mint_Click(object sender, RoutedEventArgs e) { Mint mint = new Mint(); mint.Show(); }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); Mint.SetMintCallback(this); Mint.EnableDebug(); Mint.SetUserIdentifier("*****@*****.**"); // Mint.DisableNetworkMonitoring (); // Mint.AddURLToBlackList("requestb.in"); IList <string> blacklist = Mint.URLBlackList; Mint.EnableLogging(true); // Log the last 100 messages Mint.SetLogging(100); // Log all messages with priority level "warning" and higher, on all tags Mint.SetLogging("*:W"); // Log the latest 100 messages with priority level "warning" and higher, // on all tags Mint.SetLogging(100, "*:W"); // Log all messages from the ActivityManager at priority "Info" or above, // all log messages with tag "MyApp", with priority "Debug" or above: Mint.SetLogging(400, "ActivityManager:I MyApp:D *:S"); Mint.LastBreath = () => { Log.Debug(Tag, "Last Breath invoked!"); }; Mint.InitAndStartXamarinSession(Application.Context, "3520f5c9"); Mint.AddExtraData("ExtraKey1", "ExtraValue1"); Mint.ClearExtraData(); IDictionary <string, string> dictionaryMap = new Dictionary <string, string> (); dictionaryMap.Add("ExtraDictionaryKey1", "ExtraDictionaryValue1"); dictionaryMap.Add("ExtraDictionaryKey2", "ExtraDictionaryValue2"); Mint.AddExtraDataMap(dictionaryMap); IDictionary <string, string> globalExtras = Mint.ExtraData; Mint.RemoveExtraData("ExtraKey1"); Mint.LeaveBreadcrumb("MainActivity:Oncreate"); // Set our view from the "main" layout resource SetContentView(Resource.Layout.Main); // Get our button from the layout resource, // and attach an event to it Button nullReferenceButton = FindViewById <Button> (Resource.Id.myButton); Button flushButton = FindViewById <Button> (Resource.Id.flushButton); Button logEventLogLevelButton = FindViewById <Button> (Resource.Id.logEventLogLevelButton); Button logEventButton = FindViewById <Button> (Resource.Id.logEventButton); Button handleExceptionNullButton = FindViewById <Button> (Resource.Id.handleExceptionNullButton); Button handleExceptionArgumentButton = FindViewById <Button> (Resource.Id.handleExceptionArgumentButton); Button startTransactionButton = FindViewById <Button> (Resource.Id.startTransactionButton); Button stopTransactionButton = FindViewById <Button> (Resource.Id.stopTransactionButton); Button cancelTransactionButton = FindViewById <Button> (Resource.Id.cancelTransactionButton); Button httpClientButton = FindViewById <Button> (Resource.Id.httpClientButton); Button modernHttpClientButton = FindViewById <Button> (Resource.Id.modernHttpClientButton); Button unobservedTaskButton = FindViewById <Button> (Resource.Id.unobservedTaskButton); nullReferenceButton.Click += NullReferenceClick; flushButton.Click += FlushClick; logEventLogLevelButton.Click += LogEventLogLevelClick; logEventButton.Click += LogEventClick; handleExceptionNullButton.Click += HandleNullReferenceClick; handleExceptionArgumentButton.Click += HandleArgumentClick; startTransactionButton.Click += TransactionStartClick; stopTransactionButton.Click += TransactionStopClick; cancelTransactionButton.Click += TransactionCancelClick; httpClientButton.Click += HttpClientRestPost; modernHttpClientButton.Click += ModernHttpClientRestPost; unobservedTaskButton.Click += TaskUnawaitedMethod; Mint.HandleUnobservedException = (Exception arg) => { return(true); }; }
void LogEventLogLevelClick(object sender, EventArgs args) { Mint.LogEvent("Log a Xamarin Android Event with Log Level!", MintLogLevel.Info); }
void LogEventClick(object sender, EventArgs args) { Mint.LogEvent("Log a Xamarin Android Event!"); }
void TransactionCancelClick(object sender, EventArgs args) { Mint.TransactionCancel(TransactionName, "Because I can!"); }
void TransactionStopClick(object sender, EventArgs args) { Mint.TransactionStop(TransactionName); }
private void TickTimer(object state) { //stop the timer syncTimer.Change(Timeout.Infinite, Timeout.Infinite); var start = this.currentTime; var end = Math.Min(this.currentTime + 1000, this.lastblocktime + PeercoinConstants.Findstakelimit); for (uint timestamp = start; timestamp < end; timestamp++) { var modifier = Mint.GetModifier(this.blockModifiers, timestamp); if (modifier.HasValue) { foreach (var template in templates) { if (this.formclosing || this.token.IsCancellationRequested) { return; } var result = Mint.CheckStakeKernelHash(template, timestamp, modifier.Value); if (result.success) { if (this.results.All(r => r.Id != template.Id && r.txTime != timestamp)) { results.Add(new CheckStakeResult() { Id = template.Id, OfAddress = template.OfAddress, minimumDifficulty = result.minimumDifficulty, txTime = timestamp }); FillGrid(true); } } } } if (this.formclosing || this.token.IsCancellationRequested) { return; } this.currentTime++; } const int hour = 3600; if (!this.formclosing) { SetProgress( Convert.ToInt32(this.currentTime / hour), Convert.ToInt32((this.lastblocktime + PeercoinConstants.Findstakelimit) / hour), Convert.ToInt32(this.lastblocktime / hour)); } if (!this.formclosing && !this.token.IsCancellationRequested && syncTimer != null && this.currentTime < this.lastblocktime + PeercoinConstants.Findstakelimit) { syncTimer.Change(50, Timeout.Infinite); } else { SetProgress(0, 100); SetStatus("Done"); } }
public uint SetBitsWithDifficulty(float diff) { this.Bits = Mint.BigToCompact(Mint.DiffToTarget(diff)); return(this.Bits.Value); }
void FlushClick(object sender, EventArgs args) { Mint.Flush(); }